Skip to content

Instantly share code, notes, and snippets.

View willhbr's full-sized avatar

Will Richardson willhbr

View GitHub Profile
struct SingleFiberAccess(T)
@object : T
{% if flag? :debug %}
@fiber = Fiber.current
{% end %}
def initialize(@object)
end
macro method_missing(call)
var theme = {
color: [
'#292c36',
'#dc3c3c',
'#95c76f',
'#d28e5d',
'#8485ce',
'#b73999',
'#00aba5',
'#a9acb6',
module MultiIndexable
macro index(type, *args, set_args = [] of Nil)
@%lock = Mutex.new
{% for arg in args %}
@values_by_{{ arg.var }} = Hash({{ arg.type }}, {{ type }}).new
def [](*, {{ arg.var }} key : {{ arg.type }}) : {{ type }}
@values_by_{{ arg.var }}[key]
end
def []?(*, {{ arg.var }} key : {{ arg.type }}) : {{ type }}?
@values_by_{{ arg.var }}[key]?
require "http/server"
module MaybHTTP
VERSION = "0.1.0"
class ConcattedIO < IO
def initialize(@first : IO::Memory, @second : IO)
end
def read(bytes)
if @first.closed?
size = @second.read(bytes)
else
@willhbr
willhbr / spindle.cr
Created January 4, 2020 13:02
Crystal Fiber Spindles
class Spindle [12/193]
@fiber_count = 0
@chan = Channel(Nil).new
@subspindles : Array(Spindle)? = nil
@on_error : Proc(Exception, Nil)? = nil
def initialize
end
def self.new(existing : Spindle?)
@willhbr
willhbr / then.sh
Created January 8, 2019 11:14
Run something after something else
#!/bin/bash
__then() {
fg
echo "> $*"
"$@"
}
alias 'then:'=__then
### 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 September 30, 2017 04:50
Number of words in reports vs number of words in code
#!/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 04:47
Type-safe unit conversion with composite units
/**
* 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
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