Posts

Using a boolean attribute as a conditional on an update action on a model in Rails 3 -

imagine have boolean , string attribute on model data this: model.locked => true model.status => "available" when update action invoked, want use boolean attribute control whether string attribute gets modified update, other attributes in update should saved regardless. so if model.locked => true and try model.status = "sold" then model.status => "available" currently have model this... before_update :dont_update_locked_item, :if => :item_locked? def item_locked? self.locked end def dont_update_locked_item #some rails magic goes here end how prevent single attribute being updated? i know answer going hurt, me out. it's late, i'm tired , i'm fresh out of talent. ;-) hope doesn't hurt :) class item < activerecord::base validate :cannot_update_if_locked, :on => :update def item_locked? self.locked end def cannot_update_if_locked errors.add(:item_id, "is lo...

Conventions for combining PHP with HTML -

i studying php book. author uses echo output html. @ first thought how supposed done, picked more "advanced" book. author of second book inserted php code between html rather echo whole thing. how done in large web development companies work on large projects? can use either, or 1 more accepted other? take code example: <?php //pagination if ($pages > 1) { //determine current page $current_page = ($start / $display) + 1; //print out previous page button if ($current_page != 1) { ?> <div class="pages"><strong><a href="view_users.php?s=<?php echo ($start - $display); ?>&amp;p=<?php echo $pages; ?>">&nbsp;&lt;&nbsp;</a></strong></div> <?php } //print page numbers ($i = 1; $i <= $pages; $i++) { if ($i == $current_page) { ?> <div class="pages active"><span>&nbsp;<?php echo $i; ?>&nb...

regex - Extract various characters from string (Alternate method) -

ok, have garbled text strings , want extract lower-case characters, upper-case characters , numerical values string 3 sub-strings , later use them purpose. have code this: sinput = "awsedrgy vgiycfry2345ewscfvg gyifvygxscyui^rsfv gyd&k^dfyuodvl234sdv8p7ogyhs" local slower, supper, snumbers = "", "", "" sinput:gsub("%l", function(s) slower=slower..s end) sinput:gsub("%u", function(s) supper=supper..s end) sinput:gsub("%d", function(s) snumbers=snumbers..tostring(s) end) print( slower, supper, snumbers ) and working fine. not sure on using these 3 separate extractions 30,000 lines of such garbled text. there more efficient way? or way best possible solution? try using complement classes : sinput = "awsedrgy vgiycfry2345ewscfvg gyifvygxscyui^rsfv gyd&k^dfyuodvl234sdv8p7ogyhs" local slower = sinput:gsub("%l","") local supper = sinput:gsub("%u","...

neo4j - Using relationship index on gremlin is relatively slow -

in neo4j, have relationship index 'index_e_assoc_smethdgexp' containing 180000 edges, attribute 'property'. want simple query lists 200 edges index, @ point regardless of property value (later query fetch same attribute values 200 first edge out vertices edge property <= 0.01), , fetch few attribute values out node: time = system.currenttimemillis(); t = new table(); g.idx('index_e_assoc_smethdgexp')[[property: neo4jtokens.query_header + "*"]][0..200].outv().id.as('nodeid').back(1).alias.as("alias").back(1).chr.as('chr').table(t,["nodeid","alias","chr"]).iterate(); system.currenttimemillis() - time =713ms getting 200 first edges index takes 262ms : time = system.currenttimemillis(); g.idx('index_e_assoc_smethdgexp')[[property: neo4jtokens.query_header + "*"]][0..200]; system.currenttimemillis() - time why first query completed slowly? shouldn't take long 200 ...

php - Dealing with an array of input text dynamically generated in JavaScript -

i want phone numbers of customer in form generates input text dynamically. have made this <html> <head> <title> telephones </title> <script language="javascript"> function add(type) { //create input text dynamically. if(typeof add.counter=='undefined') { add.counter=0; } add.counter++; var element = document.createelement("input"); //assign different attributes element. element.setattribute("type", type); element.setattribute("value", ""); element.setattribute("name", type.concat(add.counter)); var foo = document.getelementbyid("foobar"); //append element in page (in span). foo.appendchild(element); return add.counter; } </script> </head> <body> <form action="test1.php" method="post"> //here think there problem <input type="button" value="add...

Showing 500 (Internal Server Error) using backbone.js with slim.php when only adding new model -

i got code https://github.com/ccoenraets/backbone-cellar trying learn backbone.js. when trying add new model database using slim.php, showing 500 (internal server error). when trying fetch, update, delete working good. why showing error on adding ? plz me, thanks. window.wineview = backbone.view.extend({ initialize: function () { this.render(); }, render: function () { $(this.el).html(this.template(this.model.tojson())); return this; }, events: { "click .save" : "beforesave", "click .delete" : "deletewine" }, beforesave: function () { var self = this; var check = this.model.validateall(); if (check.isvalid === false) { utils.displayvalidationerrors(check.messages); return false; } // upload picture file if new file droppe...

symbol - How to return the real/imaginary part of a symbolic polynomial in MATLAB? -

given polynomial such (a+b*i)*c+i , a , b , c defined symbolic elements represent 3 real values , i imaginary unit, how return real part , imaginary part of polynomial? a = sym('a','real'); b = sym('b','real'); c = sym('c','real'); expand(real((a+b*1i)*c+1i))