Skip to content

Instantly share code, notes, and snippets.

View ecto's full-sized avatar
🙂
building things

Cam Pedersen ecto

🙂
building things
View GitHub Profile
@ecto
ecto / maybe_exit.sh
Last active September 15, 2016 17:51
~ :q 10:50 AM
Your shell has no parents. Are you sure you want to exit? (y/n)n
@ecto
ecto / home.js
Created January 24, 2011 22:05
The home page for our FaceMash clone
app.get('/', function(req, res){
db.keys('image:*:location', function(err,keys){
if (err) { throw err; }
var offense = keys[Math.floor(Math.random()*keys.length)];
var defense = keys[Math.floor(Math.random()*keys.length)];
if (defense == offense) {
defense = keys[Math.floor(Math.random()*keys.length)];
}
db.mget('image:' + offense + ':location', 'image:' + offense + ':rating',
'image:' + defense + ':location', 'image:' + defense + ':rating',
@ecto
ecto / gravity.js
Created November 23, 2013 23:35
calculate single-object effect on spacetime plane (with three.js PlaneGeometry)
var G = 100;
var vertex;
for (var i = 0; i < plane.geometry.vertices.length; i++) {
vertex = plane.geometry.vertices[i];
var distance = Math.sqrt(Math.pow(vertex.x - sphere.position.x, 2) + Math.pow(vertex.y - -sphere.position.z, 2));
var f = -(G * sphere.mass) / Math.pow(distance, 2);
vertex.z = f;
}
@ecto
ecto / snake.js
Last active December 28, 2015 22:59

Snake in your terminal!

Still needs score, losing state, and collision detection for walls.

If you have node installed, you can do this to play:

curl -Lo snake.js http://bit.ly/1jo72pa
#make sure you got the right file:
cat snake.js
@ecto
ecto / gist:7324775
Last active December 27, 2015 12:19
~ → cat testConnection.js
var net = require('net');
var url = require('url');
// edit this
var conString = 'tcp://crypton_test_user:crypton_test_user_password@localhost:5432/crypton_test'; // default
var config = parse(conString);
console.log(config);
@ecto
ecto / gist:5393759
Last active December 16, 2015 06:48
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) {
char line[80];
FILE *fr;
NSString *path = @"/path/to/long/file";
struct stat info;
stat([path UTF8String], &info);
off_t lastSize = info.st_size;
fr = fopen([path UTF8String], "rt");
@ecto
ecto / gist:4734484
Created February 7, 2013 21:36
bork
npm@1.2.10 /usr/local/lib/node_modules/npm
~ [ npm install -g express v0.8.18 ] 3:35 PM
npm info it worked if it ends with ok
npm info using npm@1.2.10
npm info using node@v0.8.18
npm ERR! TypeError: Object info has no method 'verbose'
npm ERR! at RegClient.regRequest [as request] (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:43:14)
npm ERR! at RegClient.get_ (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/get.js:112:8)
npm ERR! at RegClient.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/get.js:37:12)
@ecto
ecto / browser.js
Last active December 12, 2015 03:58
Challenge derivation test
// include CryptoJS
var message = '12345678901234567890123456789012';
var iv = CryptoJS.enc.Utf8.parse('1234567890123456');
var challengeKey = 'fe8844b73775265aef8839bf39de68a5aec6b0f447034472e8ff937bd9046e91';
var key = CryptoJS.enc.Hex.parse(challengeKey);
var challenge = CryptoJS.AES.encrypt(message, key, {
mode: CryptoJS.mode.CFB,
iv: iv
/*
Example of achieving compatibility with AMD and standard CommonJS by putting boilerplate around the standard CommonJS module format:
*/
(function(define){
define(function(require,exports){
// module contents
var dep1 = require("dep1");
exports.someExportedFunction = function(){...};
//...
var module = (function() {
var _private = {
i:5,
get : function() {
console.log('current value:' + this.i);
},
set : function( val ) {
this.i = val;
},
run : function() {