Skip to content

Instantly share code, notes, and snippets.

@mmalecki
mmalecki / nextTick.js
Created October 2, 2011 12:13
process.nextTick vs setTimeout(fn, 0)
for (var i = 0; i < 1024 * 1024; i++) {
process.nextTick(function () { Math.sqrt(i) } )
}
@mmalecki
mmalecki / ren.py
Created July 10, 2011 12:15
Simple Python script to remove leading numbers from file names (useful when renaming music files)
#!/usr/bin/python
import re
import os
import os.path
pattern = re.compile("^[0-9]+ ?- ?")
def directory(d):
for f in d[2]:
if pattern.match(f):
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
@mmalecki
mmalecki / test.sh
Created November 9, 2012 01:18
The only test runner you'll ever need
#!/bin/sh
echo "Running test suite"
passed=0
failed=0
total=0
for t in test/*-test.js; do
total=`expr $total + 1`
function getLine(offset) {
var stack = new Error().stack.split('\n'),
line = stack[(offset || 1) + 1].split(':');
return parseInt(line[line.length - 2], 10);
}
global.__defineGetter__('__LINE__', function () {
return getLine(2);
});
@mmalecki
mmalecki / index.js
Created August 13, 2013 14:41
I taught a neural network to recognize a cross
var nn = require('nn');
var correct = [
[
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0,
0, 0, 1, 1, 1, 1, 0, 0,
0, 0, 1, 1, 1, 1, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0,
@mmalecki
mmalecki / fetch.sh
Created July 19, 2013 12:07
Easily fetch from your network on GitHub
#!/bin/sh
username=$1
git remote -v | grep "$username"
if [ $? -ne 0 ]; then
project=`git ls-remote --get-url | sed 's/.*\/\([a-z]*\).git/\1/g'`
git remote add "$username" "https://github.com/$username/$project.git"
fi
git fetch "$username"
  • 2 cups water
  • 1 cup caster sugar (to taste)
  • 1/2 teaspoon powdered cinnamon
  • 1/2 teaspoon powdered ginger
  • 1 clove
  • splash of lime juice
  • sliced peppers (depending on desired spicyness, either remove or save the seeds)

Preheat oven to 90 *C.

replicated_api_version: 1.0.0
name: npm Enterprise
version: "[IMAGE_VERSION]"
release_notes: "remove proxy if not needed, remove reject-unauthorized from config"
properties:
app_url: '{{repl ConfigOption "website_url" }}'
logo_url: "https://s3.amazonaws.com/replicated-vendor-assets/66045325f001a1e0ccde2d457cb2b30b/66045325f001a1e0ccde2d457cb2b30b.png"
console_title: "npm Enterprise Management Console"
bypass_local_registry: false
admin_commands:
@mmalecki
mmalecki / buffer.js
Created November 13, 2012 17:59
Differences between multiple arguments of `console.log` and concatenating strings
var b = new Buffer('Hello, world');
console.log('buffer: ' + b);
console.log('buffer:', b);
/* Output:
buffer: Hello, world
buffer: <Buffer 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64>
*/