Posts

Showing posts from August, 2013

sql - c# List using where statement -

my application asp.net mvc using linq-to-sql. trying use following filter view. i have added filter sql server view using: where (dbo.client.recstatus null) or (dbo.client.recstatus = 0) it works when run in sql server management studio, still see entries in application. i tried filter again in repository using: list<vw_client_info> searchresult = new list<vw_client_info>().where(c=> c.recstatus != 1); recstatus smallint i following error: cannot implicitly convert type 'system.collections.generic.ienumerable' 'system.collections.generic.list'. explicit conversion exists (are missing cast?) i appreciate assistance, in advance. seems forget use tolist() method @ end. try this: list<vw_client_info> searchresult = new list<vw_client_info>().where(c=> c.recstatus != 1).tolist();

python - for loops, indexing, taking the min value of a list -

i have 2 shapefiles: of lakes , of cities. need find closest city each lake , add name of city lake shapefile. have: for lake in lake_cursor: lake_geom = lake.shape city_dist_list = [] #create city dis list = list of dist 1 lake each city cityid in range(0, city_length-1): #obtaining x , y both cities , lakes cityx = citylist_x_coor[cityid] cityy = citylist_y_coor[cityid] lakex = lake_geom.centroid.x lakey = lake_geom.centroid.y #calculate distance dist = math.sqrt((cityx-lakex)**2 + (cityy-lakey)**2) #add dist city dist list city_dist_list.append(dist) closest = min(city_dist_list) closestid = city_dist_list.index(closest) lake.city_name = citylist_city_name[closestid] lake.x_coor = citylist_x_coor[closestid] lake.y_coor = citylist_y_coor[closestid] print closest but keep getting error message starting @ lake.city_name . python shell isn't telling me wrong - ideas?

c++ - exit() or _exit() after forking? -

i writing program requires communicating external program two-way simultaneously, i.e., reading , writing external program @ same time. i create 2 pipes, 1 sending data external process, 1 receiving data external process. after forking child process, becomes external program, parent forks again. new child writes data outgoing pipe external program, , parent reads data incoming pipe external program further processing. i've heard using exit(3) may cause buffers flushed twice, afraid using _exit(2) may leave buffers left unflushed. in program, there outputs both before , after forking. which, exit(3) or _exit(2), should use in case? the below main function. #includes , auxiliary function left out simplicity. int main() { srand(time(null)); ssize_t n; cin >> n; (double p = 0.0; p <= 1.0; p += 0.1) { string s = generate(n, p); int out_fd[2]; int in_fd[2]; pipe(out_fd); pipe(in_fd); pid_t child = fork()

java me - How to autostart j2me application on foreground? -

i'm trying make j2me application auto-start when phone powered on. (the phone sonim xp1301.) i added jad attribute "midlet-launch-power-on: yes", , application starts automatically stays on background... useless me because application ui-based , requires user interaction... is there other jad attribute force application start in foreground , or j2me command bring application foreground? edit: @ sonim developer site found this: "we have our emulator library in can check whether application in background. once result can bring foreground javabackgroundmode.isrunninginbackground(midlet m); used check whether midlet in background. if returns true means in background. javabackgroundmode.bringtoforeground(this); used bring app foreground." ..but have no idea means... "emulator library"? can download , how use it? if try add line code: javabackgroundmode.bringtoforeground(this); ..netbeans gives me error "cannot find sybmol: variabl

pgadmin - PostgreSQL Exception handling detail with GET STACKED DIAGNOSTICS -

i using simple function exception handling code is.. create or replace function test(int4) returns void $$ declare v_state text; v_msg text; v_detail text; v_hint text; v_context text; begin begin insert test2 (id) values ($1); exception when others stacked diagnostics v_state = returned_sqlstate, v_msg = message_text, v_detail = pg_exception_detail, v_hint = pg_exception_hint, v_context = pg_exception_context; raise notice e'got exception: state : % message: % detail : % hint : % context: %', v_state, v_msg, v_detail, v_hint, v_context; end; return; end; $$ language plpgsql; but giving error: syntax error @ or near "stacked" stacked diagnostics . i using postgresql 9.1 , pgadmin 3. you need upgrade postgresql 9.2 ... 9.1 version doesn't su

regex - How to convert this sed command to Python script? -

i have 1 old shell script include sed command below. source data($tmp) html table. sed '/<table border/,/table>/d' $tmp > $out can me convert command python script? can't figure out how regular expression. many thanks.. the script copys lines input file output file, unless finds line containing <table border , deletes lines until finds /table> , continues writing further lines. so 1 possibility be: with open('in') inf, open('out', 'w') outf: while true: line = inf.readline() if '<table border' in line: while true: line = inf.readline() if not line or '/table>' in line: line = inf.readline() break if not line: break outf.write(line)

c++ - Regarding create a NTL class type -

thanks looking i trying create class long lprime,lgenerator; lprime = atol(vout[1].c_str()); zz aliceprime; aliceprime = new zz(99999,lprime); i not sure init_val_type asking me input. i got error: udpechoclient.cpp:85:34: error: no matching function call ‘ntl::zz::zz(int, long int&)’ udpechoclient.cpp:85:34: note: candidates are: /sw/include/ntl/zz.h:113:1: note: ntl::zz::zz(ntl::zz&, ntl::init_trans_type) /sw/include/ntl/zz.h:113:1: note: no known conversion argument 1 ‘int’ ‘ntl::zz&’ /sw/include/ntl/zz.h:176:8: note: ntl::zz::zz(ntl::init_val_type, double) /sw/include/ntl/zz.h:176:8: note: no known conversion argument 1 ‘int’ ‘ntl::init_val_type {aka const ntl::init_val_struct&}’ /sw/include/ntl/zz.h:180:8: note: ntl::zz::zz(ntl::init_val_type, float) /sw/include/ntl/zz.h:180:8: note: no known conversion argument 1 ‘int’ ‘ntl::init_val_type {aka const ntl::init_val_struct&}’ /sw/include/ntl/zz.h:172:8: note: ntl::zz::zz(ntl::init_val_

session - Spring MVC SessionAttributes with ModelAttribute usage -

i trying learn spring mvc recently. seems did not understand functionality of @sessionattributes , @modelattribute annotations. this part of controller: @sessionattributes({"shoppingcart", "count"}) public class itemcontroller { @modelattribute("shoppingcart") public list<item> createshoppingcart() { return new arraylist<item>(); } @modelattribute("count") public integer createcount() { return 0; } @requestmapping(value="/addtocart/{itemid}", method=requestmethod.get) public modelandview addtocart(@pathvariable("itemid") item item, @modelattribute("shoppingcart") list<item> shoppingcart, @modelattribute("count") integer count) { if(item != null) { shoppingcart.add(item); count = count + 2; } return new modelandview(new redirectview("showallitems")); } basically there jsp listing items. wenn user click "addtocart&quo

android - Actionbarsherlock use activities or fragments -

i've been working on school project in course mobile prototype couple of weeks when our mentor said should change our way of navigate in app. before app started simple menu user chose feature open, different activities, listactivities, mapactivities, activities custom views, ect. we found actionbarsherlock library make nice tab bar. should change our activities fragments (supportfragments runs 2.3.3) or can keep (normal) activities? if how best show under each tab. actionbarsherlock have been implemented in our apps start activity , "only" need make navigation existing activities or change them fragments. do tell if isn't clear have described or need further information. if wish can use activities actionbarsherlock it depends on want achieve , use of fragment might making cleaner app. actionbarsherlock sample: 1° tab bar fragment & viewpager 2° tab bar fragment

json - Kendo UI Grid Inserts/Updates create Duplicate Records (again) -

i have same problem daniel had in topic, solution doesn't work me: http://www.kendoui.com/forums/ui/grid/kendo-ui-grid-inserts-updates-create-duplicate-records.aspx#-jhxqrrnaugstfjac-ojwg so use-case. users adds 2 new records 1 after another: presses "add new record" button of grid fills fields (name="alex", amount=10, comment="first"). record 1 ready. press 'save'. (data goes controller , database) user see 1 record in grid press "add new record" button again fills fields (name="bob", amount=20, comment = "second"). record 1 ready. press 'save'. data goes controller , database. in moment happens , grid send ajax request again record 1 data controller. user updates grid , see 3 records "alex | 10 | first" (duplicated record) id = 1 "bob | 20 | second" id = 2 "alex | 10 | first" id = 1 they recommend return id correct binding\update of data

javascript - jQuery focus on Alert box with clicking on button -

i have form, after submitting form when button clicked using jquery this. function validate(){ if($('#firstname').val() =="") alert("please enter first name"); else if($('#lastname').val() == "") alert("please enter last name"); else if( $('#association').val() == "") alert("choose association"); else if($('#association_no').val() == "") alert("please enter association number"); else $('#register').submit(); } $(function(){ $(".enter_submit").keyup(function(event) { if(event.keycode === 13) validate(); }) }) the alert box displaying fine issue when press enter after alert box displayed, gives alert box instead of getting rid of alert(works fine when click ok mouse). in ff, gives #prevent more alerts page. believe still focusing on form after alert displayed.

python - Customized django manage.py use case -

i using django use object relational mapper(orm) feature and, currently, have nothing web-framework. @ present have been able customize django.setting suit database needs , defined test data models bumped manage.py , required build database tables etc. how can call manage.py (or achieve purpose) within module model defined , not command line? well, hedde right sqlalchemy being better suit, if still want programmatically access manage.py commands, checkout answers question . django project has predefined structure , syncdb in scope of project affect apps part of installed_apps in settings.py file. the fun stuff can have on-the-fly schema alteration django-mutant . of course, should use when you're absolutely sure when , you're doing :))) .

c style string and dynamic allocation in c++ -

i must implement bunch of methods allocates, modify , free 2d array of c-style string. cannot use string nor vectors nor stl container. getnewmat : char*** getnewmat(int w, int h){ char*** newmat = new char**[h]; for(int = 0 ; < h ; i++){ newmat[i] = new char*[w]; for(int j = 0 ; j < w ; j++) newmat[i][j] = null; } return newmat; } fillmat void fillmat(char***mat, int x, int y, char* newel){ mat[y][x] = newel; //this produce segfault (even index) } showmat : void showmat(char*** mat, int w, int h){ for(int = 0 ; < h ; i++){ for(int j = 0 ; j < w ; j++) cout << mat[i][j]; } cout << endl; } so, can please tell me what's wrong this? in fillmat method this: mat[y][x] = newel; where x , y dimensions of 2 ranks of array. line cause segmentation fault because you're going outside bounds of array. mat indexed 0 length - 1 , setting x , y going

android - How to use two drawable background images in custom listview for a messaging app -

i'm developing kind of messaging app android. when messages loaded custom list view database, displayed ok. want them displayed native messaging app of android. have 2 images sender , receiver using 9patch. want display image http://s21.postimg.org/bj6idzdaf/example.png . i'm having http://s23.postimg.org/805pfdxqz/example1.png . here code of row: <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/chatlinearlayout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/me" android:orientation="vertical" > <!-- user , createdat --> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingbottom="0dp&qu

android - Linux Script run on Startup -

i'm looking build cyanogenmod roms android, i've followed tutorial setup build environment. this tutorial followed: http://wiki.cyanogenmod.org/w/build_for_i9305#prepare_the_device-specific_code the question have is, instead of executing: cd ~/android/system source build/envsetup.sh every time want build rom, there way run on boot? tried create script me , run in startup applications couldn't work. #!/bin/bash cd ~/android/system/ source build/envsetup.sh it throws error: kane@androidvm ~ $ sudo sh ~/android/system/build/envsetup.sh /home/kane/android/system/build/envsetup.sh: 1: /home/kane/android/system/build/envsetup.sh: syntax error: "(" unexpected what doing wrong? you can try add code in ~/.bashrc. think need launch terminal work. executed when terminal open.

android - Importing gmail contacts using GoogleAuthUtil -

i'm trying add import contacts gmail account function in android app. first problem access token gmail. i've found there googleauthutil class can me it. here code: private void importcontactsfromgmail() { showprogressdialog(); gettokentask gettokentask = new gettokentask(); gettokentask.execute(); string token = ""; try { token = gettokentask.get(); } catch (exception e) { e.printstacktrace(); } system.out.println(token); hideprogressdialog(); } private class gettokentask extends asynctask<void, void, string> { @override protected string doinbackground(void... params) { string token = ""; try { token = googleauthutil.gettoken(activity, <my_gmail_account>, "https://www.google.com/m8/feeds/"); } catch (exception e) { e.printstacktrace(); } return token; } } now after calling googleauthutil.gettoken

asp.net - Role implementation not picked up by menu list -

i implementing user roles. have menu list drawn in html , controlling visibility of them code behind. have 3 database tables, user w/ user_number, user_role_id , roles w/ role_id, role_name , user_roles w/ user_role_id, user_number, role_id . role_id integer linked role name. each user assigned 1 of 6 of these integers , role based on this. work expected apart administrator role int 3. allow me display or hide table based on role, exception of lstadminmenu . have tested other roles , menus , can show menu in role except lstadminmenu in administrator role . menu contorl is: <li runat="server" id="lstadminmenu"><a class="menuitem">administration</a> <ul class="submenu"> <li><a href="../administrative/createstudent.aspx">create student</a></li> <li><a href="../administrative/enrolls

How to wrap text till the allowed height, and then show ellipses if text overflows at the last line - CSS -

this question has answer here: with css, use “…” overflowed block of multi-lines 17 answers i have div -: <div id="prep">hey jony whats up. new solar radars of great use , may evern put of wacky scientist brain strom. crazy!</div>. this associated css -: #prep { height:32px; font-weight:bold; overflow:hidden; text-overflow:ellipsis; font-family: arial, helvetica, sans-serif; font-size:13px; line-height:16px; display:block; } clearly 2 lines of text visible. since text not fit in the div, want show ellipses @ end of last visible line of text. you need add width, , white space. width: 56px; white-space: nowrap;

c - __isoc99_scanf and scanf -

i studying various compiler option in gcc , observing changes when made changes in standard used. $ gcc q1.c -wall -save-temps -o q1 $ vi q1.s i see 1 of opcodes as call __isoc99_scanf and when compile c89 standards $gcc q1.c -wall -save-temps -std=c89 -o q1 $ vi q1.s i see opcode as call scanf what difference between these 2 forms of scanf ? link can see source highly appreciated. the reason strict following of c99 disallow existing gnu extension conversion specifiers. in glibc 2.17, in libio/stdio.h there comment: /* strict iso c99 or posix compliance disallow %as, %as , %a[ gnu extension conflicts valid %a followed letter s, s or [. */ extern int __redirect (fscanf, (file *__restrict __stream, const char *__restrict __format, ...), __isoc99_fscanf) __wur; extern int __redirect (scanf, (const char *__restrict __format, ...), __isoc99_scanf) __wur; extern int __redirect_nth (sscanf, (const char *__restrict __s, const ch

Android Creating a playable story -

i trying create playable story progresses via choices made player. at each stage there 2 or 3 choices. e.g. text.settext("you reach stairs"); button1.settext("go up"); button2.settext("go down"); button3.settext("jump off cliff"); however way can think of making work having huge line of if else statements inside each other, or having 40 different activitys. is there simpler way of doing this? off top of head, this: private void stairs() { text.settext("you reach stairs"); button1.settext("go up"); button1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { attic(); } }); button2.settext("go down"); button2.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { basement(); } }); button3.settext("jump off cliff");

weblogic11g - OBIEE 11g not working : not entering to analytics? -

i'm using obiee 11g, , have problem logging analytics, post username , password, tells me invalid username !! here follows entire stacktrace of problem ( weblogic ) : at com.google.inject.scopes$1$1.get(scopes.java:53) @ com.google.inject.internalfactorytoprovideradapter.get(internalfactor ytoprovideradapter.java:41) @ com.google.inject.bindingbuilderimpl$factoryproxy.get(bindingbuilderi mpl.java:299) @ com.google.inject.providertointernalfactoryadapter$1.call(providertoi nternalfactoryadapter.java:37) @ com.google.inject.injectorimpl.callincontext(injectorimpl.java:756) @ com.google.inject.providertointernalfactoryadapter.get(providertointe rnalfactoryadapter.java:35) @ com.google.inject.scopes$1$1.get(scopes.java:53) @ com.google.inject.internalfactorytoprovideradapter.get(internalfactor ytoprovideradapter.java:41) @ com.google.inject.injectorimpl$singleparameterinjector.inject(injecto rimpl.java:640) .

php - file input not work in joomla 2.5 component -

i have simple component must upload file server, when submit form see error: notice: undefined index: uploaded_file in d:\wamp\www\joomla2.5\components\com_print\print.php on line 13 component in frontend , code is: <?php // no direct access defined('_jexec') or die; jimport('joomla.application.component.controller'); ?> <form enctype="multipart/form-data" action="<?php $_server['php_self']; ?>" method="post"> <input type="hidden" name="max_file_size" value="1000000" /> choose file upload: <input name="uploaded_file" type="file" /> <input type="submit" value="upload" /> </form> <?php echo $_post['uploaded_file']; echo $_post['max_file_size']; ?> please help. the datas input of type "file" in $_files not $_post var_dump($_files['uploaded_file']);

php - Protecting mysql database from injection attacks with pdo script -

recently, database experienced attack mysql injections. did not know injections before incident. however, have been studying on , how prevent it, cannot seem work script when try add sql injection protection (it works fine on it's own). how pdo script add sql injection protection? <?php $username = $_get["hits"]; $sq = "something"; $pu = $_get["something"]; $jjj = "something"; $fff = "something"; $dbh = new pdo("mysql:host=$sq;dbname=$pu", $jjj, $fff); $sql = 'select autoj tabl username = ?'; $params = array( $username ); if ( isset( $_get['q'] ) ) { $sql .= " , myname ?"; $params []= '%'.$_get['q'].'%'; } $q = $dbh->prepare( $sql ); $q->execute( $params ); $doc = new domdocument(); $r = $doc->createelement("mutablerec" ); $doc->appendchild( $r ); foreach ( $q->

ios - How to use SSH on iPhone -

i trying create iphone app connects linux machine. app should send command via ssh linux machine. using system("ssh david@192.xxx.x.xx gpio write 0 0" command doesn't include password, log response access denied . know how ssh linux machine password? the way achieve want on not jailbroken devices use lib http://www.libssh.org implement ssh login within app. can find examples on how implement there : http://api.libssh.org/master/libssh_tutor_guided_tour.html

java - Understanding the difference between Cursor API and Iterator API of StAX -

ok, when learning how process xml stax api. saw has 2 ways xml document parsed namely: cursor api iterator api the cursor api use xmlstreamreader , it's next() , hasnext() methods. iterator api uses xmleventreader in same way above. the book sums iterator api in paragraph not quite descriptive. says use when want see event come next , based on value of xmlevent , can use xmlstreamreader skip or process upcoming event. i unable head around this. please explain how? sscce cursor api import javax.xml.stream.*; import javax.xml.stream.events.*; import java.io.*; public class staxcursordemo{ public static void main(string[] args){ try{ xmlinputfactory inputfactory = xmlinputfactory.newinstance(); inputstream input = new fileinputstream(new file("helloworld.xml")); xmlstreamreader xmlstreamreader = inputfactory.createxmlstreamreader(input); while(xmlstreamreader.hasnext()){

cron - Spring scheduler which is run after application is started and after midnight -

how describe spring scheduler run after application started , after 00:00 ? i 2 separate constructs. for after application starts, use @postconstuct , , every night @ midnight use @scheduled cron value set. both applied method. public class myclass { @postconstruct public void onstartup() { dowork(); } @scheduled(cron="0 0 0 * * ?") public void onschedule() { dowork(); } public void dowork() { // work required on startup , @ midnight } }

c - Using fread() hangs until killed -

this general structure of code: if (contentlength > 0) { // send post data size_t sizeread = 0; char buffer[1024]; while ((sizeread < contentlength) && (!feof(stream))) { size_t diff = contentlength - sizeread; if (diff > 1024) diff = 1024; // debuging fprintf(stderr, "sizeread: %zu\n", sizeread); fprintf(stderr, "contentlength: %ul\n", contentlength); fprintf(stderr, "diff: %zu\n", diff); size_t read = fread(buffer, 1, diff, stream); sizeread += read; exit(1); // write pipe fwrite(buffer, 1, read, cgipipepost); exit(1); } } however, program hangs when hits fread() line. if add exit() before line, program exists. if add after, program hangs until send sigint signal. any appreciated, have been stuck on quite time now. thanks fread tries fill internal buffer. depending on implementati

Unexpected Python (and idle) crash when running my script -

python , idle both exited if run code. use python 3.2 , there may few errors made after changing code out of desperation. my goal create file copies code separate file later use. recently, python 2.7 crashed , happening python 3.2. try code out on computer , see happens. please give me tips, because annoying. def creating(): print ('you have total of 70 points spend on str(strength), chr(charisma), dex(dexterity), int(intelligence), con(constitution).\nif put in greater amount restart character creation process; , if put smaller amount told can add more.\nyou may have limit of 18 on 1 attribute or restart stat creation process.') global st global ch global de global inte global con #it gives me error stuff above if doesn't crash st = (input('str:')) ch = (input('chr:')) de = (input('dex:')) inte = (input('int:')) con = (input('con:')) global scores score = st+ch+de+inte+inte+co

php - foreach loop stopping on the first xml element -

i have following xml data <items> <request> <isvalid>true</isvalid> <itemlookuprequest> <condition>all</condition> <idtype>isbn</idtype> <itemid>0071762345</itemid> <responsegroup>alternateversions</responsegroup> <searchindex>all</searchindex> <variationpage>all</variationpage> </itemlookuprequest> </request> <item> <asin>0071762345</asin> <alternateversions> <alternateversion> <asin>b0058o8v9u</asin> <title> likeable social media: how delight customers, create irresistible brand, , amazing on facebook (& other social networks) [paperback] dave kerpen dave kerpen </title> <binding>unknown binding</binding> </alternateversion> <alternateversion> <asin>b00511onpg</asin> <title&g

zipcode - Is there any free zip-codes plugin to Excel? -

i have 30,000 zip codes, , need extract states. tried cdxzipcode trial, works 1,000 entries. there freeware? copy this csv file this website workbook , use vlookup to lookup state zip code. given how easy is, don't see why want add-in.

JQuery jqgrid not sorting on client side -

Image
the data loads fine grid, won't sort. when click in table header, sort arrows appear, data's not being sorted. thanks. $("#comptable").jqgrid({ url:'bomexplosioninjsonobj.asp' , datatype: 'json' , mtype: 'get' , height: 400 , colnames:['part','description','src','std usage','usage inc scrap','rate scrap','uom','item','unit cost','stock'] , colmodel:[ {name:'comp1_part',index:'part', width:120} , {name:'wscompdesc',index:'desc', width:300} , {name:'wscompsrc',index:'src', width:10} , {name:'compusage',index:'usage', width:80, align:"right",sorttype:"float"} , {name:'wsgr

javascript - Replace img with iframe on click of button -

im pretty new js/jquery , need more knowledgeable! i have had on site , on web cannot find answer myself. i've played around myself limited knowledge cannot figure out next. what i've got i have img when clicked replaced iframe (youtube video), placeholder/poster, , works below code, found here: how add splash screen/placeholder image youtube video : <div class="playbutton"></div> <img src="image.jpg" data-video="http://www.youtube.com/videolink"> <script> $('img').click(function(){ var video = '<div class="video-container"><iframe src="'+ $(this).attr('data-video') +'"></iframe></div>'; $(this).replacewith(video); }); </script> as said - works when image clicked is replaced video. the problem i have added play button (currently div can use img instead) f

java - Debugging JVM memory leak -

i have java application uses native library of functionality. uses jni control native library , receives asynchronous callback library. can think of java frontend , native backend communicate each other. i facing memory leak. shortly after start application, memory steadily increases. tried cause leak. first, tried replacing java frontend simple c++ text interface. way, application doesn't use java in way - , leaks stopped. problem must in java frontend. so fired jvisualvm see if heap increases - , turned out doesn't. java heap size constant. launched program xmx32m, memory kept increasing past 100m without outofmemoryerror s. in fact, jvisualvm showed java heap @ 7m. so dug deeper program windbg. analyzed heap patterns !heap -s command , got this: heaps on freshly run program: 0:059> !heap -s lfh key : 0x382288b9 termination on corruption : enabled heap flags reserv commit virt free list ucr virt lock fast