Posts

javascript - Centering a flot chart relative to the chart plotted instead of the canvas size. -

hey i'm working on application uses flot charts extensively. manager tasked me "centering" charts not way right now. by default generate canvas size leaves room on y-axis data, , leads offset canvas centered leaving chart slight offset right. i know nitpicky issue i'm wondering if there's implementable way make chart center relative chart itself, possibly extending right-side canvas equal left, or making y-axis generate in text form leaving chart canvas. i've tried read through flot api solution nothing jumps out @ me. if i'm understanding correctly, looking grid's margin property . grid:{ margin:{ right: 17, top: 17 } } see fiddle here . for comment to set right margin equal left margin dynamically, let flot draw plot once, set right margin equal yaxis's width , redraw plot: p = $.plot( ... p.getoptions().grid.margin.right = p.getyaxes()[0].box.width; p.setupgrid(); p.draw(); updated fiddle ....

jquery - Better way to load dropdown list from comma separated string -

i have string of comma separated values. need split string , load each entry in dropdown . have following code job. is there better code reduces number of lines without using other library? code //remove existing entries dropdown $('.ddlasn').empty(); //split string array var arr = result.split(','); //loop through array for(var = 0; i<arr.length; i++) { //add ddl options - text , value $('.ddlasn').append($('<option></option>').val(arr[i]).html(arr[i])); } you can simplify to: $.each(result.split(','), function(i, e) { $('.ddlasn').append($('<option>', { value: e, text: e })); });

ios - Unable to update the model layer upon CoreAnimation completion -

Image
i have following function. it's purpose animate ui elements out of the screen's bounds. func animateelementsout(elements: anyobject...) { var moveoutanimation : cakeyframeanimation = cakeyframeanimation(keypath: "transform"); moveoutanimation.delegate = self; var key1 : nsvalue = nsvalue(catransform3d: catransform3didentity); var key2 : nsvalue = nsvalue(catransform3d: catransform3dmaketranslation(-300, 0, 0)); var values : nsarray = [key1, key2]; var delayamount = 0.0; moveoutanimation.values = values; moveoutanimation.calculationmode = kcaanimationlinear; moveoutanimation.timingfunction = camediatimingfunction(name: kcamediatimingfunctioneasein); moveoutanimation.duration = 0.5; moveoutanimation.additive = true; element : anyobject in elements { delayamount += 0.1; moveoutanimation.removedoncompletion = true; moveoutanimation.begintime = cacurrentmediatime() + delayamount; ...

osx - Full path to an awk script from within the script itself -

i have awk script, i.e., ascii file executable in linux in first line is: #!/usr/bin/awk -f i execute myscript this, if i'm in same directory: > ./myscript afile or this, if i'm in different directory: > pwd /some_weird_path > /full_path/myscript afile how can have access "/full_path/" within awk script itself? i've tried following without success: argv[0] => /usr/bin/awk argv[1] => afile environ["pwd"] => some_weird_path ideas? this ugly seems work gnu awk on linux. begin { getline cmdline <("/proc/"procinfo["pid"]"/cmdline") nf=split(cmdline,fields,/\0/) print fields[3] } this uglier, should work on system ps implementation, long neither path awk nor path script include whitespace characters: begin { "ps -p "procinfo["pid"]" -ocommand=" | getline cmdline nf=split(cmdline,fields," ...

javascript - JQuery css function not persisting its change -

i have "button-bar" div want show once user has clicked on "settings" button. have set button-bar div display:none in css. unfortunately, when settings button clicked, div shows split second, goes away. know why might happening? current code: $(document).ready(function() { $('#settings').on('click', function() { $('#button-bar').css('display', 'inline-block'); }); }); the problem href="" empty, reloading page. put hashtags in them. href="#"

haskell - Why is the return value of head implicitly converted to Maybe? -

i've started learn haskell , practice i've decided create function takes tree, elements have position , size, , returns element located @ position. code looks this: import data.list (dropwhile) data node = node (int,int) (int,int) [node] deriving(eq, show) findnode :: (int,int) -> node -> maybe node findnode loc node@(node (x, y) (width, height) []) = if loc >= (x, y) && loc <= (x+width, y+height) node else nothing findnode loc node@(node (x, y) (width, height) children) = if loc >= (x, y) && loc <= (x+width, y+height) if not $ null nodes head nodes else node else nothing nodes = dropwhile (==nothing) $ map (findnode loc) children this code compiles , runs far can tell, i'm curious 1 thing, why head nodes acceptable instead of just $ head nodes? . that's because nodes has type of [maybe node] . can infact verify annotating explicitly , compiling again: findnode ...

r - ggplot2 stat_function plots the wrong function -

Image
i want plot loglikelihood function of series of independent bernoulli distributed random variables y parameter p being function (the logistic function) of feature x. logistic function has parameter b. parameter want estimate. want plot loglikelihood function of b. want in r using ggplot2, because want become better in those. my creation of loglikelihood function can , should done better, not point here. problem plotted loglikelihood constant on interval (-5,5). seems wrong. especially, because when call function arbitrary b in interval returns different value. why happen? thank you. library(ggplot2) set.seed(123) # parameters n=100 mu=0 s=2 b<-0.2 # functions logit <- function(x,b){1/(1+exp(-b*x))} # simulation of data x<-rnorm(n,mu,s) y_prob<-logit(x,b) y<-rbinom(n,1,y_prob) df<-data.frame(x,y) # loglikelihood function loglikelihood<-function(b,df){ prd<-1 (i in 1:nrow(df)){ events<-logit(df$x[i],b) nonevents<-1-events prd...