Skip to content

Instantly share code, notes, and snippets.

@pyrobot
pyrobot / index.html
Created March 19, 2013 13:19
resizable timeline
<!DOCTYPE html>
<style>
.axis text {
font: 8px sans-serif;
}
.axis line,
.axis path {
fill: none;
stroke: #000;
@pyrobot
pyrobot / module.js
Created March 6, 2013 14:37
angular factory methods that registers a modal dialog service that builds on a throttled screenSize event notification service
angular.module('app', [])
.factory('throttle', ['$timeout', function ($timeout) {
return function (fn, delay) {
var timer = null;
return function () {
var ctx = this, args = arguments;
$timeout.cancel(timer);
timer = $timeout(function () {
fn.apply(ctx, args);
}, delay);
@pyrobot
pyrobot / componentLoader_middleware.js
Created March 3, 2013 19:42
reads app component.json and serves the files associated with them
var path = require('path'),
fs = require('fs');
module.exports = function (rootComponentPath) {
var componentBase, modules, modPaths, modRoutes;
modPaths = [];
modRoutes = {};
rootComponentPath = rootComponentPath || '.';
@pyrobot
pyrobot / prompter.js
Created February 21, 2013 21:11
read prompts from stdin, send answers to a callback
/*
Usage:
module.exports([
'Demo of a prompt?', // cannot be empty
'Prompt with a default? (No prob)', // the last parenthesized term will be the default if empty
'Dont echo text?*' // end with an asterisk to turn off echoing to console
],
function (answer1, answer2, answer3) {
console.log("You responded with:\n'%s'\n'%s'\n'%s'", answer1, answer2, answer3);
@pyrobot
pyrobot / client.js
Last active December 13, 2015 23:29
http example
var net = require('net');
var socket = new net.Socket();
socket.connect(80, 'google.com', function () {
socket.pipe(process.stdout);
socket.write('GET / HTTP/1.0\n\n');
});
@pyrobot
pyrobot / client.js
Last active December 13, 2015 23:29
echo server (that logs what it received)
var net = require('net');
var socket = new net.Socket();
socket.connect(8124, 'localhost', function () {
console.log ('connected');
process.stdin.resume();
process.stdin.pipe(socket);
socket.pipe(process.stdout);
});
@pyrobot
pyrobot / index.html
Created January 26, 2013 16:07
same thing
<html ng-app>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
</head>
<body>
<span>Clicked: {{clickCount}}</span>
<button ng-click='clickCount = clickCount + 1'>Click</button>
</body>
</html>
@pyrobot
pyrobot / index.html
Created January 26, 2013 03:23
using angularJS with no extended attributes
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
<script src="module.js"></script>
</head>
<body>
<span>
{{msg}}
</span>
<button>Click</button>
@pyrobot
pyrobot / jshints.js
Created January 14, 2013 20:24
jshints
/*jshint indent:4, forin:true, noarg:true, noempty:true, eqeqeq:true,
bitwise:true, strict:true, undef:true, unused:true, curly:true,
browser:true, laxcomma:true, jquery:true*/
function compile(fmt) {
fmt = fmt.replace(/"/g, '\\"');
var js = ' return "' + fmt.replace(/:([-\w]{2,})(?:\[([^\]]+)\])?/g, function(_, name, arg){
return '"\n + (tokens["' + name + '"](req, res, "' + arg + '") || "-") + "';
}) + '";'
return new Function('tokens, req, res', js);
};