Skip to content

Instantly share code, notes, and snippets.

View skeggse's full-sized avatar
⚠️
Drop ICE

Eli Skeggs skeggse

⚠️
Drop ICE
View GitHub Profile
@skeggse
skeggse / example-json.php
Created October 25, 2012 18:25
Example JSON Output
<?php
header("content-type: application/json");
$output = array("classes" => array(0, 1, 2, 3, 4), "rooms" => array(0, 1, 2, 3, 4));
echo json_encode($output); // {"classes":[0,1,2,3,4],"rooms":[0,1,2,3,4]}
@skeggse
skeggse / gist:4181247
Created December 1, 2012 09:16
Node.js Segfault
/var/lib/stickshift/{REDACTED}/app-root/data/bin/node: line 3: 12992 Segmentation fault NODE_PATH=$OPENSHIFT_DATA_DIR/lib/node_modules PORT=$OPENSHIFT_INTERNAL_PORT C9_PORT=$OPENSHIFT_INTERNAL_PORT IP=$OPENSHIFT_INTERNAL_IP HOME=$OPENSHIFT_DATA_DIR $OPENSHIFT_DATA_DIR/bin/node-openshift "$@"
@skeggse
skeggse / app.js
Created December 9, 2012 19:36
ServerTime
socket.on('ping', function(fn) {
_.isFunction(fn) && fn(Date.now());
});
@skeggse
skeggse / stdout
Created March 18, 2013 05:29
npm install cb() never called!
npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/node', '/usr/bin/npm', '-ddd', 'install', 'julius' ]
npm info using npm@1.2.14
npm info using node@v0.10.0
npm verb node symlink /usr/bin/node
npm verb read json /home/skeggse/repos/package.json
npm WARN package.json home-pi@0.0.1 No README.md file found!
npm verb read json /home/skeggse/repos/node_modules/colors/package.json
npm verb read json /home/skeggse/repos/node_modules/express/package.json
npm verb read json /home/skeggse/repos/node_modules/imap/package.json
!!!5
html(lang="en")
head
title= title
link(rel='stylesheet', type='text/css', href='/stylesheets/style.css')
body
#account_manager
#sign_in Sign in
#sign_up Sign up
#top
@skeggse
skeggse / udpstream.js
Created July 11, 2013 18:09
Node Streams2 UDPStream Implementation
var dgram = require('dgram');
var _ = require('underscore');
var thumbs = {
twiddle: function() {}
};
_.mixin({
options: function(self, options, defaults) {
if (options)
function factorial(n) {
if (n == 0)
return 1;
return n * factorial(n - 1);
}
function factorialb(n) {
var b = 1;
while (n)
b *= n--;
@skeggse
skeggse / consumer.js
Created October 3, 2013 00:44
A Node.js backpressure example over a tcp/net stream. Just run index.js, the output is a little shoddy but it works. The producer only produces once the consumer catches up, but the streams are disconnected--they can't communicate directly.
var net = require('net');
var util = require('util');
var Writable = require('stream').Writable;
/**
* Pretends to consume the data written to it. In reality, it just eats data
* really slowly.
*
* @constructor
* @extends Writable
var net = require('net');
var EventEmitter = require('events').EventEmitter;
// just define this in the file scope, you don't need to assign it as a property
var numApples = 50;
// pickers, because this can handle multiple pickers
var fruitPickers = new EventEmitter();
// replentish apples every thirty seconds
var numApples = 5;
function handleConn(name) {
var pickedApples = 0;
return function pick() {
pickedApples++;
numApples--;
console.log(name, 'has', pickedApples, 'apples');
};