Posts

ruby on rails - Using a frozen constant as a hash key? -

i built small api makes few calls have similar payloads, have base payload merge in call-specific elements, so: def foo_call base_payload.merge({"request.id" => request_id}) end def biz_call base_payload.merge({"request.id" => some_other_thing}) end def base_payload { bar: bar, baz: baz, "request.id" => default_id } end my coworker suggested make "request.id" frozen constant, arguing making constant means can freeze means wont allocating new string object on each call, saving bit of memory. this: requestid = "request.id".freeze def foo_call base_payload.merge({requestid => request_id}) end def biz_call base_payload.merge({requestid => some_other_thing}) end def base_payload { bar: bar, baz: baz, requestid => default_id } end i'm little apprehensive, can't quite pin down reason why not (other latent resistance @ having new commit :> ). feel might cause...

With a simple http server in node.js, how to find out why it's crashed? -

i running basic http server serve static files in node.js express : var setting = require('../setting') var express = require('express'), app = express(), port = setting.http.port; app.use(express.static(__dirname + '/' + setting.http.static_dir)); app.listen(port); i know can use forever restart server if it's dead reason. but, there way log when server crashed can know reason why it's crashed , when it's crashed? with forever : forever -o out.log -e err.log my-script.js see this answer more details . if want log express server errors, use error handler generated express cli tool: server.on('error', onerror); /** * event listener http server "error" event. */ function onerror(error) { if (error.syscall !== 'listen') { throw error; } var bind = typeof port === 'string' ? 'pipe ' + port : 'port ' + port; // handle specific listen errors friendly m...

virtualbox - Getting timeout on vagrant up -

today have started learning vagrant. creating first, base virtual machine ( hashicorp/precise32) went pretty smooth. wanted test box, time :puppetlabs/ubuntu-14.04-32-puppet. im getting msg : default: warning: connection timeout. retrying... have read might because of disabled virtualization, understand virtualization it's needed 64bit machines. can problem here? me, please? in advance. try increase 'ssh_wait_timeout' increase 'boot_wait' activate vb.gui options in vagrantfile increase 'config.vm.boot_timeout options in vagrantfile disable shared folder line config.vm.synced_folder '.', '/vagrant', disabled: true in vagrantfile update vagrant (latest 1.8.1) update virtualbox (latest 5.0.12) cross finger

android - Compile error building project with multiple flavors and Play Services -

when trying build play services enabled project multiple flavors, compile errors. think might related package names not matching, not sure. have hints doing wrong? i using newer gradle plugin allows ( per gh issue ) i seeing error when try build multiple flavors: error:(115, 50) error: cannot find symbol variable global_tracker i double checked package names match expectation, wonder if still not correct. my build.gradle looks this: productflavors { app1 { applicationid "com.examplea.app" manifestplaceholders = [domain:"examplea"] } imore { applicationid "com.exampleb.app" manifestplaceholders = [domain:"exampleb"] } crackberry { applicationid "com.examplec.app" manifestplaceholders = [domain:"examplec"] } an example of 1 of google-services.json files (which located @ main/src/examplea) i...

Order list item on Rails update with jQuery -

i have sidebar list of room names. can edit room's name in modal. when click update in modal, room name should updated in sidebar , should appear in proper order in list. happen on refresh because of server side rails code. need make work on client side. it's working fine except sorting. i've tried in update.js.erb file: $("ul.rooms li").detach().sort(asc_sort).appendto('ul.rooms'); function asc_sort(a, b){ return ($(b).text()) < ($(a).text()) ? 1 : -1; } that results in each list item appearing twice , newly updated room sorts bottom of list. here's html looks list item (the room name 1): <li> <a href="#" class="room" id="room-11"> 1 <span class="badge counter"></span> </a> <a class="cog-link pull-right" style="padding:0 20px 0 2px;" data-remote="true" href="/rooms/11/edit"><i class="glyphic...

ios - Need a completion block for SnapKit constraints in a UIView -

i have uiview in swift using snapkit layout it's views. want blur 1 of views, need put blur code in method runs after layout code finished , 1 view has it's proper size. i can't seem figure out right place blur code go. since snapkit based on blocks, it's asynchronous , don't know when finished. callback method can use? edit: reported issue on snapkit , blocks synchronous after all. however, in layoutsubviews (and after synchronous blocks) frames still cgrectzero , blur code can't snapshot , blur view of 0 width or height. i don't know snapkit there's technique can use code executed after last of bunch of asynchronous blocks has been completed. the trick create class hold piece of code , have each block hold reference it. in class's deinit code, execute code. example: class completionblock { var completioncode:()->() init?(_ execute:()->() ) { completioncode = execute } func deferred() {} deinit { ...

objective c - uisearchbar in grouped section uitable -

i've pieced several tutorials create grouped table sections , i'm trying uisearchbar work. problem i'm having how search within grouped sections. i've read similar questions post suggested can't this code create grouped sections #import "job.h" // model data #import "address.h" // model data - (void)viewdidload { [super viewdidload]; self.thetable.delegate = self; self.thetable.datasource =self; _searchbar.delegate = (id)self; fmdbdataaccess *db = [[fmdbdataaccess alloc] init]; jobs = [[nsmutablearray alloc] init]; jobs = [db getjobs:1]; _sections = [[nsmutabledictionary alloc] init]; nsmutablearray *jobstemparray = [db getjobsasdictionary:1]; bool found; // loop through books , create our keys (nsdictionary *book in jobstemparray) { nsstring *clong = [book objectforkey:@"addraddress"]; nsstring *c = [clong substringtoindex:1]; found =...