Posts

Showing posts from July, 2013

python - Can executables made with py2app include other terminal scripts and run them? -

so have nice python app os x working great. runs external terminal script , include in python app. ideally, i'd able run py2app , have script bundled executable , able include , run in python portion of code. possible? thanks in advance! extra edit: script using compiled. can't inside , paste it. see http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html#option-reference , @ --resources parameter. example: python setup.py py2app --resources foo if shell script, valid thing do. binary executable, it's bit more hacky. first, p2app's documentation says "not code!". second, os x documentation says not put executables in resources directory. main reason code signing: default settings "seal" in resources part of main app's signature, separate executables not supposed sealed way, they're supposed signed separately. however, being said, still work. except won't end +x permissions, after py2app step, you'll have "chmod +x ...

mongodb: field sorted by number of occurances -

i have collection each document representing virtual auction. want find common item id given time period. in sql, i'd select item, count(*) count group item , usual sorting , limits. there mongodb equivalent this? mongodb has several options here. in version 2.1.0+ can use new aggregation framework . there's conversion chart right here . in older versions can use either map / reduce for simple versions of aggregation ca use special aggregation operators . each of these options have different syntax , different speed. in of these cases, find these options relatively slow. map / reduce jobs intended run "off-line", "cron job" or "scheduled task". note if plan lot, want pre-aggregate data.

C++ basic array assignment is not working -

so have function f(int d[],int a[],int len){ for(int k = 0; k < len; k++) d[k] = a[k]; and if output d numbers wrong. function f called d initialised int* d = new int[100000]; in main function , a because output in function , looks ok. so... can't understand problem is... tried memcpy(d+k,a+k,sizeof(int)); , doesn't work. your loop works perfectly. problem must somewhere else in code. here example program copies data in 3 different ways: for loop, memcpy , , std::copy : #include <algorithm> #include <cstring> #include <iostream> #include <iterator> void copy1(int d[], int a[], int len) { for(int k = 0; k < len; k++) d[k] = a[k]; } void copy2(int d[], int a[], int len) { std::memcpy(d, a, len*sizeof(int)); } void copy3(int d[], int a[], int len) { std::copy(a, a+len, d); } int main () { int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int *d = new int[10]; std::ostream_iterator<int> out(std::cout, ","); // first, print...

python - unpack the first two elements in list/tuple -

is there way in python this: a, b, = 1, 3, 4, 5 and then: >>> 1 >>> b 3 (the above code doesn't work throw valueerror: many values unpack .) just add nolen's answer, in python 3, can unpack rest, this: >>> a, b, *rest = 1, 2, 3, 4, 5, 6, 7 >>> 1 >>> rest [3, 4, 5, 6, 7] unfortunately, not work in python 2 though.

PHP MYSQLI number of rows doesnt work no errors -

i have login form when user clicks login checklogin.php called , should check username , password matches record on database if true else print wrong password or username so far wrong password username though correct username&&password. have made somechanges no echo, printf or error how can fix issue? form <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#cccccc"> <tr> <form name="form1" method="post" action="checklogin.php"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#ffffff"> <tr> <td colspan="3"><strong>member login </strong></td> </tr> <tr> <td width="78">username</td> <td width="6">:</td> <td width="294"><input name=...

sshfs - Why is vim syncronous in file loading and saving? -

i'm working on vim on sshfs mounted filesystem high latency. opening , saving file takes 9 seconds of blocking editor. is there way can block tab i'm in , still work other tabs while files saving , loading? writing blocking operation because vim single threaded: can't 2 things @ same time. afaik when vim has written file locally, sshfs uploads remote server before "notifying" vim it's done. whole process can , take quite time. there better ways: vcs (git, svn, mercurial…) or ftp client folder monitoring capabilities (transmit, yummy ftp, fetch…) example.

php - MySQL finding rows in one table with information from another -

currently, have 2 mysql tables. first table stores relation between friend , picture. table 1 id | pic_id | friend_id ---------------------------- 0 | 123 | 84589 1 | 290 | 11390 2 | 884 | 84589 table 2 second table stores more information pic... id | pic_id | title | color | detail ---------------------------------------------- 0 | 123 | hello | black | brush 1 | 124 | world | red | paint 2 | 884 | sample | green | star i have friend_id , need grab pic_id table 1 , use pic_id grab columns table 2(title, color, detail)... how in mysql? thank you! simply join 2 tables. select b.title, b.color, b.detail table1 inner join table2 b on a.pic_id = b.pic_id friend_id = 84589

What is the use of cvGetRows() function in OpenCV? -

Image
when should use function. can explain me example? according documentation, it returns array row or row span. returns rows specified. i explain of python terminal: load image in grayscale mode , check width , height. >>> import cv2.cv cv >>> img = cv.loadimage('approx2.jpg',0) >>> img <iplimage(nchannels=1 width=300 height=300 widthstep=300 )> see, image 300x300 size. below image. taking sum pixels, >>> cv.sum(img) (1252271.0, 0.0, 0.0, 0.0) now apply our first function, cv.getrow() >>> row = cv.getrow(img,150) >>> row <cvmat(type=42424000 8uc1 rows=1 cols=300 step=300 )> >>> cv.sum(row) (14279.0, 0.0, 0.0, 0.0) i took 150th row , took sum of elements in row. see resulting image has height = 1. now taking function cv.getrows(). >>> rows = cv.getrows(img,0,150) >>> rows <cvmat(type=42424000 8uc1 rows=150 cols=300 step=300 )> >>> cv.sum(rows) (802501.0, 0....

javascript - Create several instances of a module with different values -

this simple problem need create javascript equivalent n instances of 'class' state must totally separate. like: var car = new car('ford'); var car = new car('toyota'); how can achieve this? you can use array object store them: var cars = []; cars.push(new car('ford')); cars.push(new car('toyota')); cars[0].beep(); you can iterate on stored instances using for loop: for (var = 0; < cars.length; i++) { var car = cars[i]; car.beep(); }

mongodb - Can we use Hadoop and any NoSQL database with Android instead of SQLite -

can kindly tell can use hadoop , nosql database mongodb tec android instead of sqlite. , if yes how (i mean process so), because sqlite embedded in android , mongodb etc have use separate server etc or can used embedded. , db better use sqlite or mongodb hadoop resource intensive. developed large cluster of machines not single mobile device. added strength of nosqls large cluster of machines can process them. if have such limited in storage , processor power machine mobile device suffer great overhead. maybe possible set hadoop , nosql, have pay orders of magnitude in performance. suggest not - better start off learning traditional sql.

c# - System.Diagnostics.Process.Start throwing threadabort exception on server -

in website using system.diagnostics.process.start preview particular file. working fine on local server but, throws threadabortexception on online server when try preview file. the preview of happens on button click of repeater. code given below: if (e.commandname == "preview") { button btn = (button)e.commandsource; string filepath = server.mappath("~/upload"); string _downloadableproductfilename = filename; system.diagnostics.process.start(filepath + "\\" + _downloadableproductfilename); } to use process on asp.net server need configure application full trust. are sure need spawn process server side? seems aren't using output.

php - How to set default controller in Yii -

is there way specify default controller in yii? instead of using sitecontroller? thank in advance. to set default controller homepage's controller on yii php-framework. must modify core defaults controller (site/index) on /protected/config/main.php return array( 'name' => 'web application', 'defaultcontroller' => 'home ', );

Merging one-by-many CSV files in Python -

i have output of series of stochastic simulations in form of .csv file this: run,id,var 1,1,7 1,2,9 1,3,4 2,1,3 2,2,4 2,3,8 etc. along that, have data file, .csv, formatted so: id, var2, var3 1,0.89,0.10 2,0.45,0.98 3,0.27,0.05 4,0.98,0.24 note : there values in data file do not appear in simulation file. i'd these ignored. what i'd write script takes each value id first .csv file, , finds var2 , var3 , puts together, end like: run, id, var, var2, var3 1,1,7,0.89,0.10 1,2,9,0.45,0.98 1,3,4,0.27,0.05 2,1,3,0.89,0.10 2,2,4,0.45,0.98 2,3,8,0.27,0.05 any suggestions on way this? confess @ limits of understanding data handling in python. i'd got fair sense of how in sas, i'd prefer keep one-language task can processed single script. ouput.csv: run, id, var 1, 1, 7 1, 2, 9 1, 3, 4 2, 1, 3 2, 2, 4 2, 3, 8 data.csv: id, var2, var3 1, 0.89, 0.10 2, 0.45, 0.98 3, 0.27, 0.05 8, 0.4, 0.5 note if have entries within data.csv, not present in ouput.csv won't af...

java - How to get FolderName and FileName from the DirectoryPath -

i have directorypath "data/data/in.com.jotsmart/app_custom/foldername/filename" stored string in arraylist like arraylist<string> a; a.add("data/data/in.com.jotsmart/app_custom/page01/note01.png"); now path want page01 seperate string , note01 seperate string , stored 2 string variable. tried lot, not able result. if 1 knows me solve out. f.getparent() returns pathname string of abstract pathname's parent, or null if pathname not name parent directory. for example file f = new file("/home/jigar/desktop/1.txt"); system.out.println(f.getparent());// /home/jigar/desktop system.out.println(f.getname()); //1.txt update: (based on update in question) if data/data/in.com.jotsmart/app_custom/page01/note01.png valid representation of file in file system then for(string filenamestr: fileslist){ file file = new file(filenamestr); string dir = file.getparent().substring(file.getparent().lastindexof(file.separator) + 1);//page01 string f...

C++ class object pointers and accessing member functions -

i'm bit new c++ , try work things qt , came across confusing thing: the concepts on various tutorials state like: class *obj; *obj - display value of object stored @ referenced memory obj - address of memory pointing so, like *obj=new class(); but if want access function, have obj->function1(); instead of *obj->function1(); -- not sure why, since normal objects [ normalobj.function1(); ] work, since that's value directly. so, pointer objects why use memory reference access function, or in case of normal objects also, references p.s: can guide me tutorial of usage of pointers in c++, queries these can directly addressed in it. the * symbol used define pointer , dereference pointer. example, if wanted create pointer int, do: int *ptr; in example, * being used declare pointer int . now, when not declaring pointer , use * symbol declared pointer, dereferencing it. know, pointer address. when dereference pointer, obtaining value being pointed address. exa...

validation - BlackBerry Date Validator -

is there easy way validate input date in balckberry? tried regex couldn't success. 1 have validation method. thanks. as date string in parts, use java.util.calendar class build java.util.date instance. in case of exception entered date not correct. intercept exception in validation method , return false.

ruby on rails - new layout vs MVC in ror -

i learning ror, , wanted know if want make page google's homepage, must use model+controller+view? or can use new layout (this because dont need db or entity save search query) thanks you don't need generate model , still need controller , relevant views. if want bunch of static pages, might have pages controller , in there you'll have methods set different pages want. match each of methods views of same name. layouts more base view templates. simple app might have 1 layout. see layouts , rendering in rails more info. first though if you're serious learning rails i'd suggest working through tutorial hartle's rails tutorial: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book - it'll take through basics , more.

functional programming - What is Lambda definability? -

while reading lambda calculus, came across word lambda definability . can please explain couldn't find resources on that. thanks see church-turing thesis, lambda-definable functions (from church) give "effectively computable" functions. turing showed programs implementable on turing machine equivalent lambda-definable functions.

ios - How to change icon files with code constant on xCode? -

i'm building app has free version , paid version. difference between apps define line of constant in code (it creates code needed add on each app). i want icons change according definition. knows how can that? can choose example between different info.plist files using code generated? please help. you want setup duplicate target of main target lite version. in secondary target, should identical except preprocessor macro add lite_version . should point different info.plist then, in code @ compile time, can use #ifdef lite_version compile lite code vs reg code when compile target.

Django/python querysets - adding another "child" queryset as an item to each list object? -

apologies if answer obvious - i'm new django/python & haven't been able find solution in searching far. i have straightforward queryset, eg members = librarymembers.objects.all() with can do:- for m in members: member_books = libraryborrows.objects.filter(member_id=m[u'id']) what want though able serialize results json, looks this:- { "members": [ { "id" : "1", "name" : "joe bloggs" "books": [ { "name" : "five go exploring", "author" : "enid blyton", }, { "name" : "princess of mars", "author" : "edgar rice burroughs", }, ] } ] } to mind, obvious thing try was:- for m in members: m[u'books'] = libraryborrows.objects.filter(member_id=m[u'id']) however i'm getting typeerror: 'libraryborrows' object not support item assignment is there way achieve i'm after? model instances not indeed n...

ios - UIButton's click action? -

i following book learn ios programming. uibutton, supposed have click action. saw actions touch down etc. also, want know why default action not "touch down" "touchupinside" i using xcode 4.3. click action in ios represented touchupinside , since click mouse event touchupinside, means user touched down on button, , touch up, while still on same button, normal behavior when want tap on button

Passing action to Android Intent using constructor and setter method -

i have written run simple android camera application run on android 4. the code had camera intent defined intent cameraintent = new intent(); cameraintent.settype(android.provider.mediastore.action_image_capture); when tried run application throwing below exception :- 07-07 12:44:09.755: e/androidruntime(11533): android.content.activitynotfoundexception: no activity found handle intent { typ=android.media.action.image_capture } however when tried run same program defining "cameraintent" below worked fine - intent cameraintent = new intent(android.provider.mediastore.action_image_capture); i thought passing "action" intent through setter or through constructor same. but doesn't seems so, passing "action" through setter method throws exception while passing through constructor new intent works fine. idea why so? this code work fine: intent cameraintent = new intent(); cameraintent.setaction(android.provider.mediastore.action_image_capture);...

django - Unrelenting TemplateSyntaxErrors -

update #7 : i removed first line , put in place second line below copied jinja2 link jinja2 install docs . still error below. # google.appengine.ext.webapp import template jinja2 import template file "/users/brian/googleapps/youpoll/views.py", line 271, in self.response.out.write(template.render(path, template_values)) nameerror: global name 'template' not defined info 2012-07-08 22:43:53,053 dev_appserver.py:2952] "get /?id=testbschott http/1.1" 500 this appengine worked little while ago non-django code in template files. furthermore, if execute following code in gae interactive console, works, though contains {%- if ... -%} code think unique jinja2, not django. from jinja2 import template template = template('{%- if true -%}hello {{ name }}!{% endif %}') print template.render(name='john doe') update #6 : ok, found variable template being defined. it's below. jinja_environment.filters['datetimeformat'] = datetimeformat c...

jquery - User Interaction Enabled Javascript -

i writing javascript application , going wrap in native ios application. block user interaction on uiwebview containing js app second or 2 following event. normally use self.webview.userinteractionenabled = no event triggered in javascript. how can block user interacting web view? guessing return false on touch event of sort? it's scrolling want block. thanks! when event occurs in javascript code can send message native wrapper using following method: set following uiwebviewdelegate method (don't forget set delegate uiwebview): - (bool)webview:(uiwebview*)webview shouldstartloadwithrequest:(nsurlrequest*)request navigationtype:(uiwebviewnavigationtype)navigationtype { nsurl *url = [request url]; if ([[url scheme] isequaltostring:@"block"]) { // blocking code here return no; } return yes; } now when event happens, call delegate method javascript code: window.location.href = "block://";

Class not found PHP OOP -

i can't work. <?php function __autoload($classname){ include 'inc/classes/' . $classname . '.class.php'; } __autoload("queries") $travel = new queries(); echo $travel->getpar("price"); ?> and inc/classes/queries.class.php file. <? class queries { function getpar($par, $table='travel', $type='select') { $result = $db->query(" $type * $table $par "); while ($row = $result->fetch_assoc()) { return " $row[$par] "; } } } ?> it returns "class 'queries' not found". what's wrong it? edit: fatal error: cannot redeclare __autoload() (previously declared in /index.php:5) in /index.php on line 5 what hell? can't redeclare function declared in own line, why? instead of dreadful abomination, should learn how utilize spl_autoload_register() : spl_autoload_register( function( $classname ){ $filename = 'inc/classes/' . $classname . '.class.php'; if ( !...

Need GStreamer command for streaming video -

can 1 give me working (gstreamer) command streaming video on udp here example using test audio , video source gst-launch audiotestsrc ! ffenc_mp2 ! mpegtsmux name=mux ! udpsink host=239.1.1.1 auto-multicast=true port=1234 videotestsrc ! ffenc_mpeg2video bitrate=200000 ! mux. you can play in vlc using url: udp://@239.1.1.1:1234 if not want unicast, multicast instead, enter ip address @ udpsink options, example host=192.168.1.1 . vlc url becomes udp://@:1234 .

statistics - Apply ANOVA tests in MATLAB neural networks.toolbox -

matlab has nn toolbox anova tests. want apply anova tests nn model after training. how it? references or examples welcome. i'm not sure starting data looks here reference anova function within matlab. believe it's in stats package if you're using nn toolbox think have access stats toolbox too.

css - Fade in fade out on image hover using CSS3? -

i wondering if possible state unhover class @ on image? what trying achieve when hovers on image fade in , when unhover fades out? heres code, got fade in work when hovers on image need fade out when unhover... hope made sense. http://jsfiddle.net/l7xcd/ this should work you! http://jsfiddle.net/l7xcd/1/ let's use great mozilla documentation explain this: transition rovide way control speed of animation changes css properties. instead of having animation changes take effect instantly, can transition property changes on specified time period. also used transition timing functions (ease, linear, easy-in, easy-out, easy-in-out) timing functions determine how intermediate values of transition calculated. timing function can specified providing graph of corresponding function, defined 4 points defining cubic bezier ccs markup: img { opacity: 0.6; transition: opacity 1s ease-in-out; -moz-transition: opacity 1s ease-in-out; -webkit-transition: opacity 1s ease-in-out; } img:...