Posts

Showing posts from September, 2014

PHP: clean urls and query strings -

why isn't query string added array when using clean urls? eg. using /foo/bar?stack=overflow , $_get['stack'] variable empty. i'm implementing clean urls code: $request = rawurldecode($_server['request_uri']); // extracts index.php file path (eg. /my_app) // there no need specify path index.php script handles $path_to_index = str_ireplace($_server['document_root'].'/', '', $_server['script_filename']); $path_to_index = str_ireplace('/'.basename($_server['script_filename']), '', $path_to_index); // rid of path index.php $request = str_ireplace($path_to_index, '', $request); // rid of index.php in url $request = str_ireplace(basename($_server['script_filename']), '', $request); // our url clean can explode $request = explode('/', $request); // delete empty , reindex $request = array_values(array_filter($request)); if using rewriterules in .htaccess at end of rewriterul...

ruby on rails 3 - Extend a view with array of models (not join) -

Image
i'm trying extend view reusing views i've made. i've no partials , simplified directory views. views -- properties -- index.json.rabl -- show.json.rabl -- type -- index.json.rabl -- show.json.rabl i saw examples on how extend using child method, solution works have relation model. looked extends, in case didn't go far. here sample code came , not working right now. have suggestions? i've been reading docs , different articles couldn't come out working. object typedecorator.decorate(@type) attributes :uri, :id, :name, :public node(:properties) |type| collection property.in(_id: type.property_ids) extends 'properties/index' end ruby on rails 3 - extend view array of models (not join) - stack overflow stack overflow questions developer jobs documentation beta tags users current community help chat stack overflow meta stack overflow communities sign up or log in customize list. more ...

java - How to kill previous HttpRequest for a user session in a HttpServlet -

is there way locate previous httprequest, given session? web client sends request long running web service. while service running client sends request. want locate first request , send stop signal. background: have web service requires 2-4 seconds process. servlet hosted in tomcat container , using osgi access main processor in plugin. the requests come web site allows users make 10 or requests @ time. while user waiting may make page change start 10 web requests. need way locate previous requests. i'll find way send stop signal long running process allow original httprequest finish suitable error code. perhaps way @ problem say: if client makes series of requests overlap want service last request , cancel previous requests possible. i don't think httpsession gives looking for, recommend making kind of object requests can periodically check see if "newest" request. if no longer newest request can stop , return immediately.

c++ - Does Qt have a way of converting bytes to int and vice versa? -

i'm trying find qt function can convert bytes int same endianness i'm using below. feel i'm reinventing wheel here, , there must in qt libs already. exist? // todo: qt must have built in way of converting bytes int. int ipcreader::bytestoint(const char *buffer, int size) { if (size == 2) { return (((unsigned char)buffer[0]) << 8) + (unsigned char)buffer[1]; } else if (size == 4) { return (((unsigned char)buffer[0]) << 24) + (((unsigned char)buffer[1]) << 16) + (((unsigned char)buffer[2]) << 8) + (unsigned char)buffer[3]; } else { // todo: other sizes, if needed. return 0; } } // todo: qt must have built in way of converting int bytes. void ipcclient::inttobytes(int value, char *buffer, int size) { if (size == 2) { buffer[0] = (value >> 8) & 0xff; buffer[1] = value & 0xff; } else { // todo: other sizes, if needed. } } edit: data always big endian (no matter os), example 101 [0, 0, 0, 101] , 78000 [0, 1, 48, 176]. your code pretty...

yii components - Yii::app()->getModule('user') is not returning the right value view/layout/main.php -

yii::app()->getmodule('user') not returning right value in view/layouts/main.php i using yii-user yii-user extension manage user related features. when yii::app()->getmodule('user')->loginurl, i trying property of non-object at array('url'=>yii::app()->getmodule('user')->loginurl, 'label'=>yii::app()->getmodule('user')->t("login"), 'visible'=>yii::app()->user->isguest), pls tell me whats going wrong, known issue or that. here config/main.php // autoloading model , component classes 'import'=>array( 'application.models.*', 'application.components.*', 'application.modules.user.models.*', 'application.modules.user.components.*', ), 'modules' => array( 'user'=>array( # enable debuging 'debug' => true, # encrypting method (php hash function) 'hash' => 'md5', # send activation email ...

c++ - Calling width(), height(), size() or rect() inside subclass of QWidget ends with segfault -

i have problem qwidget 's width() , height() , size() or rect() function; when called gets segfault. qt 4.7. here header of problematic class: class plotcanvas : public qwidget { void paintevent(qpaintevent * e); uint64_t smallestdiv(); uint64_t longestlength(); void drawgrid(qpainter * painter); qvector<plot*> plots; int calculateheight() const; int calculatewidth() const; uint32_t cursorposition; public: plotcanvas(qwidget * parent = 0) : qwidget(parent) { setstylesheet("background-color: black"); setautofillbackground(true); setsizepolicy(qsizepolicy::minimumexpanding, qsizepolicy::minimumexpanding); setfocuspolicy(qt::strongfocus); update(); } void addplot(plot * plot); int getdivcount(); }; and actual segfaulting code: int plotcanvas::getdivcount() { qrect bounds = rect(); //segfaults qdebug() << bounds.size().width(); qdebug() << bounds.size().height(); return 10; } traced qt's qrect.h : inline int qrect::width() const { return x2 - x1...

git: finding which merge brough commit into the current branch -

i have number of branches, periodically merged, i.e. can have a, merged b, b c, d , d c, etc. suppose have commit x, know introduces in a, , merged c somehow (i can see when git log c). there way find out merge (which merge commit) brought commit x branch c? usually following: git log --oneline --ancestry-path --merges <commit-of-interest>..c the --ancestry-path argument key here: causes git show commits both descendant of <commit-of-interest> , ancestor of c . --merges option filters resulting list further show merge commits. each of printed merges falls 1 of following categories: the merge brought <commit-of-interest> branch the merge brought different branch branch has <commit-of-interest> both parent branches had <commit-of-interest> the first category 1 you're interested in. can tell category merge in looking @ commit subject line. start @ bottom of list; oldest merges in first category. it's technically possible write scr...

python - Reasons to rename property to _property -

i reading source code of collections.py yesterday. in namedtuple function, template string generated , exec ed in temporary namespace. in namespace dict, property renamed _property , tuple _tuple . i wonder what's reason behind this. problems renaming helps avoid? in general, underscore names used in standard library to keep namespace clean. in case of _tuple, necessary because you're allowed use "tuple" field name: >>> example = namedtuple('example', ['list', 'tuple', 'property']) >>> e.list [10, 20, 30] >>> e.tuple (40, 50, 60) >>> e.property 'boardwalk'

ios - Converting float to NSNumber -

i missing basic, here. must have forgotten it. basically, have following code purpose take nsnumber, convert float, multiply 2 , return result nsnumber. error on last step, , stumped. should there. nsnumber *testnsnumber = [[[nsnumber alloc] initwithfloat:200.0f] autorelease]; float myfloatvalue = [testnsnumber floatvalue] * -2; nslog(@" test float value %1.2f \n\n",myfloatvalue); [testnsnumber floatvalue:myfloatvalue]; // error here floatvalue not found the method floatvalue of nsnumber not take parameters. if set new float number, need re-assign testnsnumber , because nsnumber not have mutable counterpart: testnsnumber = @(myfloatvalue); // new syntax or testnsnumber = [nsnumber numberwithfloat: myfloatvalue]; // old syntax

javascript - What's wrong with this code to find heightInInches? -

after click, calculated bmi shown 0.3; expected answer 22.8 code snippet in question: calculatebutton.addeventlistener('click', function() { var feet = feetfield.value; var inches = inchesfield.value; var heightininches = (feet * 12) + inches; bmidisplay.text = ((weightfield.value / (heightininches * heightininches)) * 703).tofixed(1); }); heightininches should equal 68, not 608 . seems somehow feet (5) being multiplied 120 instead of 12 , tacking on inches (8) @ end, don't quite understand why that's happening, , why it's hiding me when step through code? debugger shows correct values feet (5) , inches (8) in formula incorrect value assigned heightininches after calculation. link bmi formula i think formatted question correctly; long time listener, first time caller. i've been staring @ long... had screenshots of ui , debugger had remove images post. ok, checking out. try adding: var feet = parsefloat(feetfield.value); var inches = parsefloat(inch...

plugins - Symfony getUser and save to form -

i have symfony form few hidden fields user can't edit set automatically when submit form. 1 field can't seem set userid. form secured requires authentication in order display (sfdoctrineguardplugin). what i'm looking form set "user_id" field logged in username. have tried in class file. if ($this->isnew() && ! $this->getseller_id()) { $this->setseller_id($this->getuser()->getguarduser()->getusername()); } but returns error stating there no user field in current table. hope explained right. do not set user_id in hidden field. change via firebug. preffer use code inside proccessform() try (edited): $form = new yourform(); $this->user = $this->getuser()->getobject(); $form->getobject()->setsellerid($this->user->getid()); $form->bind($request->getparameter($form->getname()));

android - Can't bind an Activity to Service -

i'm having trouble getting onserviceconnected() method run, means it's not binding activity service. it's simple i've missed out - i've tried quite few times - starting scratch. here go... my service class import android.app.service; import android.content.intent; import android.os.ibinder; public class quickservice extends service { private final ibinder mbinder = new quickbinder(this); @override public ibinder onbind(intent intent) { return mbinder; } } my binder class import android.os.binder; public class quickbinder extends binder { private final quickservice service; public quickbinder(quickservice service){ this.service = service; } public quickservice getservice(){ return service; } } and... activity trying bind service. import android.app.activity; import android.content.componentname; import android.content.context; import android.content.intent; import android.content.serviceconnection; import android.os.bundle; import android.os.ibinder; public ...