Skip to content

Instantly share code, notes, and snippets.

Will Richardson willhbr

Block or report user

Report or block willhbr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@willhbr
willhbr / then.sh
Created Jan 8, 2019
Run something after something else
View then.sh
#!/bin/bash
__then() {
fg
echo "> $*"
"$@"
}
alias 'then:'=__then
View Keybase Proof
### Keybase proof
I hereby claim:
* I am willhbr on github.
* I am willhbr (https://keybase.io/willhbr) on keybase.
* I have a public key ASBPxIfCrNsJrL_PZpocUrsB3CWHeAeWZV7Bm_dHMutf8wo
To claim this, I am signing this object:
@willhbr
willhbr / seng_stats.rb
Last active Sep 30, 2017
Number of words in reports vs number of words in code
View seng_stats.rb
#!/usr/bin/env ruby
DETAILED_MODE = !ARGV[2].nil?
begin
require 'yomu'
rescue LoadError
msg = '(Looks like this is you)'
lab = `hostname`.strip.start_with? 'cs'
puts <<-EOF
You need the 'yomu' gem to use this script.
@willhbr
willhbr / Units.kt
Created May 23, 2017
Type-safe unit conversion with composite units
View Units.kt
/**
* Based on Ben Trengrove's example: https://gist.github.com/bentrengrove/9759a3fbb564d62e1e63f417c58a3895
*/
package units
import java.util.concurrent.TimeUnit
abstract class Unit(val suffix: String, val ratio: Double) {
internal fun convertToBaseUnit(amount: Double) = amount * ratio
internal fun convertFromBaseUnit(amount: Double) = amount / ratio
View regex_cond.ex
defmodule RegexCond do
defmacro match(matchable, do: matches) do
IO.inspect matches
de_sigged = matches |> Enum.map(fn
{:"->", context, [[lhs], code]} ->
lhs = de_sig matchable, lhs
{:"->", context, [[lhs], code]}
end)
quote do
View brainfuck.swag
read("", :program, {
def(:program_length, send(program, :length))
def(:program_location, 0)
def(:input, (1, 2, 3, 4))
def(:input_location, 0)
def(:program_char, {
send(program, :substring, program_location, +(program_location, 1))
})
@willhbr
willhbr / oh_god_why.swift
Last active May 7, 2016
I hope you're happy
View oh_god_why.swift
/// Please don't do this
func iff(condition: Bool, block: () -> ()) -> Bool {
if(condition) {
block()
}
return condition
}
func iff<T>(optional: Optional<T>, block: (val: T) -> ()) -> Bool {
@willhbr
willhbr / matrix.py
Created Jan 31, 2016
Matrix Determinant Calculator
View matrix.py
def calculate(mat, mul=1):
return (mul * mat[0][0] if len(mat) == 1 else sum((mul * calculate(list(map(lambda j: list(filter(lambda el: el != None, (mat[j][k] if k != i else None for k in range(len(mat))))), range(1, len(mat)))), (-1 if i % 2 == 0 else 1) * mat[0][i])) for i in range(len(mat))))
matrix = [
[1, -2, 3],
[0, -3, -4],
[0, 0, -3]
]
print(calculate(matrix))
@willhbr
willhbr / GrahamScan.swift
Created Jan 31, 2016
Graham Scan in Swift
View GrahamScan.swift
struct Point: CustomStringConvertible {
let x: Int
let y: Int
func theta(anchor: Point) -> Float {
let dx = Float(x - anchor.x)
let dy = Float(y - anchor.y)
let t = dy / (abs(dx) + abs(dy))
if dx == 0 && dy == 0 {
return 0
@willhbr
willhbr / pretty_json.rb
Created Oct 25, 2015
Format JSON with newlines.
View pretty_json.rb
def self.pretty_json(o, l=0)
o.class == Hash ? "{\n" + o.keys.map { |k| (" " * (l + 1) * INDENT) + "\"#{k.to_s}\": " + pretty_json(o[k], l + 1) }.join(",\n") + "\n" + (" " * l * INDENT) + "}" : o.class == Array ? "[\n" + o.map { |k| (" " * (l + 1) * INDENT) + pretty_json(k, l + 1) }.join(",\n") + "\n" + (" " * l * INDENT) + "]" : o.inspect
end
You can’t perform that action at this time.