Skip to content

Instantly share code, notes, and snippets.

View cobbal's full-sized avatar

Andrew Cobb cobbal

View GitHub Profile
$ cat realworlddata.txt | awk '{print $2}' | python2.7 -c 'import sys, collections; print collections.Counter(line.strip() for line in sys.stdin)'
Counter({'excellent': 66, 'good': 53, 'average': 6})
@cobbal
cobbal / gist:4771297
Created February 12, 2013 16:53
Magic Trackpad HID Report Descriptor
0000000 05 01 09 02 a1 01 85 02 05 09 19 01 29 02 15 00
0000020 25 01 95 02 75 01 81 02 95 01 75 06 81 03 05 01
0000040 09 01 a1 00 15 81 25 7f 09 30 09 31 75 08 95 02
0000060 81 06 c0 05 06 09 20 85 47 15 00 25 64 75 08 95
0000100 01 b1 a2 06 02 ff 09 55 85 55 15 00 26 ff 00 75
0000120 08 95 40 b1 a2 85 13 15 00 25 01 75 01 95 01 06
0000140 01 ff 09 0a 81 02 06 01 ff 09 0c 81 22 75 01 95
0000160 06 81 01 c0 00
0000165
@cobbal
cobbal / monad.swift
Last active April 6, 2016 04:40
Monad protocol in swift
protocol Monad {
typealias F
typealias U
class func bind<M : Monad where M.U == U>(Self, F -> M) -> M
class func `return`(F) -> Self
}
extension Array : Monad {
typealias F = T
@cobbal
cobbal / keyDown.swift
Last active August 29, 2015 14:04 — forked from bjhomer/keyDown.m
func keyDown(theEvent: NSEvent) {
func intToString(x : Int) -> String {
return String(UnicodeScalar(x))
}
let hasCommand = (theEvent.modifierFlags & .CommandKeyMask).value != 0
switch theEvent.charactersIgnoringModifiers! {
case intToString(NSUpArrowFunctionKey) where hasCommand == true:
// Scroll to top

Keybase proof

I hereby claim:

  • I am cobbal on github.
  • I am cobbal (https://keybase.io/cobbal) on keybase.
  • I have a public key ASAUd-s9K6D_sdwVhWPmyHg0V6o0jL5wmAC6sKyuyW-Elgo

To claim this, I am signing this object:

@cobbal
cobbal / pre-commit
Last active October 2, 2019 20:07
swift lint before commit, put in ".git/hooks/pre-commit", then chmod +x it
#!/bin/zsh
set -euo pipefail
if xcbeautify --version 2>/dev/null >/dev/null; then
./scripts/runSwiftLint.sh 2>&1 | xcbeautify
else
./scripts/runSwiftLint.sh 2>&1 | tail -n 1
fi
class A {
private var underlying: Int = 0
open var x: Int {
set {
print("A.set \(newValue)")
underlying = newValue
}
get { underlying }
}
}
@cobbal
cobbal / zoom.py
Created December 19, 2019 16:53
opens zoom to the next/current meeting on your calendar.If distributing publicly, please remove the client secret. fill in your calendar id before use.
#!/usr/bin/env python3
# opens zoom to the next/current meeting on your calendar
# license: Apache 2.0
calendar="[email protected]"
import datetime
import pickle
import os.path
try:
#include <iostream>
#include <functional>
#include <random>
using namespace std;
struct OrElse {
function<void()> destruct;
~OrElse() {
if (destruct) { destruct(); }