Skip to content

Instantly share code, notes, and snippets.

@tombeynon
tombeynon / acl.rb
Created March 8, 2017 14:10
Update ACL for all files in a bucket
require 'aws-sdk'
Aws.config.update({
region: 'REGION_CODE_HERE',
credentials: Aws::Credentials.new(
'ACCESS_KEY_ID_HERE',
'SECRET_ACCESS_KEY_HERE'
)
})
bucket_name = 'BUCKET_NAME_HERE'
@tombeynon
tombeynon / pgloader-commands
Created October 5, 2016 15:06
pg_loader config to migrate a MySQL DB to Postgres
-- See https://github.com/dimitri/pgloader/blob/master/pgloader.1.md for
-- connection string options.
LOAD DATABASE
FROM mysql://root@localhost/mydb
INTO postgresql:///mydb
WITH include drop, truncate, create tables, create indexes, foreign keys, reset sequences
-- CAST varchar to varchar instead of text
@tombeynon
tombeynon / index.html.erb
Created February 24, 2016 12:36
Facade pattern
<% if facade.logged_in? %>
<ul>
<% facade.active_users.each do |user| %>
<li><%= user.name %></li>
<% end %>
</ul>
<% else %>
<p>You are not logged in!</p>
<% end %>
@tombeynon
tombeynon / gist:c7fbcfa511be8ab6ecc9
Created October 6, 2014 21:31
Convert CSS url to Rails image-url
url\(['|"].?.?/images/([a-zA-Z0-9\-.\/]*)['|"]\)
image-url('$1')
@tombeynon
tombeynon / solr_string_sanitizer.rb
Last active August 29, 2015 14:06
Sanitizing Solr Requests
# http://pivotallabs.com/sanitizing-solr-requests/
module SolrStringSanitizer
ILLEGAL_SOLR_CHARACTERS_REGEXP = /[\+\-\!\(\)\{\}\[\]\^\|"~\*\?:;&]/
def self.sanitize(string)
if string
string.gsub(ILLEGAL_SOLR_CHARACTERS_REGEXP,"")
end
end
@tombeynon
tombeynon / Gemfile
Created January 21, 2014 17:28
Rails twitter integration
gem 'twitter'
gem 'twitter-text'
@tombeynon
tombeynon / createVhost.sh
Last active August 25, 2023 06:56
Programmatically create Apache VHost
#!/bin/bash
# /usr/local/bin/createSite.sh -d domain -t com -u user -p password -r git@github.com:user/repo.git
# TODO: SCP could be done in reverse
domain=''
tld=''
username=''
password=''
@tombeynon
tombeynon / gist:4723507
Last active December 12, 2015 05:39
Display Rails flash alerts
<% [:error, :alert, :notice].each do |key| %>
<%= "<div class='message #{key}'>#{flash[key]}</div>".html_safe if flash[key].present? %>
<% end %>
@tombeynon
tombeynon / deploy.rb
Created December 9, 2012 22:13
Capistrano multi-environment recipe
# Multi-environment deployment recipe
require 'bundler/capistrano'
task :production do
set :application, "Appname"
set :repository, "git@github.com:user/repo.git"
set :branch, "master"
set :deploy_to, "/var/www/vhosts/domain.co.uk"
server "server.domain.com", :app, :web, :db, :primary => true
@tombeynon
tombeynon / gist:4232133
Created December 7, 2012 09:34
jQuery preload images with callback
// Pass an array of image locations, and an optional callback function
function preload_images(images, callback){
var preloaded = 0;
jQuery.each(images, function(index, image){
var image = $('<img />').attr('src', image).load(function(){
preloaded++;
if(preloaded == images.length){ callback(); }
});
});
}