Posts

Showing posts from April, 2010

java - How should I send resourcebundle messages across controllers in spring mvc? -

most of spring tutorials , examples show how message resource file , how show in view (jsp), not how should handle messages in controller , between views. here example of how im doing have view/controller handles forgotten passwords. when password sent redirect login screen message "your password sent ..." @requestmapping(value="/forgottenpassword") public string forgottenpassword(@requestparam string email) { ....something if(email != null){ return "redirect:/login?forgottenpassword=ok"; } } @requestmapping(value="/login") public string login(httpservletrequest request) { if(request.getparameter("forgottenpassword") != null && request.getparameter("forgottenpassword").equals("ok")) { data.put("ok_forgottenpassword", "forgottenpassword.ok"); } return "login"; } finaly display message in view, in case freemarker template ...

php - Preg_replace multiple patterns -

i'm busy website , element use preg_replace replace spaces dash. preg_replace('/\\s/', '-', $item_replace_en[0]) and works great have new problem. user enterd following "music / film". output "music-/-film" , want "music-film". how can accomplish this? it looks you're trying generate string can used url. there numerous of scenarios can happen when user adds title want convert url safe string. instance use this: mess'd --text-- (to) stress /test/ ?our! `little` \\clean\\ url fun.ction!?-->"); should return: messd-up-text-just-to-stress-test-our-little-clean-url-function is code ready that? in case can use function: setlocale(lc_all, 'en_us.utf8'); function toascii($str, $replace=array(), $delimiter='-') { if( !empty($replace) ) { $str = str_replace((array)$replace, ' ', $str); } $clean = iconv('utf-8', 'ascii//translit', $str)...

Android Internal File Storage or SQLite? -

i developing android application. app deals contact information (name, number, photo), need store locally later processing. data needs modified frequently. what way achieve this? thinking of "file input stream internal file storage(achieved serialized)" , sqlite, confused both of them. can tell me difference between these 2 in terms of performance, speed, memory consumption etc.? (besides, sqlite3?) (my personal opinion) database slow compare file in getting data in arranging formats , can perform aggregate function on it. suggest use database in requirements. can store particular record in arranged format. sqlite software library implements self-contained, serverless, zero-configuration, transactional sql database engine.

c# - Using Timer In WCF Or ASMX based webservice? -

i have scenario, want monitor database(sql server) table, if record inserted in webservice should through message moblie phone. i have written function of throwing message mobile phone already, dont know how use timer hit database after few intervals monitor table using web service. any 1 me how resolve issue? thanks in advance. why want webservice, windows service or app running through windows scheduler better choice.

java - Why is it faster to process a sorted array than an unsorted array? -

Image
here piece of c++ code seems peculiar. strange reason, sorting data miraculously makes code 6 times faster. #include <algorithm> #include <ctime> #include <iostream> int main() { // generate data const unsigned arraysize = 32768; int data[arraysize]; (unsigned c = 0; c < arraysize; ++c) data[c] = std::rand() % 256; // !!! this, next loop runs faster std::sort(data, data + arraysize); // test clock_t start = clock(); long long sum = 0; (unsigned = 0; < 100000; ++i) { // primary loop (unsigned c = 0; c < arraysize; ++c) { if (data[c] >= 128) sum += data[c]; } } double elapsedtime = static_cast<double>(clock() - start) / clocks_per_sec; std::cout << elapsedtime << std::endl; std::cout << "sum = " << sum << std::endl; } without std::sort(data, data + arraysize); , code runs...

vba - Rule to save attachments on incoming emails not working on a fresh install of Outlook -

we're migrating 1 server , vba script save attachments working has given ghost on new server. this fresh install of outlook. script below: public sub saveattachmentall(itm outlook.mailitem) dim objatt outlook.attachment dim savefolder string savefolder = "d:\www\phones" each objatt in itm.attachments objatt.saveasfile savefolder & "\" & objatt.displayname set objatt = nothing next end sub i've tested outlook rule , outlook performing other actions on script isn't working! so turns out had disable macro security (which isn't best) , restart outlook. simple, scratching head while...!

How to specify to match more than one character inside regex sqaure brackets? -

given user input string, need find if end 1 of following - .com, .net , .edu., html etc. is there way regex square brackets? i tried $[.com|.net|.html] , $[(.com)(.net)(.html)] both don't work. you want use capture group. (\.com|\.net|\.html) this match either 1 of values. can add additional values appending pipe inside parenthesis , placing new value after pipe.

internet explorer - Struts2 StreamResult not working in IE8 -

i'm trying allow downloading of pdfs located on file system. have action class downloadfileaction extends actionsupport following: public string execute() { // lookup file inputstream = new fileinputstream(file); return success; } public string getcontenttype() { return "application/pdf"; } public string getcontentdisposition() { return "attachment;filename=\"filename.pdf\""; } my action mapping defined you'd expect: <action name="downloadfile" class="com.foo.downloadfileaction"> <result name="success" type="stream"> <param name="allowcaching">false</param> </result> </action> this works great in firefox , ie9, fails work in ie8 unknown reasons. thoughts? update : using live http headers plugin, see when doing download in firefox. assume same in ie8: http://fmpdmb:7001/shopping/search/printitemdetail.action?upid=41271812...

design patterns - Singleton's consequence trouble -

i'm learning singleton pattern using gof's book. have problem when read it's consequence: more flexible class operations : another way package singleton's functionality use class operations (that is, static member functions in c++ or class methods in smalltalk). both of these language techniques make hard change design allow more 1 instance of class. moreover, static member functions in c++ never virtual, subclasses can't override them polymorphically. i don't understand explanation. think class operation (static method) can allow more 1 instance of class too, if use static list of instances, know i'm wrong, of course. so, can give me examples me understand problem? much! the original idea make use static members in class, , static methods operate on these static members, , use the class itself singleton. no runtime istantiation needed or allowed - , if istantiate anything, of type (an instance, not class. in smalltalk instance of class...

mysql - variable radio button with ajax -

i have loop of multiple radio buttons in php file- for($j=1;$j<4;$j++) { $var[$j]=$randnum[$j]; $queryques="select * quesans q_id='$var[$j]'"; $resultques=mysql_query($queryques); while($rowques=mysql_fetch_array($resultques)) { echo "<br/>".$rowques['ques']; echo "<br/>".'<input type="radio" value="hello" name="radio'.$j.'" />'.$rowques['ans_1']; echo "<br/>".'<input type="radio" value="hello" name="radio'.$j.'" />'.$rowques['ans_2']; echo "<br/>".'<input type="radio" value="hello" name="radio'.$j.'" />'.$rowques['ans_3']; echo "<br/>".'...

javascript - how to flash jquery dialog box -

is there way flash jquery dialog box on browser let user know important needs done if on other window. lets take case timeout popup user needs extend session, if flash dialog user notified when on other page. actually timeout jquery popup want user's attention, can take appropriate action. it's not you're talking about, think ui effect need dynamic favicon change, described in: is possible change favicon on site when users change themes? using that, can swap favicon , forth kind of alert icon every second or until user returns window.

vb.net - C# string replace from position X to Y only -

possible duplicate: how perform string replacement on subsection of string? how replace string position x y only, there string method? input = abcdxyzabcdxyz string replace input (start position = 3, end position=9, xyz pqr) xyz position 3 9 should replaced output = abcdpqrabcdxyz here extension method create method described: public static class stringextension { public static string replace(this string basevalue, int start, int length, string oldvalue, string newvalue) { return basevalue.substring(0, start) + basevalue.substring(start, length).replace(oldvalue, newvalue) + basevalue.substring(start + length, basevalue.length - (start + length)); } }

caching - In-Memory Data Grid for Java Project -

i'm looking use in memory data grid java project. know there few relevant products such vmware gemfire, gigaspaces xap, ibm extreme scale , others. can elaborate experience of these tools , how compare 1 another? thanks, alex (disclaimer - work gigaspaces) hi alex there many criteria compare by, depends on you're trying do. in memory data grid have lot of use cases, e.g. caching, oltp, high throughput event processing, etc. in general, main criteria should looking @ are: programming model: support popular java frameworks such spring (xap , gemfire support natively) querying , indexing: if want more trivial key/value data access. people need sql semantics, or full text search, , if data grid can provide out of box it's big advantage. ability execute code on grid nodes, , colocate code them , handle events injected grid (e.g. objects written or updated). massive scalability benefit , allows implement efficient shared-nothing architectures. languages , ...

java me - Button field(using image as button) focus issue -

in single row displaying text field enter search text along search image button field. below of row displaying list of names. the issue here is, image button field not getting focus during downward movement of keyboard arrow keys. during upward movement getting focus when click left arrow. downward movement not getting focus arrow movement. text field enter search text: final textfield tfteamsearch = new textfield(); tfteamsearch.setfocus(true); image button field: btnsearchimage = new button(); btnsearchimage.seticon(imgsearchunfocus); btnsearchimage.getstyle().setbgtransparency(0); btnsearchimage.getstyle().setborder(null); btnsearchimage.getstyle().setfont(font); btnsearchimage.getselectedstyle().setfont(font); btnsearchimage.getpressedstyle().setfont(font); btnsearchimage.getunselectedstyle().setfont(font); btnsearchimage.setfocusable(true); could u please me how set focus both upward , downward movement using arrow keys? firstly: should use tfteam...

makefile - Why doesn't my make file leave behind object files? -

i new make files , put bit of trial & error. code used compile c++ program. my main.cpp file in same folder makefile. have lib/ folder contains headers main depends on. the following makefile results in correct , complete compilation of code. expecting find *.o objects left behind. (note i've tried make both , without "clean" rule, , same results both times.) # # makefile # cxx = g++ ccflags = -o3 -i/sw/include -l/sw/lib ## /sw/include , /sw/lib contain dependencies files in lib/ ldflags = -lpng opts = $(ccflags) $(ldflags) sources = $(wildcard lib/*.cpp) main.cpp objects = $(sources: .cpp = .o) target = spirals $(target): $(objects) $(cxx) $(opts) $^ -o $@ .phony: depend depend: g++ -mm $(sources) > depend ## generate dependencies list include depend .phony: clean clean: rm -f *.o lib/*.o $(target) also, in case matters, i'm on macosx , program designed in xcode. (i know xcode has own build flow, i'm designing comma...

c - Socket loses connection on send() -

edit : scroll down see updated code. i build fake player minecraft, in c language. my minecraft server (bukkit) listening on port 25565, on local ip 192.168.1.141 when launch application, (when send data trough socket) bukkit server says : "192.168.1.141:xxxxx lost connection", and my application tell me : socked created socked connected send data = (smilie)kekos91;192.168.1.141:25565 send length = 27 send ! response data = (a strange symbol) response length = 1 socket disconnected maybe because of char-set ? know why ? here code : #include <stdio.h> #include <stdlib.h> #include <windows.h> #include <winsock2.h> int main() { char pseudo[] = "kekos91;192.168.1.141:25565"; int pseudolen = strlen(pseudo); char *packet = null; packet = (char*)malloc(3 + ((pseudolen)*sizeof(char)*2)); if(packet == null) { return -1; } memset(packet, '\0', sizeof(packet)); packet[0] = (char)0x0...

javascript - firefox doesn't work for event.target.id -

i have in javascript var identifier = event.target.id; it works on chrome in firefox gives me event not defined (?)()gift_c...oval.js (line 16) add(c=object { originalevent=event click, type="click", timestamp=897038643, more...})jquery.min.js (line 3) add(a=click clientx=1023, clienty=158)jquery.min.js (line 3) [break on error] var identifier = event.target.id; how can make cross browser competible have passed event on function() ? something like $('#id').click(function(event) { var identifier = event.target.id; });

node.js - Express Error: EMFILE, too many open files -

i getting following annoying error: error: emfile, many open files '/home/savagegames.net/views/index.jade' @ object.opensync (fs.js:240:18) @ object.readfilesync (fs.js:128:15) @ view.contents (/home/savagegames.net/node_modules/express/lib/view/view.js:121:13) @ function.compile (/home/savagegames.net/node_modules/express/lib/view.js:68:45) @ serverresponse._render (/home/savagegames.net/node_modules/express/lib/view.js:417:18) @ serverresponse.<anonymous> (/home/savagegames.net/node_modules/express/lib/view.js:318:17) @ /home/savagegames.net/node_modules/express-mongoose/index.js:45:21 @ resolve (/home/savagegames.net/node_modules/express-mongoose/index.js:75:12) @ serverresponse.expressmongoose [as render] (/home/savagegames.net/node_modules/express-mongoose/index.js:37:12) @ /home/savagegames.net/controllers/index_controller.coffee:49:18 i believe problem express; how can remedy it? thanks. from found, happens when error happens, , files aren't c...

python - get max duplicate item in list -

i have list: mylist = [20, 30, 25, 20, 30] after getting duplicated values indexes using [i i, x in enumerate(mylist) if mylist.count(x) > 1] the result is: `[0, 1, 3, 4]` having 2 pairs of duplicated values. i'd know, how can higher duplicated value? in list 30 or of it's indexes, 1 or 4 , instead of whole list of duplicated values. regards... this 1 o(n) >>> collections import counter >>> mylist = [20, 30, 25, 20, 30] >>> max(k k,v in counter(mylist).items() if v>1) 30

java - Empty <f:selectItems > in JSF 2.0 -

i using jsf 2.0 facelets , tring selected items value database, tried @postconstruct way throws excpetion, write shortly, i tried same databse connection , entities , runs good. i should mention here using string send selectitems, , before used selectitem list did not work, and funny thing when inserted try , catch block in while loop(u'll see in moment) mistake, threw exception on , on again, means list not empty, not getting page. what cloud cause of ? my jsf code <h:selectonemenu > <f:selectitems value="#{settingsbean.countryitems}" /> </h:selectonemenu> my managed bean @named(value = "settingsbean") @requestscoped public class settingsbean { /** * creates new instance of settingsbean */ private string favorits; private string hobbies; private string aboutme; private string education; private string country; private string listcountry; private list<string> countryitems; private list<countries> countri...

javascript - What do i do with json? -

ive been stuck on couple days , hopingnyou guys coiuld shed light on this. quite ive been toying steam api , have been able make few calls. problem have im not quite sure how use result ( in json) arrange meaningful content. hoping create website info json results. im not here have give me answer point me in right direction. im html css , javascript , trying teach myself python open learning other languages done. anways, thanks! json means javascript object notation . nice data-format, because can use directly in javascript, because can parse native browser-methods json.parse() (and reverse json-stringify() ) , directly javascript-object, can work with.

objective c - Copy file to App Document folder automatically -

i want copy set of files project resource folder app document folder automatically @ time of app first launch. can this. need through code. bool success; nserror *error; nsfilemanager *filemanager = [nsfilemanager defaultmanager]; nsstring *documentsdirectory = [nshomedirectory() stringbyappendingpathcomponent:@"documents"]; nsstring *filepath = [documentsdirectory stringbyappendingpathcomponent:@"data.txt"]; success = [filemanager fileexistsatpath:filepath]; if (!success) { nsstring *path = [[nsbundle mainbundle] pathforresource:@"data" oftype:@"txt"]; success = [filemanager copyitematpath:path topath:filepath error:&error]; } in application did finish launching options

WiX: register .NET COM component both x86 x64 -

i have c# com .dll. install .dll once, have registered both x86 , x64. here's wix have registering x64: <component id="netdll.dll" directory="installdir"> <file id="netdll.dll" name="netdll.dll" keypath="yes" source="..\netdll.dll" /> <class id="{78be...}" context="inprocserver32" description="netdll" threadingmodel="both" foreignserver="mscoree.dll"> <progid id="netdll" description="netdll" /> </class> <registryvalue root="hkcr" key="clsid\{78be...}\implemented categories\{62c8fe65-4ebb-45e7-b440-6e39b2cdbf29}" value="" type="string" action="write" /> <registryvalue root="hkcr" key="clsid\{78be...}\inprocserver32\1.0.1.0" name="class" value="netdll" type="string" action="write" /> ...

loading - Making a page transition animation -

i noticed pages on internet (like gizmodo , io9) have page load animation. in latter cases, previous page greyed out small loading "spinner" animation in middle, , second page comes in without blank loading page in between, pages on internet. how done? hopefully works you... below solution worked me although jquery needed: first right after body tag add this: <div id="loading"> <img id="loading-image" src="images/ajax-loader.gif" alt="loading..." /> </div> then add style class div , image css: #loading { width: 100%; height: 100%; top: 0px; left: 0px; position: fixed; display: block; opacity: 0.7; background-color: #fff; z-index: 99; text-align: center; } #loading-image { position: absolute; top: 100px; left: 240px; z-index: 100; } and add javascript page (preferably @ end of page, before closing body tag of course): <script language="javascript" type...

visual studio - Compiling Python modules on Windows x64 -

i'm starting out projects in words processing , needed numpy , nltk. first time got know easy_install , how compile new module of python system. i have python 2.7 x64 plus vs 11 , vs 12. cygwin (the latest 1 guess). see in file compiles using vs looks vs env same version 1 compiled python code, why? when hardcoded 11.0 version, numpy failed build on several strange errors regarding vcvarsall (it found vcvarsall , misused it). can't build python binaries on windows? if not, can cross compile on linux windows? (using same method google android sdk) update: zooba mentions below, free x86 , amd64 (x86-64) vc90 c-compilers python-2.7 available microsoft . update: patch vcvarsall.bat use x64 compilers sdk v7.0 directly pip in shell instead of using sdk shell , setting distutils_use_sdk , mssdk environmental variables in directions below. see fix vcvarsall.bat install python-2.7 x64 extensions v90 instead of sdk7 . tl;dr: use windows sdk v7.0 compilers, ...

python - Render dynamic menu in every view -

i have few views , has render dynamic menu this: def view1(request): return render_to_response('view1.html', requestcontext(request, {'menu': menu, 'a': a, ...})) def view2(request): return render_to_response('view2.html', requestcontext(request, {'menu': menu, 'b': b, ...})) def view3(request): return render_to_response('view3.html', requestcontext(request, {'menu': menu, 'c': c, ...})) def viewn(request): return render_to_response('view4.html', requestcontext(request, {'menu': menu, 'd': d, ...})) but incomfortable beacuse have add menu attribute every view. in way can optimization of that? this context processors for. you're using requestcontext, need define function returns menu , add template_context_processors .

Excel Macro to replace numeric zip code with county name -

Image
issue - have spreadsheet thousands of addresses no counties. goal - add counties each record. can identify counties using zip codes , have list of zip codes , county names. what i've tried far - county names in column , it's corresponding zip code in column b. copied address list same spreadsheet starting zip codes in column d. i wrote following simple macro compare , replace zip codes county names. runs doesn't seem replace anything. don't errors, i'm not sure problem is. ideas? public sub take_two_replace_zip_with_name() dim lastbcell long dim b integer dim bcell range lastbcell = activesheet.range("b65000").end(xlup).row b = lastbcell 2 step -1 set bcell = activesheet.cells(b, 2) if bcell = bcell.offset(0, 2) bcell.offset(0, 2) = bcell.offset(0, -1) next b end sub ok, worked out myself: each bcell in range("b2:b100").cells columns("d:d").cells.replace what:=bcell, repla...

c++ - How can I delete characters in stdout by programming? -

Image
i want emulate backspace in programming , implemented below. // del.cpp #include <iostream> using namespace std; int main() { cout << "123456"; cout << "\b\b\b" /* backspace key */<< '\x7f' /* del key */ << '\x7f' << '\x7f'; cout << endl; return 0; } but result how can result below without need of replacing tails blank space 123 that how can delete, rather replace, character after cursor has been backspaced. use "clear end of line" escape sequence, csi k . cout << "123456"; cout << "\b\b\b\033[k"; cout << endl; for list of escape sequences, see ansi escape code (wikipedia) . of course, not of them work on terminals, these days, software terminals, wouldn't worry it.

java - Non Deprecated findPreference() Method? - Android -

Image
i want detect when preference contained in listview gets clicked, can launch intent manage selection. i have done in layout xml file: <preference android:title="about" android:key="mykey"></preference> and following in java code: preference mypref = (preference) findpreference("mykey"); mypref.setonpreferenceclicklistener(new onpreferenceclicklistener() { public boolean onpreferenceclick(preference preference) { //open browser or intent here } }); but method public preference findpreference (charsequence key) deprecated. is there non deprecated equivalent? if not, if use anyway? how can fragments me task in better way?chek here: preferences without deprecated methods . here can check xml layout structure activity has, , snapshot of application: xml: <?xml version="1.0" encoding="utf-8"?> <preferencescreen xmlns:android="http:...

swing - java jspinner change listener trigger -

i have 2 comboboxes , spinner, work this: if selected item of first combo changed, second combo keeps selected item re-calls spinner (the spinner linked second box). problem can't trigger statechange listener of spinner when this. here code forcing second box reselect last item when first 1 changed (nothing wrong here, works fine): string orientare = (string) orientarecombobox.getselecteditem(); orientarecombobox.setselecteditem(orientare); this code second box actionlistener: public void actionperformed(actionevent e) { jcombobox combo = (jcombobox) e.getsource(); string value = combo.getselecteditem().tostring(); if (value.equalsignorecase("oblica")) { unghispinner.setenabled(true); double unghi = (double) unghispinner.getvalue(); unghispinner.setvalue(new double(unghi)); } } and spinner's listener: public void statechanged(change...

android - How to change the color of tab 'underbar' in actionbarsherlock -

ok i'm loosing more sanity ever. can't find/understand how style damn thing. managed change background of tab can't cahnge color of bar under selected tab. how change blue something. my styles.xml unfortunately have bad understanding of how works <?xml version="1.0" encoding="utf-8"?> <resources> <style name="theme.styled" parent="theme.sherlock.light"> <item name="actionbartabstyle">@style/widget.styled.actionbartab</item> <item name="android:actionbartabstyle">@style/widget.styled.actionbartab</item> <item name="actionbartabbarstyle">@style/widget.styled.actionbartabbar</item> <item name="android:actionbartabbarstyle">@style/widget.styled.actionbartabbar</item> <item name="actionbartabtextstyle">@style/mytext</item> <item name="androi...

opencv - HoughCircles Parameters to recognise balls -

Image
after processing image converting grey scale , blurring it, i'm trying apply hough circle transformation these parameters: cv_hough_gradient dp = 1 min_dist = 1 param_1 = 70 param_2 = 100 min_radius = 0 max_radius = 0 here 1 of many images i've tried: http://i.stack.imgur.com/jgrim.jpg but algorithm fails recognise ball relaxed parameters. (when try image of circle created in gimp works fine) i agree krzych. had working effortlessly : cv::mat img,img2; std::vector<cv::vec3f> circles; img = cv::imread("jgrim.jpg",1); cv::bilateralfilter(img, img2, 15, 1000, 1000); cv::cvtcolor(img2, img2,cv_bgr2gray); cv::houghcircles(img2, circles, cv_hough_gradient, 1,300,50, 10); cv::circle(img2,cv::point(circles[0][0],circles[0][1]),circles[0][2],cv::scalar(126),2); cv::imshow("test",img2); cv::waitkey(0); cv::imwrite("test.jpg",img2); return 0; good luck :)

asp.net mvc - Is there a tool to automatically generate view models from domain models? -

i'm using ado.net dbcontext generator generate domain objects entity model. there tools can generate view model each of domain objects? adding data annotations, [required], [displayname] , [datatype], view model properties nice too. i'll adding these generated view models build more complex view models @ least tedious work automated. asp.net mvc 4 rc thanks! no, there no such tools. define view models. tool cannot possibly know how views , information contain. remember view model projection of multiple domain models. tool can generate models existing database schema, there's no such thing view models. design left ingenuousness of developer , imho that's better.

php - Combining 2 queries into 1 -

i'm looking optimize 2 queries one, if possible. my first query searches authors of lyrics... then, each author found, want find total numbers of lyrics author involded in... right now, im executing first query , each row found, i'm launching query authors total lyrics involved... so, if there 4 authors end launching 4 more queries... many queries in opinion. why i've decided write here, can on how optimize query... this query i'm executing author(s) responsable lyrics: $sql = "select author.author_id, author.name track inner join lyrics_author on track.lyrics_id = lyrics_author.lyrics_id inner join author on lyrics_author.author_id = author.author_id track.track_id = $trackid "; this query total number of lyrics author writing: $total = "select lyrics_author.author_id, count(*) total lyrics_author lyrics_author.author_id = $author_id group lyrics_author.author_id"; this sample of code: <?php $trackid =...

How to flush the CPU cache in Linux from a C program? -

i writing c program in need flush memory. know if there unix system command flush cpu cache. this requirement project involves calculating time taken logic. i have read cacheflush(char *s, int a, int b) function not sure whether suitable , pass in parameters. i take mean "cpu cache", not memory cache the link above good: suggestion "write lot of data via cpu" not windows specific here's variation on same theme: how clear cpu l1 , l2 cache here's article linux , cpu cache: http://lwn.net/articles/252125/ note: at (very, low) level, "linux" != "unix"

Floating point bug when writing to file in Matlab? -

im not sure if im missing simple following code fails (a , b meant same): a=single(2147483584) f=fopen('test','wb'); fwrite(f,a,'int32') fclose(f); f=fopen('test','rb'); b=fread(f,inf,'int32'); fclose(f) b with output: a = 2.1475e+009 b = -2.1475e+009 and following code succeeds: a=single(2147483583) f=fopen('test','wb'); fwrite(f,a,'int32') fclose(f); f=fopen('test','rb'); b=fread(f,inf,'int32'); fclose(f) b with output: a = 2.1475e+009 b = 2.1475e+009 does know why? i don't know matlab well, seems clear what's happening here. you're converting a float , storing result of conversion 32-bit signed integer. nearest single-precision ieee 754 float integer 2147483584 2147483648.0 , or 2**31 . 32-bit integer can represent values in range [-2**31, 2**31-1] , looks though when write value integer, gets wrapped modulo 2**32 give -2**31 ...

opengl es - LibGDX - Sprite to Pixmap -

i using libgdx small app project, , need somehow take series of sprites , place them (or pixels rather) pixmap. basic idea take random sprites generated through various means while app running, and, @ specific times, merge of them onto single background sprite. i believe of can done easily, step of getting sprite images pixmap isn't quite obvious me. sprites have various transparent , semi-transparent pixels, grabbing color @ each pixel while on same screen isn't applicable either, shouldn't take background colors it. if there suitable alternative accomplish looking love hear it. highly appreciated. i think want render sprites off-screen buffer (called "fbo" or framebuffer in libgdx) (blending them they're added), , render offscreen buffer screen single draw call? if so, question should help: libgdx spritebatch render texture this requires opengl es 2.0, eliminate support older devices.

C++ How to get sizeof(enum) == sizeof(char)? -

i know how. i have looked @ this topic , , understand "the choice of type implementation-defined.", curious know how 1 instead of 4. c++11 introduced way change underlying type of enum. enum foo : char { ... }; enum class foo : char { ... }; still, you're better off using default int in cases.

c# - How to calculate the infinite value of a division? -

possible duplicate: how know repeating decimal in fraction? 1/3 different 3/10. 0.33333 != 0.3 so 1/3 0.3 (with line above number three) 1/12 = 0.833333 = 0.083 (with line above number three) 1/13 = 0.076923076923 = 0.|076923| those lines represent repeating part. i plan have model in class. i'm bit lost on situation. need ideas know determine repeating value. thanks. cycle detection algorithm answer. can use floyd's cycle detection algorithm or brent's cycle detection algorithm . the function plug algorithms function produce next digit of quotient.

java - Why can't implementing classes define an overriding method as static? -

i'm confused why following not allowed: public interface myinterface { myinterface getinstance(string name); } public class myimplementation implements myinterface { public myimplementation(string name) { } @override public static myinterface getinstance(string name) { // static not allowed here return new myimplementation(name) } } i understand why method in interface cannot static, why can't overriding method be? i want classes implement getinstance(string name) method, i'm limited being able call method if object has been instantiated kind of defeats purpose... *update: * answers, understand better now. shouldn't trying make utility class (or factory class matter) implement interface (or @ least, not in way)... invoking static methods in java requires specify exact type. not possible invoke static methods polymorphically, eliminating need @override . please note approach not universal across languages: example, can override...

sencha touch 2 app not displaying in android browser completely -

i have working sencha touch2 example app running on python single threaded server (django runserver) on laptop. uses jsonp load images carousel similar example here http://edspencer.net/2012/02/building-a-data-driven-image-carousel-with-sencha-touch-2.html it works on chrome , partially on firefox. i followed guide make production build docs in sencha touch 2. here on chrome. here requests see. 127.0.0.1 - - [03/jul/2012 00:21:15] "get /static/build/production/cache.manifest http/1.1" 200 - 127.0.0.1 - - [03/jul/2012 00:21:16] "get /static/build/production/app.json?1341246076009 http/1.1" 200 - 127.0.0.1 - - [03/jul/2012 00:21:16] "get /static/build/production/src/log/logger.js?_dc=1341246076006 http/1.1" 200 - 127.0.0.1 - - [03/jul/2012 00:21:16] "get /static/build/production/deltas/app.js/812d759b7c7a366ab0976c13044b2cd38f3444dc.json?1341246076040 http/1.1" 200 - 127.0.0.1 - - [03/jul/2012 00:21:16] "get /static/build/production/...

swing - How to scroll to a given position in a document displayed in a JScrollPane -

in application java swing components have jtextpane inside non-editable jscrollpane , , other fields user can enter criteria. if user clicks button or menu item, there search section of document in jtextpane meets given criteria, , if match found section highlighted. that part solved; can find relevant document segment, know starts , ends (in terms of integer offsets), , highlight it. but highlighted segment might have scrolled off screen , need scrolled within visible piece of jscrollpane. see there method scrollrecttovisible(rectangle) on jcomponent seems might job, don't see how convert textual document position integer rectangle . note non-editable jtextpane , don't want move cursor highlighted segment (the user cannot see cursor anyway), want make segment show within visible area of jscrollpane. well can use modeltoview(...) , can return 1 rectangle object, can use case. here 1 example @camickr regarding same one more example here

jQuery mobile: how to load a detailpage from a listview -

i'm using singe page concept jquery mobile. create dynamic listview so: var resultitems = '<ul data-role="listview">'; (i = 0; < 10; i++) { if (msg.hotspots[i] != null) { resultitems += '<li><a href="acura.html"><img src="' + msg.hotspots[i].imageurl + '" />' + msg.hotspots[i].title + '</a></li>'; } } resultitems += '</ul>'; $('#results').html(resultitems); $('#results').trigger("create"); as can see have hyperlink acura.html now. want activate subpage #detailpage , load details of id of clicked item in listview. it's no problem adding item id link, don't know link should , how read id page #detailpage. thanks! what asking how pass data data 1 page in jquery mobile, in case want append id of item , in pageshow event of acura.html based on that. there few questions here on deal (passing data) example may wa...