Skip to content

Instantly share code, notes, and snippets.

@nicholas
nicholas / gist:1665233
Created January 23, 2012 19:59
Installing Falcon's Ruby 1.9.3 Performance Patches
# Reference: https://gist.github.com/1658360
curl https://raw.github.com/gist/1658360/afd06eec533ad0140011bdaf652e6cd82eedf7ec/cumulative_performance.patch > $rvm_path/patches/ruby/1.9.3/p0/falcon.patch
rvm install 1.9.3 -n fast --patch falcon
rvm gemset copy 1.9.3-p0@global 1.9.3-p0-fast@global
rvm gemset copy 1.9.3-p0@plustrac 1.9.3-p0-fast@plustrac
bundle
@xslim
xslim / Gemfile
Created December 20, 2012 11:11
RSpec Remote API testing
source 'https://rubygems.org'
source 'http://gems.github.com'
gem 'rspec'
gem 'remote_http_testing'
gem 'net-http-spy'
gem 'mechanize'
gem "ZenTest"
# Beautifying
gem 'awesome_print'
@JEG2
JEG2 / struct.md
Created June 3, 2013 21:50
Thinking out loud about the merits and drawbacks of two different usages of Struct…

How Should We Use Struct?

The Choice

It's common in Ruby to see some code setup a Struct like this:

class Specialized < Struct.new(:whatever)
  # ... define custom methods here...
end
@madrobby
madrobby / gist:c55f39bfdbd60bf14671
Last active August 23, 2018 17:48
Deny commonly used security-probing things that spam up log files (for a Rails app)
location ~ ^/(wp-admin|wp-login\.php|priv\.dog|companies\/sidekick) {
deny all;
break;
}
# file extensions that should never be served, this prevents
# potential malicious downloads in case someone manages to manipulate
# a Rails URL or write a file that can be served
# (~* matches case-insensitive)
location ~* \.(?:git|svn|DS_Store|asp|aspx|cgi|pt|pl|idx|php|exe|scpt|AppleScript|dll|dmg|pif|msi|application|msp|com|scr|hta|cpl|gadget|msc|jar|bat|vb|vbs|vbe|ws|wsh|inf|lnk|reg|scf|wsc|wsh|ps1|ps1xml|ps2|ps2xml|psc1|psc2|msh|msh1|msh2|mshxml|msh1xml|msh2xml)$ {
deny all;
@PatrickTulskie
PatrickTulskie / resque_retry.rb
Created July 25, 2011 19:15 — forked from clemens/resque_retry.rb
Retry failed Resque jobs in Ruby
# inspired by http://ariejan.net/2010/08/23/resque-how-to-requeue-failed-jobs
# retry all failed Resque jobs except the ones that have already been retried
# This is, for instance, useful if you have already retried some jobs via the web interface.
Resque::Failure.count.times do |i|
Resque::Failure.requeue(i) unless Resque::Failure.all(i, 1)['retried_at'].present?
end
# retry all :)
Resque::Failure.count.times do |i|
@mislav
mislav / fat-logfiles.sh
Last active December 22, 2018 19:56
Find "*.log" files in your home dir, sort them by fattest-first, and calculate the size of them all together.
find ~ -name '*.log' -print0 | xargs -0 -L1 stat -f'%z %N' | sort -rn | tee fat-logfiles.txt | head
awk '{ total += $1 } END { printf "total: %5.2f MiB\n", total/1024/1024 }' < fat-logfiles.txt
@avdi
avdi / apology101.markdown
Created March 22, 2012 17:36
How to apologize

Chances are your head's spinning right now. That accusation of bias caught you off guard, you got kind of defensive, and now all hell has broken loose. You're feeling attacked on all sides. You're a good person at heart, and having all these people treat you like the antichrist is pretty upsetting.

You need to say something, but you're probably not in the best headspace to write copy right now. So to help you along, here's my 100% guaranteed-or-you-money-back scandal defusement apology template:

@joshuap
joshuap / tag.js
Created August 5, 2019 21:21
Netlify function to tag subscribers in ConvertKit
// Netlify function to tag subscribers in ConvertKit
// https://www.netlify.com/products/functions/
// POST to /.netlify/functions/tag?id={subscriberId} with JSON array of tag ids: `[{tagId}, {tagId}, ...]`
const request = require("request-promise");
const apiKey = process.env.CONVERTKIT_API_KEY;
const apiSecret = process.env.CONVERTKIT_API_SECRET;
exports.handler = function(event, context, callback) {
@henrik
henrik / rules.md
Last active May 23, 2022 12:31
Sandi Metz' four rules from Ruby Rogues episode 87. Listen or read the transcript: http://rubyrogues.com/087-rr-book-clubpractical-object-oriented-design-in-ruby-with-sandi-metz/
  1. Your class can be no longer than 100 lines of code.
  2. Your methods can be no longer than five lines of code.
  3. You can pass no more than four parameters and you can’t just make it one big hash.
  4. When a call comes into your Rails controller, you can only instantiate one object to do whatever it is that needs to be done. And your view can only know about one instance variable.

You can break these rules if you can talk your pair into agreeing with you.

@holman
holman / gemspec-usage.md
Created February 12, 2012 07:02
test/spec/mini

Just install this in your apps like so:

gem 'test-spec-mini', :git => 'git://gist.github.com/1806986.git', :require => 'mini'