Skip to content

Instantly share code, notes, and snippets.

module ANSI
class << self
ESC = "\x1B"
CSI = ESC + "["
def cursor_up(n = 1)
"#{CSI}#{n}A"
end
def cursor_down(n = 1)
@sczizzo
sczizzo / goproj_auto.sh
Last active November 27, 2017 19:02
Automagically create a go env for each git project
unset OLD_GOPATH
# Try to find the nearest GOPATH under the given dir
func goproj_home() {
local dir="${1:-"$PWD"}/"
until [[ -z "$dir" ]]; do
dir="${dir%/*}"
if [[ -d "$dir/src" ]] && [[ -d "$dir/bin" ]] && [[ -d "$dir/pkg" ]]; then
@sczizzo
sczizzo / example.muxt
Created June 9, 2017 03:12
Sketching out a tmux layout utility
+------------+
| | 2 |
| |--------|
| 1 | 3 |4 |
| |--------|
| | 5 |
+------------+
+------------+
| 6 | 0 |
@sczizzo
sczizzo / moduleT.rb
Created May 21, 2017 18:24
module T - Naive typechecking for Ruby
module T
TypeError = Class.new(StandardError)
end
class T::Base
attr_reader :types
def initialize(*types)
@types = types
end
@sczizzo
sczizzo / env.go
Last active May 14, 2017 20:11
rerun
package main
import "os"
func envBool(key string, defaultValue bool) bool {
value, ok := os.LookupEnv(key)
if !ok {
return defaultValue
}
if value == "true" {
@sczizzo
sczizzo / rocker.rb
Last active June 13, 2018 21:25
Toy container runtime in Ruby
#!/usr/bin/env ruby
# Dependencies:
# - capsh
# - cgroup-utils
# - systemd
# - ruby
#
require 'fileutils'
require 'logger'
require 'optparse'
@sczizzo
sczizzo / classy.rb
Created October 13, 2016 17:08
Have some respect, and show some class!
module Classy
module Errors
def self.included(base)
base.extend(ClassMethods.clone)
base.private_class_method :error
end
module ClassMethods
def error(name, super_klass = StandardError)
klass_name = name.to_s.split('_').map(&:capitalize).join
@sczizzo
sczizzo / chef_dsl.rb
Created May 3, 2016 05:07
How one might implement Chef's Recipe DSL
# Basics
module Chef
class Resource
attr_reader :name
def initialize name
@name = name
end
@sczizzo
sczizzo / julio.rb
Last active March 16, 2016 21:56
Watch files, in Ruby
require 'docopt'
require 'pathname'
require 'set'
USAGE = <<DOCOPT
Julio.
Usage:
@sczizzo
sczizzo / julio.rs
Last active March 16, 2016 21:56
Watch files, in Rust
extern crate rustc_serialize;
extern crate docopt;
extern crate glob;
use std::time::Duration;
use std::thread::sleep;
use std::os::unix::fs::MetadataExt;
use std::os::unix::raw::*;
use std::collections::HashMap;
use std::collections::HashSet;