Skip to content

Instantly share code, notes, and snippets.

View iwillspeak's full-sized avatar
🚲
The status is always bike

Will Speak iwillspeak

🚲
The status is always bike
View GitHub Profile
@iwillspeak
iwillspeak / complex.c
Last active December 15, 2015 21:59
An example of computing R and Theta for a complex number in C99
#include <stdio.h>
#include <stdlib.h>
#include <complex.h>
int main(int argc, char* argv[])
{
float _Complex number = 1 + (1 * _Complex_I);
printf("%g, %g", cabs(number), carg(number));
@iwillspeak
iwillspeak / fact.c
Last active December 16, 2015 03:59
# Compute the factorial of almost any number Mainly an excuse to use GMP
#include <stdlib.h>
#include <stdio.h>
#include <gmp.h>
/**
* Compute a Factorial
*
* returns a string representation of the number `n` in base 10.
*/
@iwillspeak
iwillspeak / bitfields.c
Created April 30, 2013 20:42
Comparison of the speed of accessing various C structures The timer code is from bitbucket.org/iwillspeak/moonbase
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include "timer.h"
struct aligned {
uint32_t o:8;
uint32_t d:8;
@iwillspeak
iwillspeak / emacs
Last active December 17, 2015 02:59
Emacs.app Launch ScriptThis script will nestle in yo' `/usr/local/bin` spawnin yo' Emacs.app processes to edit yo' files.
#!/usr/bin/env python
import sys
import subprocess
import tempfile
import time
# Emacs is in the Cellar, installed by Homebrew
emacspath="/usr/local/Cellar/emacs/24.3/Emacs.app/Contents/MacOS/Emacs"
def run(cmd, args):
@iwillspeak
iwillspeak / thunker
Last active December 17, 2015 11:09
Automatic wifi router resetter control scripts. Install `thunker` into your `/usr/local/bin` on the RPi and `thunker_daemon` into your *init.d*. You will need Ruby and the `net-ping` and 'wiringpi' gems. See it in action at https://vimeo.com/66365606
#! /usr/bin/ruby
require 'wiringpi'
require 'net/ping'
require 'syslog'
# Constants
OUTPUT_PINA = 0 # RPi Pin 11
OUTPUT_PINB = 1 # RPi Pin 12
ARM_ON_TIME = 0.1
@iwillspeak
iwillspeak / writer
Last active December 18, 2015 07:09
Open a file using iA Writer.app, for those who don't want to have to leave the command line to open markdown files.
#! /usr/bin/env bash
# Touch any files that don't exist
for file in "$@"
do
echo "$file"
if [ ! -a "$file" ]; then
touch "${file}"
fi
if [ ! -w "$file" ] || [ ! -r "$file" ]; then
@iwillspeak
iwillspeak / namespace.py
Last active December 18, 2015 20:38
Represents a read-only access to a dictionary through the . operator. Used to allow easy access to options and suchlike. Should be both Python 2.7 and 3.x compatible.
class Namespace(object):
"""Namespace
Represents a read-only access to a dictionary through the . operator. Used
to allow easy access to options and suchlike. Should be both Python 2.7 and
3.x compatible.
"""
def __init__(self, dict):
self.__dict__.update(dict)
@iwillspeak
iwillspeak / md160.c
Last active December 19, 2015 17:19
Just some hashing stuff
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <openssl/ripemd.h>
int main(int argc, const char* argv[]) {
FILE* file;
int length;
unsigned char* buffer;
@iwillspeak
iwillspeak / find_config.rb
Last active December 20, 2015 07:39
Find a file in the current directory or in any of it's parents
#! /usr/bin/env ruby
require 'pathname'
def find_config_file(file_name, path)
path = Pathname(path) unless path.is_a? Pathname
path = path.realpath
path.ascend do |subpath|
location = subpath + file_name
@iwillspeak
iwillspeak / lasm-mode.el
Created August 14, 2013 20:02
Mode files for Emacs
;; Defines a simple generic mode to hilight lasm files
(define-generic-mode 'lasm-mode
;; Comment start marker, we just do single line comments for now
'("//")
;; Keywords, these are just taken verbose from opslist.h
'("pushloc" "pusharg" "pushlitn" "pushlitd" "pushlits" "pushtrue" "pushfalse"
"pushnull" "pushident" "poploc" "poparg" "dup" "pop" "idlook" "ntod" "ntos"
"dtos" "btos" "xton" "xtod" "xtob" "xtos" "add" "sub" "mul" "div" "mod"
"pow" "log" "neg" "inc" "dec" "cat" "slice" "strchar" "strcmp" "lt" "lteq"
"gt" "gteq" "eq" "noteq" "not" "and" "or" "print" "jump" "jumpt" "jumpf"