Instantly share code, notes, and snippets.

View rule_65.sh
# https://twitter.com/clarkkampfe/status/1069960462865981440
ruby -e h,w=$LINES,$COLUMNS/2'
rows = [{}]
[[6, true], [3, false], [1, true], [2, false], [1, true], [1, false]].flat_map { |n, val| [val]*n }.cycle.take(w+h).each_with_index { |val, i| rows[0][i] = val }
[[1, true], [3, false]].flat_map { |n, val| [val]*n }.cycle.take(h).each_with_index { |val, i| rows[0][i-w/2] = val }
def rows.rule
65
end
def rows.at(x, y)
row = (self[y] ||= {})
View 357.cr
# $ crystal build 357.cr --release
struct SeiveSlot
property number, divisors
def initialize(@number : Int32)
@divisors = [] of Int32
end
def prime?
@divisors.size == 2 && @divisors[0] == 1 && @divisors[1] == @number
View moire.rb
require 'graphics'
require 'matrix'
class Moire < Graphics::Simulation
include Math
def initialize(*args, distance:, radius:, frames_per_rotation:)
super *args
@fpr = frames_per_rotation
@radius = radius
@to_center = translate -w/2, -h/2
View client.rb
require 'socket'
FORWARDED_SIGNALS = %w(INT QUIT USR1 USR2 INFO WINCH) & Signal.list.keys
receiver = UNIXSocket.new('whatevz.sock')
pid = receiver.gets.to_i
receiver.send_io $stdin
receiver.send_io $stdout
$stdin.close
$stdout.close
View syntax.rb
send :if, if: :if if def if if: :if
def >>* my, oh: ($/=my*$* if/=?$/ if$==?))
$$/%/#$//
end
else
if def
alias alias: :alias
else def
begin
alias $$$>
View recursive_infinite_enumerator_in_ruby.rb
def memoized_each(&block)
memo, enum = [], Enumerator.new(&block)
Enumerator::Lazy.new 0.step do |y, i|
memo << enum.next if memo.size <= i
y << memo[i]
end
end
fibs = memoized_each { |y|
y << 0 << 1
View uninstall_snap_camera_mac_osx.sh
# these are reconstructed from a shell session without runnig them, so make
# sure you check that it's a sane thing to do before running it, I make no
# guarantees of fitness, and accept no liability. Run at your own risk.
sudo launchctl remove com.snap.SnapCameraRemover
rm -r ~/Library/Caches/Snap/
rm -r ~/Library/Caches/com.snap.SnapCamera/
rm -r ~/Library/Preferences/Snap/
rm ~/Library/Preferences/com.snap.SnapCamera.plist
rm ~/Library/Preferences/com.snap.Snap\ Camera.plist
sudo rm -rf /Applications/Snap\ Camera.app/
View example_of_postgresql_ltree.rb
require 'pg'
db = PG.connect dbname: 'josh_testing'
db.exec 'begin'
def db.exec(*)
super.to_a
rescue
$!.set_backtrace caller.drop(1)
raise
end
View git-nuke
#!/usr/bin/env bash
# a variation on https://twitter.com/r00k/status/1057657001013100544
function git-nuke() {
local local_branch="$1"
local upstream="$(git rev-parse --abbrev-ref "$local_branch"'@{upstream}')"
if [[ -n "$upstream" ]]; then
IFS=/ read remote_repo remote_branch <<<"$upstream"
git push "$remote_repo" --delete "$remote_branch" && git branch -D "$local_branch"
else
exit 1
View turtle_audio_curves.rb
# curves http://turtle.audio/play/m1f61t
# curves + music: http://turtle.audio/play/7ws2y4
# Hilbert
str = "A"
4.times { str.gsub! /[AB]/, "A" => "lBmrAmArmBl", "B" => "rAmlBmBlmAr" }
nil while str.gsub! /lr|rl|[AB]/, ""
str # => "mlmlmrmmrmrmlmlmrmrmmrmlmlmmlmrmrmlmmlmlmrmrmlmlmmlmrmrmmmrmrmlmmlmlmrmrmlmlmmlmrmrmlmmlmlmrmmrmrmlmlmrmrmmrmlmlmrmmrmrmlmmlmlmrmrmlmlmmlmrmrmmrmlmlmrmmrmrmlmlmrmrmmrmlmlmmmlmlmrmmrmrmlmlmrmrmmrmlmlmrmmrmrmlmmlmlmrmrmlmlmmlmrmrmlmlmrmrmlmmlmlmrmrmlmlmmlmrmrmmrmlmlmrmmrmrmlmlmrmrmmrmlmlmmmlmlmrmmrmrmlmlmrmrmmrmlmlmrmmrmrmlmmlmlmrmrmlmlmmlmrmrmmrmlmlmrmmrmrmlmlmrmrmmrmlmlmmlmrmrmlmmlmlmrmrmlmlmmlmrmrmmmrmrmlmmlmlmrmrmlmlmmlmrmrmlmmlmlmrmmrmrmlmlmrmrmmrmlmlm"
# Dragon