Skip to content

Instantly share code, notes, and snippets.

@silentmatt
silentmatt / parameters.js
Created June 19, 2009 18:43
Functions for dealing with function parameters
/*
Get an array of parameter names for a function.
Example:
js> function f(a, b, c) { return a + b * c; }
js> JSON.stringify(Function.parameters(f));
["a","b","c"]
*/
Function.parameters = function(f) {
@technoweenie
technoweenie / gist:1072829
Created July 8, 2011 21:12
.netrc file so you can push/pull to https git repos without entering your creds all the time
machine github.com
login technoweenie
password SECRET
machine api.github.com
login technoweenie
password SECRET
@dtrce
dtrce / mp3.js
Created September 8, 2011 18:39
streaming mp3 using nodejs
var http = require('http'),
fileSystem = require('fs'),
path = require('path')
util = require('util');
http.createServer(function(request, response) {
var filePath = 'path_to_file.mp3';
var stat = fileSystem.statSync(filePath);
response.writeHead(200, {
@ptekchand
ptekchand / shallowStringify.js
Created August 24, 2012 07:57
Hack to work around "TypeError: Converting circular structure to JSON"
/**
* Hack to work around "TypeError: Converting circular structure to JSON"
* which is seen when using JSON.stringify
* Intended to inspection/debugging purposes.
* Note: Will not display an Array in square brackets.
* Shows extra trailing comma before closing brace.
* @param obj
* @param [onlyProps] - Show only property names
* @param {String[]} [skipTypes=['function']] - array of types to trace only the type instead of value.
* @return {String}
@artisonian
artisonian / .gitignore
Last active March 21, 2024 20:13
go-eventsource
eventsource
go-eventsource
client/client
@mike-zhang
mike-zhang / udpProxy.go
Created October 8, 2012 15:58
Implementation of a UDP proxy in Golang
// Implementation of a UDP proxy
package main
import (
"flag"
"fmt"
"log"
"net"
"os"
@mudge
mudge / eventemitter.js
Last active July 2, 2024 13:06
A very simple EventEmitter in pure JavaScript (suitable for both node.js and browsers).
/* Polyfill indexOf. */
var indexOf;
if (typeof Array.prototype.indexOf === 'function') {
indexOf = function (haystack, needle) {
return haystack.indexOf(needle);
};
} else {
indexOf = function (haystack, needle) {
var i = 0, length = haystack.length, idx = -1, found = false;
@katowulf
katowulf / 1_query_timestamp.js
Last active September 21, 2023 20:28
Get only new items from Firebase
// assumes you add a timestamp field to each record (see Firebase.ServerValue.TIMESTAMP)
// pros: fast and done server-side (less bandwidth, faster response), simple
// cons: a few bytes on each record for the timestamp
var ref = new Firebase(...);
ref.orderByChild('timestamp').startAt(Date.now()).on('child_added', function(snapshot) {
console.log('new record', snap.key());
});
@ismasan
ismasan / sse.go
Last active March 19, 2024 18:13
Example SSE server in Golang
// Copyright (c) 2017 Ismael Celis
// 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:
// The above copyright notice and this permission notice shall be included in all
@gorsuch
gorsuch / gist:5aed15e45c90c9ad7d2d
Last active September 13, 2017 08:40
Example Serf client in go
package main
import (
"fmt"
"strconv"
"time"
"github.com/hashicorp/serf/client"
)