Skip to content

Instantly share code, notes, and snippets.

@jonstuebe
jonstuebe / ReSocket.ts
Created December 22, 2023 15:33
A WebSocket class with reconnection support
class ReSocket {
private token: string | undefined;
private socket: WebSocket | undefined;
private listeners: boolean = false;
private currentAttempt: number = 0;
private backoffTime: number = 1000;
private maxAttempts: number = 30;
private timer: NodeJS.Timeout | undefined;
private messageFn: (data: any) => void = (data) => {
//
@nnarhinen
nnarhinen / app.js
Last active December 21, 2015 22:19
Automatically join sockets to user-specific rooms using express.js sessions and socket.io
/**
* Module dependencies.
*/
var express = require('express'),
http = require('http'),
RedisStore = require('connect-redis')(express),
redis = require('redis'),
cookie = require('cookie'),
connect = require('connect'),
@SlexAxton
SlexAxton / .zshrc
Last active April 25, 2023 03:57
My gif workflow
gifify() {
if [[ -n "$1" ]]; then
if [[ $2 == '--good' ]]; then
ffmpeg -i $1 -r 10 -vcodec png out-static-%05d.png
time convert -verbose +dither -layers Optimize -resize 600x600\> out-static*.png GIF:- | gifsicle --colors 128 --delay=5 --loop --optimize=3 --multifile - > $1.gif
rm out-static*.png
else
ffmpeg -i $1 -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > $1.gif
fi
else
@max-mapper
max-mapper / index.js
Created September 26, 2012 04:30
html5 audio capture
// get latest canary and turn on web audio in chrome://flags
navigator.webkitGetUserMedia({audio:true}, function (stream) {
var context = new webkitAudioContext()
var streamSource = context.createMediaStreamSource(stream)
var sent = false
bufferFiller = context.createJavaScriptNode(2048, 1, 1)
bufferFiller.onaudioprocess = function(e) {
if (sent) return
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"