Skip to content

Instantly share code, notes, and snippets.

@nhunzaker
nhunzaker / gist:1360499
Created November 12, 2011 13:09
Change your version of python on OSX

This was rather annoying.....

defaults write com.apple.versioner.python Version 2.6

@nhunzaker
nhunzaker / benchmarker.js
Created November 13, 2011 13:59
Benchmarking JS
// Credit: based on code by John Resig.
var startTime = new Date().getTime();
for (var iters = 0; timeElapsed < 1000; iters++) {
// Run some test code here.
timeElapsed = new Date().getTime() - startTime;
}
// iters = number of iterations achieved in 1000 milliseconds.
@nhunzaker
nhunzaker / speakeasy_sample.js
Created February 4, 2012 21:41
Using Speakeasy
// Using Speakeasy
//--------------------------------------------------//
// Sentiment analysis
var mood = require("speakeasy-nlp").sentiment;
mood.analyze("I hate you"); //=> { score: -1, ..... }
// Classifying statements
var meaning = require("speakeasy-nlp").classify;
meaning.classify("What is the meaning of life?") //==>
@nhunzaker
nhunzaker / gist:1805617
Created February 12, 2012 01:26
The http server plugin for flatiron
// found in lib/flatiron/plugins/http.js
app.start = function (port, host, callback) {
[... code ...]
app.listen(port, host, callback);
};
app.listen = function (port, host, callback) {
app.start(8080);
var io = require('socket.io').listen(app.server);
io.sockets.on('connection', function(socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function(data) {
console.log(data);
});
});
@nhunzaker
nhunzaker / gist:1860933
Created February 18, 2012 20:30
Converting Marak's color npm package from one mode to another
// Color Converter
function convertMode (str, from, to) {
var lex = [
'bold', 'italic', 'underline', 'inverse',
'white', 'grey', 'black',
'blue', 'cyan', 'green', 'magenta', 'red', 'yellow'
];
var styles = {
@nhunzaker
nhunzaker / docs.json
Created February 19, 2012 21:42
Iterating over a collection in plates
{
location: [ {
_id: '51a93bf0caf3b609bc00b6eef300097c',
ctime: 1329683491400,
mtime: 1329683491400,
name: 'Dos Perros',
address: '200 N. Mangum Durham, NC 27701',
geolocation: [ 35.998389, -78.899839 ],
pros: [],
cons: [],
@nhunzaker
nhunzaker / Result
Created February 20, 2012 13:54
Are Plates collections truly iterative?
<ul>
<li class="name">
[object Object],[object Object]
</li>
</ul>
@nhunzaker
nhunzaker / package.json
Created March 3, 2012 16:03
Issue deploying to Nodejitsu
warn: Creating new snapshot for version 0.1.0-5
info: Done creating snapshot 0.1.0-5
info: Updating application Tweetlibs
info: Activating snapshot 0.1.0-5 for Tweetlibs
info: Stopping app Tweetlibs
info: App Tweetlibs is now stopped
info: Starting app Tweetlibs
error: Error running command deploy
error: Nodejitsu Error (500): Internal Server Error
error: There was an error while attempting to deploy your application.
@nhunzaker
nhunzaker / inline-labels.js
Created March 5, 2012 15:35
Dead simple inline labels (or placeholder pseudo-polyfill) for jQuery
// Inline Labels
// -------------------------------------------------- //
$('input, textarea').each(function() {
var self = $(this),
label = $("label[for='" + self.attr("id") + "']").text();
// Replace initial values
if (!self.val().replace(/^\s+/g, "").length) {