Skip to content

Instantly share code, notes, and snippets.

View conorh's full-sized avatar

Conor Hunt conorh

View GitHub Profile
@conorh
conorh / ransack.md
Created November 10, 2023 23:15 — forked from raghubetina/ransack.md
Ransack Cheatsheet

Ransack Cheatsheet

The Ransack gem provides us with a powerful, flexible, easy-to-integrate search/filter form.

Installation

In your Gemfile, include

gem 'ransack'
@conorh
conorh / vips_install.sh
Created May 18, 2023 19:08
Installing VIPS for image manipulation of amazon linux 2022/2023
# Installing VIPS
# NOTE: This does not install any PDF handling (but maybe handled through imagemagick?)
sudo yum install fftw libjpeg-turbo-devel libexif-devel giflib-devel libtiff-devel libpng-devel libwebp-devel ImageMagick-devel
sudo yum install meson
sudo yum install cmake
sudo yum install glib2-devel
sudo yum install expat-devel
sudo yum install gobject-introspection-devel
curl -OL https://github.com/libvips/libvips/archive/refs/tags/v8.14.2.zip
unzip v8.14.2.zip
@conorh
conorh / gist:780ff75a5d59e242856e69d97feb6720
Last active September 14, 2018 01:52 — forked from shock/gist:120186
Find bloating passengers and kill them gracefully.
#!/usr/bin/env ruby
#
# Find bloating passengers and kill them gracefully. Run from cron every minute.
#
# required for passenger since cron has no environment
ENV['HTTPD'] = 'httpd'
MEM_LIMIT = ARGV[0] || 500
@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
@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 / 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 / _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 / 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 / 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
=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 ===