Skip to content

Instantly share code, notes, and snippets.

# Has your OS/FS/disk lost your data?
# cd to the directory containing your project repositories and run the command
# below. (It's long; make sure you get it all.) It finds all of your git repos
# and runs paranoid fscks in them to check their integrity.
(set -e && find . -type d -and -iname '.git' | while read p; do (cd "$(dirname "$p")" && (set -x && git fsck --full --strict)); done) && echo "OK"
# I have 81 git repos in my ~/proj directory and had no errors.
@ftrain
ftrain / actually.js
Last active November 10, 2023 01:16
A program that generates actuallies
/*
actually.js
_ _ _
__ _ __ _ __ _ __ _ ___| |_ _ _ __ _| | |_ _
/ _` |/ _` |/ _` |/ _` |/ __| __| | | |/ _` | | | | | |
| (_| | (_| | (_| | (_| | (__| |_| |_| | (_| | | | |_| |_
\__,_|\__,_|\__,_|\__,_|\___|\__|\__,_|\__,_|_|_|\__, ( )
|___/|/
*/
@mperham
mperham / gist:7d763bdc42465caf17c7
Last active August 29, 2015 14:02
Rule execution

I want to build a system which uses rules. These rules will change hourly (i.e. "this rule is effective from 2pm to 6pm"). The rules must support arbitrarily complex logic on just 2-3 pre-defined variables and result in a boolean:

item.a > 10 && item.b == 0 || item.category == FOOTWEAR

These rules will be executed hundreds of times per second so I can't afford the overhead of plain old eval. I want to reload the current effective ruleset from the database hourly, precompile each rule's logic string and execute it via the quickest method possible. It might look something like this:

class Rule
@apeiros
apeiros / hash_map.rb
Created March 13, 2014 12:13
Implement Hash#map_keys, #map_keys!, #map_values, #map_values!, #map_pairs and #map_pairs!
class Hash
def map_keys
map_pairs { |key, value| [yield(key), value] }
end
def map_keys!
map_pairs! { |key, value| [yield(key), value] }
end
def map_values
@ColinDKelley
ColinDKelley / hash_benchmark.rb
Last active November 5, 2016 17:16
hash benchmark
# -*- immutable: string -*-
require 'benchmark'
class Request
def initialize(first, last, city, state, country)
@hash =
{
'first' => first,
'last' => last,
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
class Foo
public def my_public_method
1 + 2
end
protected def my_protected_method
3 + 4
end
private def my_private_method
@DanielleSucher
DanielleSucher / one_char.sh
Last active December 17, 2015 22:59 — forked from aprescott/gist:5683945
Bash script to find all single-character commits in a git repository
first_commit=$(git log --pretty=format:%H | tail -1)
git rev-list --all --no-merges |
while read commit; do
if [ $commit == $first_commit ]; then break; fi;
IFS_backup=$IFS
IFS=$'\n'
diff_lines=( $(git diff --numstat --minimal -U0 --word-diff=porcelain $commit^ $commit | grep -E '^(\+[^+]|-[^-]).*$') )
IFS=$IFS_backup
@sstephenson
sstephenson / super.bash
Last active January 30, 2017 01:40
`super` in Bash
#!/usr/bin/env bash
source super.bash
foo() {
echo hello
}
super_function foo
foo() {
@pragdave
pragdave / gist:4981930
Created February 19, 2013 00:13
The Ruby 2 prepend() method makes method chaining a lot easier.
module SystemHook
private
def system(*args)
super.tap do |result|
puts "system(#{args.join(', ')}) returned #{result.inspect}"
end
end
end
class Object