Skip to content

Instantly share code, notes, and snippets.

@maritz
maritz / test.js
Created August 26, 2016 22:33
strict null checks with function that always sets non-null (.js extension simply for highlighting... this is typescript)
let foo: null | string = null;
function setFoo(newFoo = 'bar') {
foo = 'baz' + newFoo;
}
setFoo();
console.log(foo.match('ba'));
var someResourcePromise = sometingAsync.get('someResource'); // this returns a promise which when resolved will return an object { more: { id: 123 } }
var doSomethingAsyncWithResult = function (id) {
return somethingAsync.get('moreResources', id);
}
someResourcePromise.then(doSomethingAsyncWithResult); // of course doenst work becuase the actual id would be in id.more.id
// is there some way in Q instead of then() to basically extract a property from a previous fulfillment?
// maybe like
@maritz
maritz / output
Created April 5, 2015 01:44
http server not closing
Server listening on 3020
closing
@maritz
maritz / high_cpu.js
Created April 1, 2014 13:55
Node.js setInterval CPU usage weirdness
var test = setInterval(function () {
var a = 1;
}, 33.3); // the only difference is not using a float here. This file uses about 21% cpu on my vps
var good_char_min_stat_threshold = 0;
var good_char_max_stat_threshold = 25;
var enemy_easy_peasy_multiplier = 1.75; // if you get a 25 stat char and set this to 1.8 your char will be too much of a pussy to fight anything and just endlessly explore the sewer. if that's up your alley, go ahead.
var max_fps = 10;
var visit_amounts_to_assume_encountered_all = 15;
var pause = false;
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, formidable = require("formidable");
var config = require("./config");
npm ERR! Error sending version data
npm ERR! Error: forbidden _npmUser field must be object
npm ERR! (You probably need to upgrade your npm version): sprintf/0.1.2/-tag/latest
npm ERR! at Request._callback (/usr/local/lib/node_modules/npm/lib/utils/npm-registry-client/request.js:180:12)
npm ERR! at Request.callback (/usr/local/lib/node_modules/npm/node_modules/request/main.js:99:22)
npm ERR! at Request.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/request/main.js:361:18)
npm ERR! at Request.emit (events.js:64:17)
npm ERR! at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/request/main.js:327:16)
npm ERR! at IncomingMessage.emit (events.js:81:20)
npm ERR! at HTTPParser.onMessageComplete (http.js:133:23)
Accept:application/json, text/javascript, */*; q=0.01
Cache-Control:max-age=0
Content-Type:application/json
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Ubuntu/10.04 Chromium/11.0.696.68 Chrome/11.0.696.68 Safari/534.24
X-Requested-With:XMLHttpRequest
@maritz
maritz / .settings.xml
Created April 5, 2011 13:10
cloud9 borked up .settings
<settings version="0.0.4" >
<auto>
<configurations debug="0" >
<config path="app.js" name="app" args="--scss-watch" />
</configurations>
<tree>["folder[1]","folder[1]/folder[1]","folder[1]/folder[1]/file[1]","folder[1]/folder[1]/file[2]","folder[1]/folder[2]","folder[1]/folder[2]/file[1]","folder[1]/folder[3]","folder[1]/folder[3]/folder[2]","folder[1]/folder[3]/folder[2]/file[1]","folder[1]/folder[4]","folder[1]/folder[4]/file[1]","folder[1]/folder[2]/folder[1]","folder[1]/folder[2]/folder[1]/file[1]","folder[1]/folder[3]/folder[1]","folder[1]/folder[3]/folder[1]/folder[1]","folder[1]/folder[3]/folder[1]/folder[1]/file[3]","folder[1]/folder[5]","folder[1]/folder[5]/file[1]","folder[1]/folder[5]/file[2]"]</tree>
<panel>{"ext/settings/settings":{"parent":{"visible":true,"width":"200","state":0},"visible":false,"flex":1,"state":"normal"},"ext/editors/editors":{"parent":{"visible":2,"flex":1,"state":0},"visible":2,"flex":1,"state":0},"ext/tr
var test1 = new testModel1(1); // creates a new instance with the id 1
var test2 = new testModel1(2); // creates a new instance with the id 2
test1.p('name', 'test'); // sets this.properties.name to 'test'
test2.p('name', 'shit'); // sets this.properties.name to 'shit'
console.dir(test1.id);
console.dir(test2.id);
console.dir(test1.p('name')); // returns this.properties.name