Skip to content

Instantly share code, notes, and snippets.

@watmough
watmough / pascal.c
Created January 5, 2012 23:00
Display a line of Pascals Triangle
/*
* Pascals Triangle in C
*
* Hacker News: http://news.ycombinator.com/item?id=3428984
*
*/
#include <stdio.h>
#include <stdlib.h>
@watmough
watmough / pascal2.c
Created January 6, 2012 05:18
Better C implementation for Pascals Triangle
/*
* Pascal2.c
*
* Pascals Triangle in C
*
* See notes below.
* To run:
gcc -std=c99 pascal2.c -o pascal2 && ./pascal2 10
*/
@watmough
watmough / Add Web Tab.py
Created January 13, 2016 23:45 — forked from steventroughtonsmith/Add Web Tab.py
Insert a custom browser tab into Pythonista
# coding: utf-8
from Foundation import *
from QuartzCore import *
from UIKit import *
import console
WKWebView = ObjCClass('WKWebView')
@on_main_thread
@watmough
watmough / FCPrivateBatteryStatus.m
Created January 30, 2016 00:03
How to get raw battery info (mAh remaining, etc.) from iOS using private APIs. For internal testing only, NOT APP STORE DISTRIBUTION!
#import <Foundation/Foundation.h>
#include <dlfcn.h>
NSDictionary *FCPrivateBatteryStatus()
{
static mach_port_t *s_kIOMasterPortDefault;
static kern_return_t (*s_IORegistryEntryCreateCFProperties)(mach_port_t entry, CFMutableDictionaryRef *properties, CFAllocatorRef allocator, UInt32 options);
static mach_port_t (*s_IOServiceGetMatchingService)(mach_port_t masterPort, CFDictionaryRef matching CF_RELEASES_ARGUMENT);
static CFMutableDictionaryRef (*s_IOServiceMatching)(const char *name);
@watmough
watmough / gist:0a11ecc424799ea5557901fe0bd9418c
Last active December 15, 2016 04:36
Silver Dollar Game in Rust
extern crate rand;
use rand::Rng;
use std::io;
// From "Practical Programs for the BBC Computer and Acorn ATOM"
// (c) David Johnson-Davies
// Sigma Technical Press 1983
// Silver Dollar Game
// http://www.acornatom.nl/atom_plaatjes/boeken/pracprog/pp.htm
@watmough
watmough / day_20.fs
Created December 21, 2017 20:47
Advent of Code Day 20 F# Part 2
open System
//module <%= namespace %>
// needed to make inference work e.g. num.MaxValue ???
// cite here:
type num = int32
// read from file
let lines filePath = System.IO.File.ReadLines(filePath);;
@watmough
watmough / NSData+JWUtil.m
Created September 24, 2011 02:21
Provide a rangeOfData:options:range: method for pre-4.0 iOS.
//--------------------------------------------------------------------------------
// NSData+JWUtil
// Provide a rangeOfData:options:range: method for pre-4.0 iOS.
//--------------------------------------------------------------------------------
@interface NSData (JWUtil)
- (NSRange)rangeOfDataX:(NSData *)dataToFind options:(NSDataSearchOptions)mask range:(NSRange)searchRange;
@end
//--------------------------------------------------------------------------------
// NSData+JWUtil
@watmough
watmough / utils.hpp
Created December 3, 2018 02:58
UTILS_HPP
#ifndef UTILS_HPP
#define UTILS_HPP
// Advent of Code 2018
// utils.hpp
#include <iterator>
// Count non-matching values over two ranges of iterators
// See: https://en.cppreference.com/w/cpp/algorithm/count
@watmough
watmough / reader.hpp
Created December 3, 2018 03:00
READER_HPP
#ifndef READER_HPP
#define READER_HPP
// Advent of Code 2018
// Handy text file reader returning vector<string>
// See: https://stackoverflow.com/a/1567703/33758
#include <iostream>
#include <fstream>
#include <string>
@watmough
watmough / day_05.c
Last active December 6, 2018 00:24
Day 5 - Alchemical Reduction
// Advent of Code 2018
// Day 05 - Alchemical Reduction
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int react(char * s) {
char *r = s+1, *w = s;
while (*r)