Skip to content

Instantly share code, notes, and snippets.

@ktheory
ktheory / redis.md
Created August 25, 2014 22:56
Redis hash benchmarks

Determine the memory impact of storing indicator counts in one big hash, or several smaller hashes.

See the redis memory docs for the advantages of several smaller hashes.

Test 1: One big hash

Store 10mm values in one big hash. Code:

r = Redis.new
@ktheory
ktheory / dd.log
Last active November 10, 2023 23:41
EC2 EBS-SSD vs instance-store performance on an EBS-optimized m3.2xlarge
# /tmp/test = EBS-SSD
# /mnt/test = instance-store
root@ip-10-0-2-6:~# dd bs=1M count=256 if=/dev/zero of=/tmp/test
256+0 records in
256+0 records out
268435456 bytes (268 MB) copied, 3.26957 s, 82.1 MB/s
root@ip-10-0-2-6:~# dd bs=1M count=256 if=/dev/zero of=/tmp/test
256+0 records in
256+0 records out
@ktheory
ktheory / .gitconfig
Created May 5, 2014 17:30
Aaron's ~/.gitconfig
# Inspired by https://github.com/gabebw/dotfiles/blob/master/gitconfig.erb
[user]
name = Aaron Suggs
email = XXX
[core]
excludesfile = ~/.gitignore
[apply]
whitespace = nowarn
[diff]
color = auto
FROM ubuntu:14.04
MAINTAINER aaron@ktheory.com
RUN apt-get update
RUN apt-get install -y build-essential libssl-dev curl
# Install ruby-build
RUN export ruby_build_release=20140420 && \

Rails Asset Pipeline + S3

The asset pipeline changed a bit in Rails4, and I've never been super happy w/ the egads approach to tar'ing assets.

So here's my idea for a better approach.

Features:

  • Assets are only built once per SHA. (Deploys are fast.)
  • Old assets remain accessible on S3 (say, for emails)
  • Minimal compiling/uploading/downloading locally and on deployed servers. (FAAAASSSSTTT!)
#!/usr/bin/env ruby
##
# Restore simplenote backup
#
# If you want to restore your Simplenote for Mac database, you can use this script.
# I created it for this issue:
# http://help.simplenote.com/customer/en/portal/questions/2773965-most-of-my-notes-were-deleted?new=2773965
#
# First, find a good backup of your simplenote database stored in
@ktheory
ktheory / fail2ban.rb
Last active December 18, 2015 04:09
# First blacklist checks for /etc/password, and counts hits in cache
blacklist 'etc/password' do
if req.query_string =~ %r{/etc/passwd}
Fail2Ban.fail('etc_password', req.ip, limit: 3, period: 24.hours, ban_for: 24.hours)
end
end
# 2nd blacklist checks for banned IPs in cache
blacklist 'banned_ips' do
Fail2Ban.banned?(req.ip)
@ktheory
ktheory / thor_run_or_die.rb
Created June 4, 2013 21:52
Monkeypatch for Thor `run_or_die` action
require 'thor'
module Thor
class CommandFailedError < Error; end
module Actions
# runs command, raises CommandFailedError unless exit status is 0.
def run_or_die(command, config={})
result = run(command, config)
if behavior == :invoke && $?.exitstatus != 0
message = "#{command} failed with %s" % ($?.exitstatus ? "exit status #{$?.exitstatus}" : "no exit status (likely force killed)")
@ktheory
ktheory / Gemfile
Last active December 14, 2015 12:38
Rack::Attack heroku demo w/ Redis
source 'https://rubygems.org'
gem 'rack-attack', :ref => '1c01e6097ce18f486d887ebbeb9f0c4b434cd8f5', :git => 'https://github.com/kickstarter/rack-attack.git'
gem 'redis-activesupport'
@ktheory
ktheory / test-status.rb
Created February 27, 2013 22:28
script to report Github commit status with CircleCi
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'octokit'
require 'yaml'
commit = ARGV.first || 'HEAD'
full_sha = `git rev-parse --verify #{commit}`.strip