Skip to content

Instantly share code, notes, and snippets.

View conorh's full-sized avatar

Conor Hunt conorh

View GitHub Profile
find . -name ".git" -exec rm -rf {} \;
@conorh
conorh / check_translations.rb
Created November 18, 2009 16:21
Check for missing i18n SimpleBackend translations
#!/usr/bin/env ruby
# This is intended for the I18n SimpleBackend. It checks to see that every string
# is translated. Running this script will output a list of translation keys that
# are remaining to be translated.
# The script only checks your custom translations. It does not check the Rails
# translations too. If you want to do that just remove the I18n.load_path = ...
# The script expects:
@conorh
conorh / gist:290606
Created January 30, 2010 16:11
Migrate Rails project from config.gem to Bundler
Steps to migrate a Rails 2.3 project to bundler.
1. Install bundler
gem install bundler
2. Remove existing vendor gems directory
rm -rf vendor/gems
=INFO REPORT==== 2010-02-16 04:51:40 ===
D(<0.199.0>:ejabberd_receiver:320) : Received XML on stream = "<message type=\"chat\" id=\"purple45d00c31\" to=\"test@mydomain.com\" from=\"someuser@gmail.com/Adium18999378\"><body>fasdf</body><html xmlns=\"http://jabber.org/protocol/xhtml-im\"><body xmlns=\"http://www.w3.org/1999/xhtml\"><span style=\"font-family: Helvetica; font-size: medium; background: #ffffff;\">fasdf</span></body></html><nos:x value=\"disabled\" xmlns:nos=\"google:nosave\"/><arc:record otr=\"false\" xmlns:arc=\"http://jabber.org/protocol/archive\"/></message>"
=INFO REPORT==== 2010-02-16 04:51:40 ===
D(<0.199.0>:shaper:61) : State: {maxrate,50000,193.68630641370012,
1266295899126721}, Size=455
M=4.558829829111692, I=1420.107
=INFO REPORT==== 2010-02-16 04:51:40 ===
@conorh
conorh / gist:1013577
Created June 8, 2011 01:02
rubinius 2.0.0pre json gem
conorhunt:~$ gem install json
Fetching: json-1.5.1.gem (100%)
Building native extensions. This could take a while...
Successfully installed json-1.5.1
1 gem installed
conorhunt:~$ irb
rbx-2.0.0pre :001 > require 'json'
TypeError: wrong argument type NilClass (expected Module)
from Rubinius::NativeMethod.load_extension at kernel/common/native_method.rb:43
from Rubinius::CodeLoader#load_library at kernel/delta/codeloader.rb:180
@conorh
conorh / nginx.conf
Created April 22, 2015 15:05
Using Nginx as a caching proxy for Refile with Ruby on Rails
http {
...
proxy_cache_path /data/perch.squaremill.com/shared/image_cache levels=1:2 keys_zone=images:10m;
...
}
@conorh
conorh / _form.html.erb
Created April 22, 2015 15:59
WYSIWYG content previews for Ruby on Rails
<% form_for(@blog_post) do |f| %>
<%= link_to 'Preview', '#', data: {preview: true, model: @blog_post.class.to_s} %>
<%= f.text_area :body %>
<%= f.submit %>
<% end %>
@conorh
conorh / mysql_cleanup_task.rake
Last active April 19, 2016 01:38
Cleanup structure.sql file after it is created
Rake::Task["db:structure:dump"].enhance do
path = Rails.root.join('db', 'structure.sql')
file = File.read(path)
file.gsub!(/ AUTO_INCREMENT=\d*/, '')
# remove all comment lines
file.gsub!(/^--.*/,'')
File.write(path, file)
end
@conorh
conorh / archive_old_migrations.rake
Created April 19, 2016 19:40
Rake task to archive old migrations
namespace :db do
namespace :migrations do
task :archive do
considered_old = 60 # how many days ago is considered old enough
puts "Looking for migrations older than #{considered_old} days"
db_path = File.join(Rails.root, "db/")
migrations_path = File.join(db_path, "migrate/")
old_migrations_path = File.join(db_path, "old_migrations/")
files = Dir[File.join(migrations_path, "/*.rb")]
@conorh
conorh / aws_v4_sig.rb
Last active April 26, 2016 02:03
Calculate AWS v4 signatures
require "uri"
require "time"
require "openssl"
# Calculate v4 AWS sig
class AWSV4Sig
def initialize(access_key, secret_key)
@access_key = access_key
@secret_key = secret_key
end