Skip to content

Instantly share code, notes, and snippets.

View tysonmote's full-sized avatar
🤠
code cowboy

Tyson Mote tysonmote

🤠
code cowboy
View GitHub Profile
@tysonmote
tysonmote / gist:5301d89621d8d0f0d881
Last active August 29, 2015 14:23
Delete large Redis hashes with Ruby and Resque
$redis = Redis.new
class SafeHashDelete
@queue = :garbage_collection
BATCH_SIZE = 100
# Rename the key and queue for deletion
def self.delete(key)
newkey = "gc:hashes:#{$redis.incr("gc:index")}"
// The following test runs against a local Consul server started like so:
//
// consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul
//
// The test output looks like this:
//
// % go test -test.v
// === RUN TestConsul
// --- PASS: TestConsul (6.76s)
// consul_test.go:188: LastIndex after #1: 5

Start master in another window with redis-server master.conf

Fill master server with 10% keys that will expire very soon and 90% keys that wont expire for a while:

% ruby fill.rb | redis-cli --pipe -p 9998
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 1000002

Wait a few seconds and then start slave in another window with redis-server slave.conf

// BenchmarkBytesBufferNoReuse 2000000 790 ns/op 152 B/op 6 allocs/op
// BenchmarkBytesBufferWithReuse 5000000 675 ns/op 40 B/op 5 allocs/op
// BenchmarkBufioWriterNoReuse 1000000 2273 ns/op 4200 B/op 7 allocs/op
// BenchmarkBufioWriterWithReuse 5000000 541 ns/op 40 B/op 5 allocs/op
// BenchmarkFmt 1000000 1894 ns/op 176 B/op 5 allocs/op
package main
import (
"bufio"
"bytes"
~ % brew --config
HOMEBREW_VERSION: 0.9.4
ORIGIN: http://github.com/mxcl/homebrew.git
HEAD: c7f398392ac2c948b3e09ae4db36f7feed7aa376
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: 8-core 64-bit ivybridge
OS X: 10.8.4-x86_64
Xcode: 5.0 => /Applications/Xcode5-DP6.app/Contents/Developer
CLT: 1.0.0.9000000000.1.1249367152
~ % brew install go
==> Downloading https://go.googlecode.com/files/go1.1.2.src.tar.gz
Already downloaded: /Library/Caches/Homebrew/go-1.1.2.tar.gz
==> ./make.bash --no-clean
==> Caveats
The go get command no longer allows $GOROOT as
the default destination in Go 1.1 when downloading package source.
To use the go get command, a valid $GOPATH is now required.
As a result of the previous change, the go get command will also fail
~ % brew doctor
Your system is ready to brew.
~ % brew install go --cross-compile-common
==> Downloading https://go.googlecode.com/files/go1.1.2.src.tar.gz
Already downloaded: /Library/Caches/Homebrew/go-1.1.2.tar.gz
==> ./make.bash --no-clean
==> ./make.bash --no-clean
==> ./make.bash --no-clean
/private/tmp/go-OXep/go/src/cmd/5l/../ld/lib.c:661:9: error: no case matching constant switch condition '53' [-Werror]
switch(thechar){
CFEngine policy files:
bundle common env {
vars:
"hosts" slist => { "foo", "bar" };
}
...
bundle agent handle_hosts {
require 'redis'
def long_running_command
t = Thread.new do
conn = Redis.new
conn.client.call(["DEBUG", "SLEEP", "1"])
end
sleep 0.1 # let it connect before we return
t
end
@tysonmote
tysonmote / gist:5632433
Last active September 7, 2016 16:30
Stop overcomplicating things, JavaScript nerds. You need, like, 20 lines of JS, max, to do a modal window. Stop writing 500-line JS library monstrosities with painfully slow animations that break if you so much as breathe on them. Jesus.
<a href="#" data-modal="#myModal">Open</a>
<div class="modal hide" id="myModal">
<button class="close-modal">X</button>
(stuff)
</div>