Posts

Showing posts from August, 2011

C# TreeView.EnsureVisible() - how else can I scroll? -

Image
on treeview here: left treeview before ensurevisible(), , right after the icon neglected. can't figure out how show icon after using ensurevisible() , use alternative ensurevisible() can't find way manually scroll. there? maybe nativemethods user32.dll or ? "left: treeview before ensurevisible, , right: after" you'll have use little external wizardry: using system.runtime.interopservices; //.. [dllimport("user32.dll", charset = charset.auto)] public static extern int getscrollpos(intptr hwnd, int nbar); [dllimport("user32.dll")] static extern int setscrollpos(intptr hwnd, int nbar, int npos, bool bredraw); private const int sb_horz = 0x0; private const int sb_vert = 0x1; // bring node display somenode.ensurevisible(); // can scroll way left: setscrollpos(treeview1.handle, sb_horz, 0, true); // ..or few pixels: int spos = getscrollpos( treeview1.handle, sb_horz); setscrollpos(treeview1.handle, sb_horz, spos - 20, true

r - Reading Data from different locations through a function -

i pretty new r , struggling below scenario : need write function reads data different locations on pc(like downloads,documents,desktop etc). each file in these locations have unique id. function take id , location arguments. : onefunc <- function(directory,id) { y <- read.csv("directory/id") } i need pass directory , id read function. above code throws error - cannot open file 'directory/id': no such file or directory. need pass in read.csv exactly? what have right inside function string (sequence of characters). r not recognize these variables. need variables directory , id string. host of options available that: sprintf('%s/%s', directory, id) paste(directory, id, sep = '/') file.path(directory, id) , meant constructing file paths. other functions generic string building functions. recommend using function in case specific situation, , work across platforms. you can feed string read.csv perform actual

proc sql - SAS - summing values down observations -

i sum values set of observations, specific column based on specific identifier. example, suppose have data below a 4 5 6 b 3 3 2 3 4 2 c 3 2 0 b 3 7 3 b 2 4 1 suppose want sum of values identifier in column 1, have totals a, b , c specific column of choice (2, 3 or 4). in separate data set output either a, b or c beyond criteria. for example, want sums of column 4 (based on identifier in column 1) above value of 1, output data set should return = 8, b = 6, , nothing c zero. i open proc sql , or data step, in fact useful know both methods. you can use sql - groupby - sum aggregate function

ios - Sprite Kit game for Iphone 3.5 inch and 4 inch screen size -

i have developed little game in sprite kit xcode 5 4-inch screen, know if , how can use 3.5-inch. when open app iphone 5, ok, if try open iphone 4s simulator, lot of things hidden outside of screen. i read lot of posts , solution seems constraints, best solution? work spritekit? how can use it? for example positioned child this: aasharebubbles *sharebubbles = [[aasharebubbles alloc] initwithpoint:cgpointmake(self.view.frame.size.width/2, (self.view.frame.size.height/2)+170) 170 absolute position. (height/2)+170 ok 4-inch screen, not 3.5-inch screen. there many ways can different device either create different textureatlas different device size or easiest way change skview for eg add line viewcontroller #define is_widescreen ( fabs( ( double )[ [ uiscreen mainscreen ] bounds ].size.height - ( double )568 ) < dbl_epsilon ) -(void)addloadingscene { if (ui_user_interface_idiom() == uiuserinterfaceidiomphone) { if (is_widescreen) {

javascript - Jquery Event Handler ".on()" -

i have problem jquery event handler ".on()". i have button favorite on post on home page. if haven't favorited post: li not active event 1 if have favorited post: li active event 2 why when click multiple times (>1) on button, script same method (event) whereas have class .active on li or not? it's .on() doesn't manage dynamic class change... my html: <ul class="post-list"> <li> <a href="#" class="favorite">favorite</a> </li> <li class="active"> <a href="#" class="favorite">favorite</a> </li> </ul> my jquery: $(function(){ $('.post-list li.active .favorite').on('click', function(e){ e.preventdefault; // event 2 }); $('.post-list li:not(.active) .favorite').bind('click', function(e){ e.preventdefault; //

Dart equivalent of Ruby's instance_eval -

ruby has neat method called instance_eval allows evaluating block of code in context of specific instance. great because 1 can use same block of code in different contexts , different results based on how context defines methods. there equivalent in dart? in other words can take method class , attach , execute on instance in class or define method letting user pass in code corresponding method. know limited form of possible emulate subclassing. it seems there no possibility of doing in dart. use several approaches, depending on needs: creating function context argument of function: somefunction (context, arg1, arg2) { ... } using mixins: https://www.dartlang.org/articles/mixins/ using generics: https://www.dartlang.org/articles/optional-types/#generics

Create MongoDB fields with names based on sub-document values using aggregation pipeline? -

given mongodb collection following document structure: { array_of_subdocs: [ { animal: "cat", count: 10 }, { animal: "dog", count: 20 }, ... ] } where each document contains array of sub-documents, want transform collection documents of structure: { cat: { count: 10 }, dog: { count: 20 }, ... } where each sub-document value of new field in main document named after 1 of values within sub-document (in example, values of animal field used create name of new fields, i.e. cat , dog ). i know how eval javascript snippet. it's slow. question is: how can done using aggregation pipeline? according this feature request , solution, new feature added functionality - function called arraytoobject . db.foo.aggregate([ {$project: { array_of_subdocs: { $arraytoobject: {

c# - No users have been created during Seed method using UserManager in ASP .NET MVC applications -

when seed method runs, records/objects added database. every object added should till try add users application(at bottom of seed method). no 1 added. there lot of sql exceptions thrown posted @ bottom. thrown if seed method empty. how add users entity framework managed database? created code following scott allen's tutorial. protected override void seed(webapplication2.models.applicationdbcontext context) { system.diagnostics.debug.writeline("seed started");//it works if (!context.persons.any()) { var persons = new list<person> { new person{firstname = "john", lastname = "doe", cellnumber = "123-456-789", secondaryphonenumber = "98873213", address = "1street 2",birthdate = datetime.now.date, pesel = "312312312", notes = "annoying"}, new person{firstname = "anna", lastname = "doe", cellnumber = &

Django example for a web app that show git logs -

i looking example how display git log data commit. i commit via shell script; retrieve info commit , make pretty. add on web app in django, capability pass hash , project repo name, can display thee info in nice way. altho can't find tutorial show how build web app django, display page in way. start tutorials today, don't know much. need read file, don't need database nor model, right? is complicate first django app?

handlebars.js - How to execute a Javascript callback when a partial is rendered in Handlebars -

i've created custom class in js wraps handlebars, way can execute callback when template has been rendered, since partials in handlebars automatically generated, how execute callback when partial rendered ? i've tried override '>' helper doesn't work... , have no idea how otherwise. thank guys help. handlebars runtime calls method handlebars.vm.invokepartial exec partial. can override adding callback function call: handlebars.vm.invokepartialorigin = handlebars.vm.invokepartial; handlebars.vm.invokepartial = function () { var args = [].slice.call(arguments, 0); handlebars.vm.invokepartialorigin.apply(handlebars.vm, args); callback(args); };

python - SKLearn Kernel PCA "Precomputed" argument -

i trying perform kernel pca using scikit-learn, using kernel not in implementation (and custom input format recognized kernel). easiest if compute kernel ahead of time, save it, , use in kernel pca. the precomputed argument kernelpca imply able want; however, it's not explained in documentation, , can't find examples of being used. in the unit test source code kernelpca in sklearn , code doesn't ever seem precomputed kernel is. does know how use own precomputed kernel? the precomputed kernel need use @ fit time gram matrix between samples. i.e. if have n_samples samples denoted x_i , need give fit first parameter matrix g defined g_ij = k(x_i, x_j) i, j between 0 , n_samples - 1 . e.g. linear kernel is def linear_kernel(x, y): return x.dot(y.t) x = np.random.randn(10, 20) gram = linear_kernel(x, x) for prediction on x_test need pass x_test = np.random.randn(5, 20) gram_test = linear_kernel(x_test, x) this seen in unit tests, e.g. he

ios - UIButton stops UIScrollView scrolling in Swift -

my uiscrollview area scrolling except when user presses on 1 of buttons: var button:uibutton = uibutton.buttonwithtype(uibuttontype.custom) uibutton button.frame = cgrectmake(0,0,self.width, self.menuheight) button.addtarget(self, action: "buttonclicked:", forcontrolevents: uicontrolevents.touchupinside) button.tag = int(itemno) scrollview.addsubview(button) and buttonclicked code: func buttonclicked(sender:uibutton) { var tag = sender.tag println(tag) } it seems touchupinside method keeps control when user moves finder away button. best way of getting uiscrollview area scroll reliably? try setting delayscontenttouches property of uiscrollview no . also, can set cancancelcontenttouches property yes . (it's yes default, in case.) reference (from docs) : cancancelcontenttouches : boolean value controls whether touches in content view lead tracking. delayscontenttouches : boolean value determines whether scroll view delays handlin

xml - XPATH: selecting text node with an embedded node -

having following xml code: <div class="content"> <ul> <li> <b>item model number:</b> fcc5302q-2 </li> </ul> i used xpath expression select li node text: //*[contains(@class, "content")]//li[b/text()="item model number"]/text() and reason fails pick text of li element. going wrong this? use single quotes match cases watch out brackets use.. try xpath.. //*[contains(@class, 'content')]//li/b[text()='item model number:']/text()

python - web2py doesn't display anything on google app engine -

i'm following tutorials chapter 3 of web2py book work locally in admin interface. trying deploy gae i'm using mac , deployment chapter of book http://web2py.com/books/default/chapter/29/13?search=gae#deploying-on-google-app-engine reference 3 files: web2py/app.yaml web2py/queue.yaml web2py/index.yaml are these files supposed in web2py/web2py.app/contents/resources? i'm guessing docs out of date? also, app.yaml configured use 'welcome' application. did find , replace change 'welcome' 'myapp' upon launching dev_appserver.py web2py/web2py.app/contents/resources folder , navigating localhost:8080 absolutely nothing no, shouldn't doing @ inside .app. that's bundle make easier install things on mac: need create directory project - somewhere inside home directory - , development there.

tcl - All expect statements across procedures in a script pattern match on output produced by the only spawned process in a particular procedure -

consider scenario of sort: #start of script proc {host_ip} { spawn ssh $host_ip #possibly 1 n expect statements pattern #match on output of spawned process } proc b {} { #pattern match using expect statements on #output of spawned process in } proc c {} { #pattern match using expect statements on #output of spawned process in } #call proc's $some_ip b c #pattern match here, not part of procedure, #but expect statement match output of #the spawned process in #end of script from reading expect/tcl online documentation appears have 2 options: return pid of spawned process in a, , explicitly use in expect statements outside of using expect statement form: expect -i $pid_from_a ... there appears magic/global variable if value set pid of spawned process in a, expect statements in script can pattern match on output of spawned process in a. 1 work, have n

gps - How to get lattitude and longitude in android -

this question has answer here: how find out if gps of android device enabled 8 answers hello stack overflowers, i want lattitude , longitude in application. i using below snippet doing job. alert dialog box , when tick mark "use gps satellites" option. don't output if nothing happening. gps being turned on. could guyz please me correcting below snippet. sorry inconvenience caused guyz :( and answering previous questions. :d cheers! this java file writing functions related getting locations etc etc gpstracker.java package com.iot.mymumbaimetro; import android.app.alertdialog; import android.app.service; import android.content.context; import android.content.dialoginterface; import android.content.intent; import android.location.location; import android.location.locationlistener; import android.location.locationmanager; import android.o

asp.net - MVC 4 - 500 error on JSON call -

i have started using vs2012 (yes time). have mvc 4 app. im making json call data db render in html. but im getting 500 internal server error can see in fiddler. im not sure how debug because cant find see c# exception if issue is. so im calling getrecipe in javascript. public jsonresult getrecipe(int rid) { var recipe = _rep.getrecipe(rid); return json(recipe, jsonrequestbehavior.allowget); } my script is var dataservice = new function () { var servicebase = '/recipes/' getrecipeslist = function (callback) { $.getjson(servicebase + 'getrecipeslist', {}, function (data) { callback(data); }); }; getrecipe = function (rid, callback) { $.getjson(servicebase + 'getrecipe', {rid:rid}, function (data) { callback(data); }); }; return { getrecipeslist: getrecipeslist, getrecipe: getrecipe }; } (); var renderer = new function () { renderlist = function () {

java - Hibernate throws SQLGrammarException -

the entity class : @entity @table(name = "moviedetail") public class moviedetailimpl implements moviedetail { @id // primary key @column(name = "idmoviedetail") @generatedvalue(strategy = generationtype.identity) private long id; @column(name = "cast") private string cast; @column(name = "producer") private string producer; @column(name = "director") private string director; @column(name = "trailer") private url trailer; @column(name = "photo") private url photo; @column(name = "plot") private url plot; @column(name = "desc") private string desc; @column(name = "moredetails") private url moredetails; // getters/setters } i trying persist moviedetail entity cast set. rest of fields null . hibernate throws below exception: 014-08-17 21:47:35 info transactionfactoryinitiator:62 - hhh

smartcard - Access the SIM Card with an Android Application? -

i wonder if it's possible access sim card android application you can imei (but want ?), exemple : mtelephonymgr = (telephonymanager)getsystemservice(context.telephony_service); string imei = mtelephonymgr.getdeviceid(); likewise, have string getsimcountryiso(): returns iso country code equivalent sim provider's country code. string getsimoperator(): returns mcc+mnc (mobile country code + mobile network code) of provider of sim. string getsimoperatorname(): returns service provider name (spn). string getsimserialnumber(): returns serial number of sim, if applicable. int getsimstate(): returns constant indicating state of device sim card. string getsubscriberid(): returns unique subscriber id, example, imsi gsm phone. for more, take @ this page and don't forget add correct permission in manifest ( getdeviceid() => requires permission: read_phone_state )

css - bootstrap fa active color -

how can set active-color of fa #9b0722? my html looks following: <div class="topbar"> <div class="container"> <!-- topbar navigation --> <ul class="loginbar pull-right"> <li class="active"> <a href="#" title="startseite"> <i class="fa fa-home"></i> </a> </li> <li class="topbar-devider"></li> <li><a href="#kontakt">kontakt</a></li> <li class="topbar-devider"></li> <li><i class="fa fa-phone"></i><a href="tel:+497147273729"> +49 7147 273729</a></li> <li class="topbar-devider"></li> <li><a href="#">impr

Spring Boot Remove Whitelabel Error Page -

i'm trying remove white label error page, i've done created controller mapping "/error", @restcontroller public class indexcontroller { @requestmapping(value = "/error") public string error() { return "error handling"; } } but i"m getting error. exception in thread "awt-eventqueue-0" org.springframework.beans.factory.beancreationexception: error creating bean name 'requestmappinghandlermapping' defined in class path resource [org/springframework/web/servlet/config/annotation/delegatingwebmvcconfiguration.class]: invocation of init method failed; nested exception java.lang.illegalstateexception: ambiguous mapping found. cannot map 'basicerrorcontroller' bean method public org.springframework.http.responseentity<java.util.map<java.lang.string, java.lang.object>> org.springframework.boot.autoconfigure.web.basicerrorcontroller.error(javax.servlet.http.httpservletr equest) {

ruby on rails - Can't puts parameter from yield -

why can't puts parameter yield? error: undefined local variable or method `options' #<#<class:0x007fd1bd8735e8>:0x007fd1ba3e4fe8> /app/helpers/bootstrap_form_helper.rb ... def inline options = "row_disable" content_tag(:div, class: "row test") { yield(options) } end ... /app/views/signup/new.html.erb ... <%= inline %> <%= options %> <%= person_f.text_field(:last_name, control_col: 7) %> <% end %> ... you cannot access local variable , options , defined in inline method. have access argument passed block inline method, , need have block in new.html.erb accept options argument: ... <%= inline |options| %> <%= options %> <%= person_f.text_field(:last_name, control_col: 7) %> <% end %> ... just clarify little further, don't need call options in new.html.erb. following work: ... <%= inline |foo| %> <%= fo

dart - AngularDart dynamically change the page title -

one of components pulls page title (and content) mongodb based off of route , stores title in instance variable of component's class. best way give mustaches in <title> tag variable display such <title>site title | {{pagename}}</title> ? <title> tag outside of scope of component. maybe controller fit use case i'm not sure state of controller directive or root object is. thought making service , injecting in both seems overkill. there better way this? thanks! i ended making new component , service. my simplified index.html (pretty no changes): <html ng-app> <title>site title</title> </head> <body></body> service store 1 variable: import 'package:angular/angular.dart'; @injectable() class global { string pagetitle; global(); } and component selector of title: library title; import 'package:angular/angular.dart'; import 'package:mypackage/service/global.dart'

php - Get local time of user around the globe and show in local timezone format to other timezone user -

i ran trouble while dealing date , time using php , mysql. trying store local time of user's timezone timestamp on mysql db , convert normal date , time @ time of output. this first time dealing date , time. as understand: can't rely on php's time() returns servers time according server's timezone , same case mysql current_timestamp . i can use javascript user's local timezone , can use date_default_timezone_set() each session. if doing right, confusion starts. as can understand users come around globe, if 2 users (one , india) @ same time, show each others time identical or show difference? mean shouldn't show indian user user has done few hours ago user done @ same time. please let me know if don't understand these things properly. what want achieve is, output of time should show in local time format. ex: time should show in ist format indian user , other country respectively. best way achieve store date in database in standard

java - How can I do a popup menu without right click using awt or swing? -

i program popup menu similar context menu in java using awt or swing, need display when typing key, example "." looking por context menu needs right click. ¿how can it? idea... thanks. start taking @ how use key bindings , how use menus , in particular bringing popup menu basically, need register key binding against component specified key, , when it's corresponding actionperformed event triggered, show popup menu... inputmap im = getinputmap(when_in_focused_window); actionmap = getactionmap(); im.put(keystroke.getkeystroke(keyevent.vk_period, 0), "popup"); am.put("popup", new abstractaction() { @override public void actionperformed(actionevent e) { popup.pack(); dimension popupsize = popup.getpreferredsize(); int width = getwidth(); int height = getheight(); int x = (width - popupsize.width) / 2; int y = (height - popupsize.height) / 2; popup.show(testpane.this, x, y

Android add TabListener inside ActionBarActivity has stopped -

i'm building app mainactivity extends actionbaractivity , inplemented navigationdrawerfragment.navigationdrawercallbacks , has actionbar want have tabs. after runing project error , alert me has stopped : caused by: java.lang.classcastexception: android.support.v4.widget.drawerlayout cannot cast android.support.v4.view.viewpager @ ir.tsms.mainactivity.oncreate(mainactivity.java:43) i want have menuslide inside tab on mainactivity code: package ir.tsms; import android.app.activity; import android.os.bundle; import android.support.v4.app.fragment; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentpageradapter; import android.support.v4.app.fragmenttransaction; import android.support.v4.view.viewpager; import android.support.v4.widget.drawerlayout; import android.support.v7.app.actionbar; import android.support.v7.app.actionbaractivity; import android.view.*; import java.util.locale; public class mainactivity extends ac

ios - Not Able to Push UIViewController -

i'm having issue ui refreshing when go push view controller. here's i'm doing... so, when push notification received app, didreceiveremotenotification method called appdelegate , following executed: uistoryboard *storyboard = [uistoryboard storyboardwithname:@"main" bundle:nil]; receiptviewcontroller *rv; if(screenheight == 480) { rv = [storyboard instantiateviewcontrollerwithidentifier:@"receiptview2"]; }else{ rv = [storyboard instantiateviewcontrollerwithidentifier:@"receiptview"]; } //receiptviewcontroller *rv = [storyboard instantiateviewcontrollerwithidentifier:@"receiptview"]; rv.orderid = userinfo[@"orderid"]; rv.driverid = userinfo[@"driverid"]; rv.cost = [userinfo[@"cost"] intvalue]; [

mysql - Different select statement for different condition -

this current mysql query. current table query in sqlfiddle http://sqlfiddle.com/#!2/6e0420 if select * table , below rn pc pc1 grp e_id 111 a1 a1 175 100 112 a1 a2 100 90 113 b1 b3 101 90 114 b1 b1 100 90 115 b1 b5 100 90 116 c1 c1 100 90 but trying output rn pc pc1 grp e_id 111 a1 a1 175 100 112 a1 a2 113 b1 b3 114 b1 b1 100 90 115 b1 b5 116 c1 c1 100 90 so condition if pc=pc1 grp , e_id should shown, otherwise if pc!=pc1 grp , e_id should empty current query select * table1 rn in(select rn table1 group rn having count(*)=1) , (pc = pc1) solution select rn, pc, pc1, case when pc = pc1 grp else null end grp, case when pc = pc1 e_id else null end e_id table1 rn in(select rn table1 group rn having count(*)=1) qn2: above solution have added count = 1 because have sql query if count > 1. how combine both query, split count =1 , count >1 below sql query select

encoding - Word-wrapping multibyte characters in PHP for console output -

i'm trying align pieces of text fixed number of columns. text meant logging purposes , may contain user data, cannot assume input. ease of viewing want make sure that, when viewed in standard linux console text fixed number of characters wide. php not have multibyte equivalent of wordwrap -function. several frameworks have own version of it. i've been trying out several multibyte functions, amongst these answers in this question in order encode utf-8 text unicode display. of answers seem use 'mb_strlen' calculate substring lengths. to ensure file wanted display recognized utf-8, prepended byte order mark text. far know, 'should' cause linux recognize , format correctly. then, tried encode long strings. strings such 'ëëëëëëëë...' correctly cut off after specified n character positions. however, string such '₩₩₩₩₩₩₩₩₩...' not. contains characters double length in unix console , cut off later supposed to. in fact, seems twice characters