Posts

sql - Two questions for formatting timestamp and number using postgressql -

i selecting date column in format "yyyy-mm-dd". i want cast timestamp such "yyyy-mm-dd hh:mm:ss:ms" i attempted: select cast(mycolumn timestamp) mytable; but resulted in format yyyy-mm-dd hh:mm:ss i tried select to_timestamp(mycolumn,yyyy-mm-dd hh:mm:ss:ms) mytable; but did not work either. cannot seem figure out correct way format this. note want first digit of milliseconds. //////////////second question i trying select numeric data such there not trailing zeros. for example, if have values in table such 1, 2.00, 3.34, 4.50. i want able select values 1, 2, 3.34, 4.5. i tried using ::float, strange output. tried rounding function, how use without knowing how many decimal points need before hand? thanks help! it seems functions to_timestamp() , to_char() unfortunately not perfect. if cannot find better, use these workarounds: with example_data(d) ( values ('2016-02-02') ) select d, d::timestamp || '.0...

Rails ActiveModel: inheritance namespace -

i have parent class class project::subscription < activerecord::base and 2 inherited classes class project::loan::subscription < project::subscription class project::investment::subscription < project::subscription when call project::loan::subscription.first , shows: project::loan::subscription load (0.4ms) select "project_subscriptions".* "project_subscriptions" "project_subscriptions"."type" in ('project::loan::subscription') order "project_subscriptions"."id" asc limit which correct. but when call project::investment::subscription.first , shows: project::subscription load (0.3ms) select "project_subscriptions".* "project_subscriptions" order "project_subscriptions"."id" asc limit 1 in last call, project::investment::subscription acting project::subscription what's wrong code?

raspberry pi - Python GPIO function input button toggle on falling edge -

i trying script work button monitored , if operated once turn on something. if operated again turn off. toggle button. have working following code not waits button edge trigger. other code in while loop not carried out. how can check in function if button has been operated , if not carry on rest of code. import time import rpi.gpio gpio gpio.setmode(gpio.bcm) # using broadcomm pin numbers gpio.setup(21, gpio.in, pull_up_down=gpio.pud_up) prevwater = 0 def buttoncontrol (): global prevwater # take reading gpio.wait_for_edge(21, gpio.falling) prevwater = not prevwater return prevwater while 1: waterbutton = buttoncontrol () if (waterbutton == true): print ("turn water on") if (waterbutton == false): print ("turn water off") # check returned function print (waterbutton) # need other stuff here gpio.cleanup() any appreciated i have tried callback shown below import time import rpi.gpio gpio ...

c - How to use fgets() in 2d-arrays (multiple dimension arrays)? -

#include <stdio.h> #include <stdlib.h> void *salloc(int x){ char **pointer; int i; pointer = malloc(sizeof(char)*x); if(pointer == null){ exit(-1); } for(i=0; i<x; i++){ pointer[i] = malloc(sizeof(char) * 20); if(pointer[i] == null){ exit(-1); } } return pointer; } void input(int value, char **array){ for(i = 0; < value; i++){ printf("%d ----\n", i); fgets(array[i], 20, stdin); printf("%d ----\n", i); } } int main(int argc, char *argv[]){ char **array; int value = 2; array = salloc(value); input(value, array); return 0; } the general idea, can miss syntax. want read in string spaces. if run value 2, print: 0 ---- 0 ---- 1 ---- "some string" and crashes after press enter. if value 1: crashes. if replace fgets() with: scanf("%s", array[i]); it works (except spaces). so how fgets() ...

recursion - Processing graph layer by layer -

Image
i have task. let's imagine have tree . have trunk , branches . every branch has own branches. etc. simplify task suppose every branch has 2 branches on it. see picture. we want address every branch, have layer layer . mean @ first should address branches 1 , 2, after 3,4,5,6, , forth. tried make algorythm it, anytime ends recursively going deeply: 1-3-7-8-4-9-10... there algorithms process tree unknown size without boilerplate code? you can breadth-first search , goes through graph layer layer because uses queue store newly discovered nodes.

python - ClientForm.AmbiguityError: more than one control matching name -

i new programming in python , trying login private website mechanize;i read similar questions like: how bypass mechanize "ambiguityerror" in python , python mechanize handle 2 parameters same name , non of these , there no feedback on solution second link. far i've read, using br.select_form(nr=0) should enough select first form still stuck; i've tried changing br.select_form(name of form) , br.form.find_control() attributeerror: 'nonetype' object has no attribute 'find_control'; options without success. below code , list of forms can found. support appreciated. thanks this code used: br = mechanize.browser() br.set_handle_robots(false) cj = cookielib.lwpcookiejar() br.set_cookiejar(cj) br.select_form(nr=0) br.form["username"]= 'myusername' br.form["password"]= 'mypassword' br.submit() these forms: <hiddencontrol(smauthreason=0) (readonly)> <hiddencontrol(clientfp=) (readonly)> <hiddencontr...

ios - Closures In Swift? -

i new ios coding , stuck in closures feature of swift. have referred many tutorials , found closures self written codes can used in many ways eg. arguments in function call,parameters in function definition,variables. giving below example below associated thoughts code & questions. please me if wrong in understanding. know wrong @ many points,so please rectify me. 1.1st part func test(text1:string,text2:string,flag: (s1:string,s2:string)->bool)//in line,i think,i using flag closure passed parameter in function. , if why doesn't follow standard closure syntax? { if flag(s1: text1, s2: text2) == true//i want check return type flag closure gets when compares both string during function call. why can't write if flag == true flag name of closure , refers return type of closure? { print("they equal") } else { // } } 2nd part this part troublesome part confuses me when callin...