Skip to content

Instantly share code, notes, and snippets.

@ghewgill
ghewgill / expressive.neon
Last active June 21, 2018 00:13
Neon implementation of the Expressive C++17 Coding Challenge
%|
| Neon implementation of the Expressive C++17 Coding Challenge
| https://www.fluentcpp.com/2017/09/25/expressive-cpp17-coding-challenge/
|%
IMPORT file
IMPORT string
IMPORT sys
BEGIN MAIN
@ghewgill
ghewgill / ringtone.cpp
Created June 28, 2016 22:52
Nokia classic ring tone for pjsip tone generator
void do_bell()
{
pjmedia_tone_desc tones[] = {
{1318.51, 0, 200, 0, 0, 0}, // E
{1174.66, 0, 200, 0, 0, 0}, // D
{739.989, 0, 400, 0, 0, 0}, // F#
{830.609, 0, 400, 0, 0, 0}, // G#
{1108.73, 0, 200, 0, 0, 0}, // C#
{987.767, 0, 200, 0, 0, 0}, // B
{587.330, 0, 400, 0, 0, 0}, // D
% TODO (unimplemented)
TYPE Animal IS INTERFACE
FUNCTION make_sound(self: Animal)
END INTERFACE
TYPE Dog IS CLASS IMPLEMENTS Animal
size: Number
END CLASS
@ghewgill
ghewgill / addnewline.py
Last active August 29, 2015 14:09
Add newlines to files that don't have them
import sys
fn = sys.argv[1]
with open(fn, "r+") as f:
data = f.read()
if not data.endswith("\n"):
f.seek(0, 2)
f.write("\n")
print("Added newline to: {}".format(fn))
@ghewgill
ghewgill / .tmux.conf
Created August 25, 2014 21:33
Configuration file for tmux that makes it more like screen.
set -g prefix ^A
bind-key ^A last-window
bind-key ^C new-window
bind-key ^D detach-client
bind-key ^N next-window
bind-key ^P previous-window
bind-key ^W list-windows
bind-key space next-window
bind-key a send-prefix
bind-key h select-pane -L
@ghewgill
ghewgill / gist:3a64ee37e114d19e01a2
Created August 20, 2014 21:43
Keybase verification
### Keybase proof
I hereby claim:
* I am ghewgill on github.
* I am ghewgill (https://keybase.io/ghewgill) on keybase.
* I have a public key whose fingerprint is 862C 894D 4908 0240 FEEE 6D1F FA34 8460 74E0 2115
To claim this, I am signing this object:
import collections
import random
MAX = 2**64
def search(weight, target):
low = 0
high = MAX
time = 0
while True:
@ghewgill
ghewgill / total_bitcoins.py
Created March 27, 2014 23:56
Function to calculate total bitcoins rewarded given a block height.
def total_bitcoins(height):
total = 0
reward = 50
while height >= 210000:
total += reward * 210000
height -= 210000
reward /= 2
total += reward * height
return total
@ghewgill
ghewgill / gist:4982845
Created February 19, 2013 03:29
Ruby implementation of the `butif` construct, which turns a regular `if` statement upside down. Do something in the normal case, unless this other condition is true then do something else instead. This construct mirrors the kind of thinking that creates the logic one often finds in formal requirements documents.
class Butter
def initialize(block)
@block = block
end
def butif(cond)
if cond
yield
else
@block.call