Posts

Showing posts from July, 2011

php - Query for finding a users rank in game database -

this question has answer here: mysql, users rank 4 answers currently have following information in game table id name xp 1 bob 11 2 jim 120 3 dan 56 4 oli 32 i want find rank when pulling single user example. want able pull 'jim' rank number 1 , 'bob' rank number 4 example. i had query seems messed up. select count(*)+2 game xp > (select xp game id = '$id') you use this: select g1.id, count(distinct g2.xp)+1 rank game g1 left join game g2 on g1.xp < g2.xp group g1.id fiddle here . use distinct or not, depending on after.

Magento Rest API Error missing media_gallery -

i have completed setting magento rest api , been able retrieve list of product without errors using api example code magento provides. when try use create simple product example provided @ http://www.magentocommerce.com/api/rest/introduction.html#restapiintroduction-overview below error. {"messages":{"error":[{"code":400,"message":"missing \"media_gallery\" in request."} i have looked everywhere , can't seem find out how fix error. don't see reference here http://www.magentocommerce.com/api/rest/resources/products/products.html#restapi-resource-products-httpmethod-post-products saying media_gallery required in request. can shed light on error , how fix it? i've been looking well, can modify attribute in magento's administration , turn off (catalog/attributes/manage attributes), in make not required. cheers

javascript - Run script if screen size is less than 1024px -

i'm running script on page make div id="homesplash" disappear when user scrolls beyond 600px follows: $(window).scroll(function() { if ($(this).scrolltop()>600) { $('#homesplash').hide(); } else { $('#homesplash').show(); } }); i need figure out how run script if browser width greater 1024px . ideas? i've tried implement code related post found here, can't work unfamiliar writing javascript. thanks. you can check $(window).width() , compare 1024 . like: $(window).scroll(function() { if ( $(this).width() > 1024 ) { $("#homesplash").toggle( $(this).scrolltop() <= 600 ); } });

c# - Beginner here: How does my Repository Layer know which user is logged in? -

i know super novice question, i'm having tough time understanding this. i'm implementing websecurity in n-tier application. i've placed websecurity code in repository layer (closest db layer). i have code this: public bool login(string username, string password, bool rememberme) { return websecurity.login(username, password, rememberme); } public void logout() { websecurity.logout(); } websecurity doesn't need know context logging in - pass parameters. logging out? 10 users logging out, how code right here know user log out? context of user somehow pushed way down repository layer, browser client api controller, through services layer? your repository layer shouldn't know user logged in. repository layer shouldn't know there is user. of authentication should handled web application - web application then, having authenticated user, accesses repository layer, whatever it's told , doesn't concern

junit - How to get Jenkins to show skipped tests using email-ext? -

Image
i using email-ext plugin within jenkins display passed failed, , email has nice blue passed methods , red failed. not including ignored tests within class. shouldn't annotations junit's @ignore display skipped in junit results via email-ext? i using html_gmail template so: ${jelly_script,template="html_gmail"} and using following tokens in extendable email notificatin config: total amount of tests: ${test_counts, var} total = $test_counts failed = ${test_counts,var="fail"} total = $test_counts passed = ${test_counts,var="pass"} is there an: ignore = ${test_counts,var=skipped") ???? junit jenkins email-ext share | improve question asked apr 17 '13 @ 21:41 jjacquet 571 1 7 20

php - Jquery Mobile Page buttons don't work after page refresh -

my jquery mobile app has footer navigation doesn't work after page refresh happens - example here : http://m-staging.qpme.com/quickpay-login.php#sessions-page login: stack@yahoo.com password: stack then in browser, refresh page, bottom navigation not work. have tried few different things, have read, no luck. can help? i jsut avoided refresh going desired page , using jquery refresh code repopulate divs. $("div").page();

java - Trying to figure out why the split method is not printg out right -

the words printed out after split command not printing out in ascending order. not think have placed in right spot of code, unsure place it. prints out whole text passage word word without punctuation marks desired, wont print in ascending (alphabetical) order. great. public static void main(string[] args) throws filenotfoundexception, ioexception { scanner ci = new scanner(system.in); system.out.print("please enter text file open: "); string filename = ci.next(); system.out.println(""); file file = new file(filename); bufferedreader br = new bufferedreader(new filereader(file)); stringbuilder sb = new stringbuilder(); string str; while((str = br.readline())!= null) { string sp[] = str.split("[\\s\\.,;:\\?!]+"); (string sr : sp ) { system.out.println(sr); } sb.append(str); sb.append(" "); // system.out.pri

parsing - Get the value from a SOAP message in Java -

i getting soap message string after making call web service. <?xml version="1.0" encoding="utf-8"?> <soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <soap:body> <passoraclexmldataresponse xmlns="http://tempuri.org/"> <passoraclexmldataresult> <gesystem xmlns=""> <return_code>0</return_code> <message>prs user not exists in gets</message> <invoiceid>testaddtlinfo2</invoiceid> <datetime>apr 17 2013 4:19pm</datetime> </gesystem> </passoraclexmldataresult> </passoraclexmldataresponse> </soap:body> </soap:envelope> i

Simple acces of C++ object data from QML -

i'm making board game in qt/c++ using qml. important game data represented in single class. intention have qml sheets access 1 object , draw game board depending on data. what simplest approach exposing c++ data members qml? now know question has been asked, i've seen answers , qt documentation. am, however, not satisfied. i've seen, way seems to make q_property out of every single variable want access qml. looks me tedious , unnecessary, not mention stretch code 3x it's original length, making worse read. also, in cases won't need write function data members, example. and why bother q_property overhead when write q_invokable getters situations need? here's example of how simple hoped when read in qt project documentation: "this enables c++ data , functions accessible directly qml, little or no modification." class game : public qobject { q_object public: explicit game(qobject *parent = 0); colors npc[3]; // colors being enu

pdf generation - Why pdftk produced pdf files will not render in Firefox? -

i have site - www.jcrocetta.com. on site have 2 pdf files. 1 file has blurred data , other clear, both files created pdftk. in order blur out personal data in pdf used inkscape. inkscape opens/edits 1 pdf page @ time. after made edits in inkscape saved files .pdf formatted files. @ point had 3 separate pdf files, pages 1 through 3. used pdftk concatenate 3 files one. the final pdftk-produced files on www.jcrocetta.com. click public information button. in chrome viewing inline works fine. downloading file firefox works fine too. viewing inline on firefox renders blank pages. how can fix this? also, know pdf files not produced pdftk render correctly on both chrome , firefox. thanks help. firefox has lovely new feature: uses pdf.js library render pdf files, instead of calling out adobe reader plugin, or forcing save file disk. unfortunately, seem pdf.js isn't quite perfect yet. quick search shows other people have same issue, "solution" i've seen

java - How to execute Selenium 2 tests in Jenkins -

Image
i able use selenium 2 jenkins. i new both please excuse of ignorance. i noticed following plugin jenkins here , , installed it. i have base class follows: public class basetestclass { protected properties myprops; protected string baseurl; protected webdriver driver; protected boolean acceptnextalert = true; protected stringbuffer verificationerrors = new stringbuffer(); public basetestclass() { try { myprops = testutil.readprops("src/myprops.properties"); baseurl = myprops.getproperty("baseurl"); driver = new remotewebdriver(new url("http://localhost:4444/wd/hub"), desiredcapabilities.firefox()); } catch(exception e) { e.printstacktrace(); } } @before public void setup() throws exception { driver.manage().timeouts().implicitlywait(30, timeunit.seconds); } @after public void teardown() throws exception { driver.quit(); string verificationerrorstring = verificationerro

ios - Rotating UIImage causing some iPhones to crash -

on app, build pdf. add image pdf file. when use uiimagepickercontroller , select portrait photo, automatically rotates 90 degrees left. so, in order fix issue, add border around image, using code. however, on iphone 3gs, when adding larger photo, app crash. ideas on in code causing issue? - (uiimage *)scaleandrotateimage:(uiimage *)image { int kmaxresolution = 640; // or whatever cgimageref imgref = image.cgimage; cgfloat width = cgimagegetwidth(imgref); cgfloat height = cgimagegetheight(imgref); cgaffinetransform transform = cgaffinetransformidentity; cgrect bounds = cgrectmake(0, 0, width, height); if (width > kmaxresolution || height > kmaxresolution) { cgfloat ratio = width/height; if (ratio > 1) { bounds.size.width = kmaxresolution; bounds.size.height = roundf(bounds.size.width / ratio); } else { bounds.size.height = kmaxresolution; bounds.size.width

xsd - Difference between using ID+IDREF and direct Type in XML Schema? -

i new xsd , have question difference between following 2 schemas? 1) direct use of idref , id limit selection element within file: <xsd:element name="policy" > <xsd:complextype> <xsd:sequence> <xsd:element name="actor-def" type="tns:actor-def"/> <xsd:element name="actor-system-def" type="tns:actor-system-def"/> </xsd:sequence> </xsd:complextype> </xsd:element> <xsd:complextype name="actor-def"> <xsd:sequence> <xsd:element name="actor-system" type="tns:actor-system-type"/> </xsd:sequence> <xsd:attribute name="name" type="xsd:id" use="required" /> </xsd:complextype> <xsd:complextype name="actor-system-type"> &l

c# - How to create a checkbox for each possible enum value in Windows forms? -

say have enum identifier {name, id, number} , want provide user message dialog checkboxes each possible identifier value , ok button. on dialog confirmation list<identifier> (empty if none of checkboxes selected). how such simple thing winforms? you can array of values in enum with: var valuesarray = enum.getvalues(typeof (identifier)); to display checkboxes: foreach (var val in valuesarray) { //create checkbox var cb = new checkbox(); cb.name = string.format("cb_{0}", val); cb.text = val; //set properties //add form controls this.controls.add(cb); } to list, checkboxes on form: var checkedidentifiers = new list<identifier>(); foreach (var val in valuesarray) { //find checkbox var cb = this.controls[string.format("cb_{0}", val)]; if (cb != null && cb.checked) checkedidentifiers.add((identifier)enum.parse(typeof(identifier), val)); } you can additional error checking above, gi

jquery - Have a radio button as a check for base value -

i've worked through code, , i've ended having 2 possible base prices. students base = $249.99 , assistants = $399.99. each option has choice add: a chair $99.99 and/or desk $99.99. as of right code not recognize assistants option($399.99), nor proper math. in all: if assistants option selected, supposed replaced new base price. how base price switch between 2 choices , recognize checkbox values? i've made fiddle better display i'm working with. thank in advance. // check if assistant or student $('input[name=type]').on('change', function(){ if($(this).prop('value') == 1) { // if assistant var originalamount = 399.99; $('span.amount').html(originalamount); }else { // else student var originalamount = 249.99; $('span.amount').html(originalamount); } }); // check current amount originalamount = number($('span.amount').html().replace(/[^0-9\.]+/g,&q

oop - Using a function inside of a C++ class inheritance -

i trying call function calculateinterest() in class // account.h -- handles banking accounts #ifndef account_h_ #define account_h_ #include <string> using std::string; class account { private: double balance; public: account(double b = 0.0); double getbalance() {return balance;} void credit(double c); void debit(double d); }; class savingsaccount : public account { private: double rate; public: savingsaccount(double r = 0.0); double calculateinterest(); }; class checkingaccount : public account { private: double fee; public: checkingaccount(double f = 0.0); void credit(double m); void debit(double m); }; #endif so far account joe(100); , use functions inside of account class not inheriting right. class account { private: double balance; public: account(double b = 0.0); double getbalance() {return balance;} void credit(double c); void debit(double d); // add this! virtual doubl

JSCH (SFTP) fails on change dir on sub folders level (second level) -

jsch's sftp channel fails change directory when previous directory not in root directory (ftp home). happens on sftp servers , not of them. for example directory structure this: / level-1 level-2 cd level-1 (ok) cd level-2 (fails) it throws exception this 4: folder not found: /level-1/level-2 @ com.jcraft.jsch.channelsftp.throwstatuserror(channelsftp.java:2569) @ com.jcraft.jsch.channelsftp._realpath(channelsftp.java:2100) @ com.jcraft.jsch.channelsftp.cd(channelsftp.java:315) the sftp server error returns / realpath root. other server didn't fail returns full path list /usr/account . i found source code jsch 0.1.49 , traced it. found out there method named _realpath throws exception when server fails return realpath. input parameter method absolute path of remote folder commented exception out , instead returned absolute path. works fine. this modified code. note original code works of time , change made rare situation server

ruby - Unable to sign_up using Devise and CanCan in Rails -

Image
i been working on application in have number of roles , users. however can't sign-up anymore. signing in works fine, signing redirects me signing page , produces same error: the console shows following when try sign up: started post "/registers/user/registration" 127.0.0.1 @ 2013-04-18 00:48:22 +0100 processing registerscontroller#registration html parameters: {"utf8"=>"✓", "authenticity_token"=>"ofucdxxzzfbtvlfvaa3qxixohl2v9hzxfsfu/99pd60=", "user"=>{"name"=>"omar arroum", "email"=>"omar@gmail.com", "password"=>"[filtered]", "password_confirmation"=>"[filtered]"}, "commit"=>"sign up", "id"=>"user"} completed 401 unauthorized in 1ms started "/users/sign_in" 127.0.0.1 @ 2013-04-18 00:48:22 +0100 processing devise::sessionscontroller#new html rendere

How to validate the password in PHP and MYSQL -

this question has answer here: secure hash , salt php passwords 14 answers i have found article code below on web want use learn more php/mysql... $username = 'admin'; $password = 'gf45_gdf#4hg'; $salt = hash('sha256', uniqid(mt_rand(), true) . 'a random string go here' . strtolower($username)); $hash = $salt . $password; ( $i = 0; $i < 100000; $i ++ ) { $hash = hash('sha256', $hash); } $hash = $salt . $hash; how validate password in php when user wants log in? you run exact same procedure , see if results match. this general procedure seeing if sumbitted password stores matched password. you create function hashes , stores known password, , typically salts well you store in database when user submits password login, run through exact same hashing , salting algorithm, , see if resulting hash matc

javascript - using JQuery can I replace an empty div with the result of a load event -

i have placeholder div nested inside div. want replace placeholder div data returned .load() call when parent div clicked on using onclick function... for example: function accordianclick(projectid) { $("#project-placeholder-" + projectid).replacewith( $.load("projectdetail?projectid=" + projectid)); } the trick want fetch data loaded if placeholder div exists once click on parent , replace first time won't exist anymore therefore load function not called. for example works every-time click parent div still fetches data. function accordianclick(projectid) { $.get("projectdetail?projectid=" + projectid, function(data) { $("#project-placeholder-" + projectid).replacewith(data); }, 'html'); } use length check if exists. function accordianclick(projectid) { var $container = $("#project-placeholder-" + projectid); if( $container.length > 0 ) {

objective c - Calling Function from RootViewController -

how call rootviewcontroller function firstviewcontroller ? i'm using xcode 4.6 storyboard. rootviewcontroller.m: -(void)openmenu { ... } firstviewcontroller: - (ibaction)btnmenu:(id)sender { rootviewcontroller *root = [[rootviewcontroller alloc] init]; [root openmenu]; // no visible @interface 'rootviewcontroller' declares selector 'openmenu' } you have declare method in header rootviewcontroller.h . example - (void)openmenu;

javascript - Cannot read property 'length' of undefined by loading object in Three.js -

i'm quite beginner in three.js. tried load simple cylinder.js object exported blender. but, got error uncaught typeerror: cannot read property 'length' of undefined three.js:600 three.loader.initmaterials three.js:600 three.jsonloader.createmodel three.js:691 g.onreadystatechange here's simple code var scene = new three.scene(); var camera = new three.perspectivecamera( 75, window.innerwidth / window.innerheight, 0.1, 1000 ); camera.position.z = 300; scene.add(camera); var renderer = new three.webglrenderer(); renderer.setsize( window.innerwidth, window.innerheight ); var loader = new three.jsonloader(); function createscene( geometry ) { var materials = geometry.materials[0]; materials.morphtargets = true; var material = new three.meshfacematerial(); mesh = new three.mesh( geometry, material ); mesh.scale.set(50, 50, 50); scene.add( mesh ); } loader.load('cylinder.js'

java - Merge sort generic method -

my merge sort doesn't seem working correctly. when display sorted list, not sorted , elements added, there supposed 9 there 49. see im going wrong? public static <e extends comparable<e>> void mergesort(list<e> a) { int n = a.size(); if (n > 1) { int half = n / 2; list<e> b = copypartialarray(a, 0, half); list<e> c = copypartialarray(a, half, n); mergesort(b); mergesort(c); merge(b, c, a); } } public static <e extends comparable<e>> void merge(list<e> b, list<e> c, list<e> a) { int n1 = b.size(); int n2 = c.size(); int = 0; int j = 0; int k = 0; while (i < n1 && j < n2) { if (b.get(i).compareto(c.get(j)) < 0) { a.add(k, b.get(i)); i++; } else { a.add(k, c.get(j)); j++; } k++; } if (i == n1) (int p = j; p < n

c# - How to use let to define a new set of data within a LINQ query? -

i have class represents ingredients recipe public class viewrecipe { public string recipename { get; set; } public string ingredientname { get; set; } public double unitweight { get; set; } public double totalweight { get; set; } public viewrecipe() { } public viewrecipe(string _recipename, string _ingredientname, double _unitweight, double _totalweight) { recipename = _recipename; ingredientname = _ingredientname; unitweight = _unitweight; totalweight = _totalweight; } }(in reality there lot more data members quantity, weight, etc....) the actual dataset list called viewrecipesummary , looks this: recipename ingredientname 1 1 b 1 c 2 d 2 e 3 3 z i have existing query finds ingrident (recipegroup.key) , need following: 1- find recipes have ingredient 2- return rows data recipes and need use inside query (so needs let or something) lets ass

trying to understand offsetExists function in Zend/Registry.php -

public function offsetexists($index) { return array_key_exists($index, $this); } this taken zend/registry.php, question is: $this current object, right? here seems array? $this mean here? you'll notice zend_registry extends arrayobject . allows used like array. further reading - http://php.net/manual/en/class.arrayobject.php the reason zend_registry overrides arrayobject::offsetexists() due bug - https://bugs.php.net/bug.php?id=40442

javascript - JQuery .animate() only works in Chrome -

i using jquery .animate() function slide divs in container div. works without issue in google chrome, when try in either firefox or ie, divs become garbled mess , don't slide. i'm new javascript , ignorant in ways of browser compatibility, can point me in right direction? here relevant code: the html <div id="slider"> <div id="main" class="content"> </div> <div id="projects" class="content"> </div> <div id="about" class="content"> </div> <div id="contact" class="content"> </div> </div> the css #slider { width: 100px; height: 100px; overflow: hidden; position: relative; } #main { background-color: red; width: inherit; height: inherit; position: absolute; } #projects { background-color: blue; width: inherit; height: inherit; position: absolute; } #about { background-color:

IP address to binary in C -

i have ip address so: address = '192.168.1.11'; and need convert binary format 11000000 10101000 00000001 00001011 i have ideas on how leftshift decimal number , using inet_addr, not sure how go doing it. thanks, i'm still new c. there socket function specific transforming text ip 32-bit "longip" address, might unecessary in context. simple form parse using sscanf() : char ip[] = "192.168.1.11"; int n1, n2, n3, n4; sscanf(ip, "%d.%d.%d.%d", &n1, &n2, &n3, &n4). // result: // n1 = 192 // n2 = 168 // n3 = 1 // n4 = 11

lua - NSURLErrorDomain error code -999 in iOS -

i've been trying use corona sdk's facebook api post score on game i'm developing on facebook. however, i'm having problem it. during first time try post facebook, error after login , user authentication: nsurlerrordomain error code -999 then, won't post on facebook. possible causes of error , how can address it? tried searching web couldn't find information it. in advance. by way, not using webview on app. widget api , show_dialog listener in facebook class. the error has been documented on mac developer library (ios docs) the concerned segment documentation be: url loading system error codes these values returned error code property of nserror object domain “nsurlerrordomain”. enum { nsurlerrorunknown = -1, nsurlerrorcancelled = -999, nsurlerrorbadurl = -1000, nsurlerrortimedout = -1001, as can see; -999 caused errorcancelled . means: another request made before previous request completed.

linux - Collect data from a named pipe for a period of time -

i want analyse data named pipe, example: cat trace_pipe | awk '{print $6}' | head -100000 | sort | uniq -c | sort -k 1 -nr this command collect first 100k lines of data trace_pipe . there way me collect data 10 seconds rather limited number of lines? you can use timeout command, might need split commands timeout 10 cat trace_pipe > trace_pipe.cut awk '{print $6}' trace_pipe.cut | sort | uniq -c | sort -k 1 -nr