Skip to content

Instantly share code, notes, and snippets.

View warmwaffles's full-sized avatar
🛠️
Code Wrestling

Matthew Johnston warmwaffles

🛠️
Code Wrestling
View GitHub Profile
#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
enum type {
NIL,
@warmwaffles
warmwaffles / pg.sh
Last active August 29, 2015 14:11 — forked from cjolly/pg.sh
newpg=9.3.2
oldpg=9.2.4 # set this to your current PG version
# Stop current Postgres server
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
# Backup current db
mv /usr/local/var/postgres/ /usr/local/var/postgres-$oldpg
# Homebrew
#!/usr/bin/env bash
# Colours picked from https://robinpowered.com/blog/best-practice-system-for-organizing-and-tagging-github-issues/
###
# Label definitions
###
declare -A LABELS
# Platform
@warmwaffles
warmwaffles / will_paginate.rb
Created June 22, 2012 15:14 — forked from isaacbowen/will_paginate.rb
extends will_paginate to play well with Twitter's Bootstrap
# config/initializers/will_paginate.rb
module WillPaginate
module ActionView
def will_paginate(collection = nil, options = {})
options[:renderer] ||= BootstrapLinkRenderer
super.try :html_safe
end
class BootstrapLinkRenderer < LinkRenderer
@warmwaffles
warmwaffles / latency.markdown
Created December 9, 2015 06:36 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC
"-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>mac.bitlbee</string>
<key>ProgramArguments</key>
<array>
import com.google.common.base.Preconditions;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
@warmwaffles
warmwaffles / postgres_queries_and_commands.sql
Created January 18, 2018 21:06 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
#include "mach_gettime.h"
#include <mach/mach_time.h>
#define MT_NANO (+1.0E-9)
#define MT_GIGA UINT64_C(1000000000)
// TODO create a list of timers,
static double mt_timebase = 0.0;
static uint64_t mt_timestart = 0;
@warmwaffles
warmwaffles / GeodesicSphere.js
Created April 18, 2018 04:14 — forked from Inscrutabilis/GeodesicSphere.js
Three.js geodesic sphere primitive class
/**
* @author Inscrutabilis / mailto:iinscrutabilis@gmail.com
*/
/*
* Generates a geodesic sphere geometry
* By default, it is 1x1x1 octahedron, as a first approximation to sphere
* It will return more sphere-like object if you specify iterations > 0
* But please keep in mind that it generates (4 ^ iterations) * 8 faces
* Radius argument overrides default sphere radius (1)