Skip to content

Instantly share code, notes, and snippets.

View avdi's full-sized avatar

Avdi Grimm avdi

View GitHub Profile
@avdi
avdi / github-actions-cheat-sheet.md
Created November 19, 2021 22:36
Github Actions Cheat Sheet

Just Fucking Use CircleCI.

@avdi
avdi / draw.sh
Last active July 5, 2021 19:02
Pick a random file using Bash (on a mac)
#!/bin/bash
if [[ $# -lt 1 ]]; then
echo "Usage: $0 somedir/*.jpg"
exit 1
fi
files=($*)
let "i = $RANDOM % ${#files[*]}"
pick=${files[$i]}
echo "Draw: $pick"
open $pick
@avdi
avdi / cloudSettings
Last active October 18, 2020 15:48
VS Code Configuration
{"lastUpload":"2020-10-18T15:48:53.735Z","extensionVersion":"v3.4.3"}
@avdi
avdi / askrubygems.rb
Created April 13, 2016 17:00
Options for "soft" script dependencies
if Gem::Specification.find_all_by_name("clipboard", "~> 1.0").any?
gem "clipboard", "~> 1.0"
require "clipboard"
# ...
end
class Symbol
def call(*curry_args)
->(receiver, *args) {
receiver.public_send(self, *curry_args, *args)
}
end
end
data = [{'x'=>1}, {'x'=>2},{'x'=>'foo'}]
class Array
def to_proc
->(receiver, *args) {
receiver.public_send(*self, *args)
}
end
end
data = [{'x'=>1}, {'x'=>2},{'x'=>'foo'}]
require "delegate"
class BankAccount
def number
123456
end
end
class SimpleDelegatorBankAccount < SimpleDelegator
end
@avdi
avdi / short_methods.rb
Created February 18, 2015 03:01
Short methods, long names
RUBY_VERSION # => "2.1.5"
m = define_method %^
puts "The coding standard says 'long methods are bad'."
puts "Stupid coding standards. What do they know?"
puts "It says long method names are OK though."
puts "Suckers!"
^ do
eval(__callee__.to_s)
end
import Sony.Vegas;
var one_second = Timecode.FromMilliseconds(1000);
var transport = Vegas.Transport;
var start = transport.LoopRegionStart;
var length = transport.LoopRegionLength;
transport.LoopRegionLength = length + one_second + one_second;
transport.LoopRegionStart = start - one_second;
@avdi
avdi / nullenum.rb
Created January 9, 2015 20:32
Behold, the null enumerator.
e = loop
e # => #<Enumerator: main:loop>
e.next # => nil
e.next # => nil
e.peek # => nil
e.size # => Infinity
e.rewind
e.next # => nil