Skip to content

Instantly share code, notes, and snippets.

@gre
gre / easing.js
Last active April 13, 2025 15:13
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
/*
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License, Version 2,
* as published by Sam Hocevar. See the COPYING file for more details.
*/
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
@jboner
jboner / latency.txt
Last active April 19, 2025 21:29
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@davidhemphill
davidhemphill / gist:5188894
Created March 18, 2013 17:09
How to do a Git clone without the .git directory
// Clone the repo
git clone --depth=1 git://someserver/somerepo dirformynewrepo
// Remove the .git directory
rm -rf !$/.git
@tedmiston
tedmiston / nodejs-tcp-example.js
Last active April 1, 2025 08:06
Node.js TCP client and server example
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');
@aras-p
aras-p / preprocessor_fun.h
Last active April 7, 2025 13:38
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
@simonw
simonw / gist:7000493
Created October 15, 2013 23:53
How to use custom Python JSON serializers and deserializers to automatically roundtrip complex types.
import json, datetime
class RoundTripEncoder(json.JSONEncoder):
DATE_FORMAT = "%Y-%m-%d"
TIME_FORMAT = "%H:%M:%S"
def default(self, obj):
if isinstance(obj, datetime.datetime):
return {
"_type": "datetime",
"value": obj.strftime("%s %s" % (
@satokjp
satokjp / test_ssh.tcl
Created March 28, 2014 06:46
expect ssh sample script
#!/usr/bin/expect --
# for cygwin64 Windows
#
# timeout sec
#set timeout 10
set timeout -1
# HOST & ID
set HOST "[email protected]"
@scottt
scottt / div0.c
Last active February 26, 2023 13:05
Generate SIGFPE through integer division by zero
volatile int a, b, out;
__attribute__((noclone,noinline))
void g(void)
{
a = -1;
b = 0;
out = a/b;
}
@yudai
yudai / gist:864840c497b643db7c31
Last active December 12, 2022 00:07
runC quick start
# generate rootfs
sudo debootstrap --arch=amd64 trusty rootfs
# container.json (from README.md)
cat <<__EOF__>container.json
{
"version": "0.1",
"os": "linux",
"arch": "amd64",
"processes": [
@chambart
chambart / gist:a3b05c0895f6afb9cf01
Created July 3, 2015 15:22
Peano numbers with ocaml functors
type zero = unit
type 'a succ = unit -> 'a
type 'a nat =
| Zero : zero nat
| Succ : 'a nat -> 'a succ nat
module type T = sig
type t
val v : t nat