Skip to content

Instantly share code, notes, and snippets.

@robdimarco
robdimarco / bootstrap-rvm-and-chef-solo-on-ubuntu.sh
Created March 24, 2012 14:21
Bash script to bootstrap chef solo using RVM on an Ubuntu server
DEFAULT_RUBY_VERSION="1.9.3-p125"
sudo apt-get -y install curl git-core bzip2 build-essential zlib1g-dev libssl-dev autoconf
if [ -x /usr/local/rvm/bin/rvm ]; then
echo "RVM Found..nothing to do";
else
echo "Installing RVM";
curl -o /tmp/rvm-installer -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer
@robdimarco
robdimarco / rl.zsh
Created April 5, 2012 15:35
Rails log viewer zsh alias from @tubbo
RAILS_PAGER='less'
rl() {
if [[ $RAILS_PAGER == "less" ]] ; then
MODES="-R"
else
MODES="-f"
fi
if [[ $RAILS_ENV != "" ]] ; then
$RAILS_PAGER $MODES log/$RAILS_ENV.log;
@robdimarco
robdimarco / gist:3437062
Created August 23, 2012 14:18
Simple method to test whether a user agent is a bot or not.
protected
def bot?
# Simple check to match if the user agent is a bot. We look for anything
# that has the pattern bot/ (e.g. Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html))
# or that does not start with Mozilla / Opera (e.g. AdsBot-Google (+http://www.google.com/adsbot.html))
# This could probably be combined in to one regex, but couldn't figure out how to do it quickly.
%r[bot/] =~ request.user_agent || %r{^(?!Mozilla|Opera)} =~ request.user_agent
end
@robdimarco
robdimarco / gist:4007355
Created November 3, 2012 13:12
How Often Will 5 kids randomly drafted to 7 teams wind up on different teams
#!/usr/bin/env ruby
TEAM_COUNT = 7
PLAYERS = 5
ITERATIONS = 1_000_000
PLAYERS_TO_DRAFT = 7
# Players available to draft are numbered 1..Total #
# we are only looking at the first PLAYERS number
AVAILABLE_PLAYERS_ARRAY = (1..TEAM_COUNT * PLAYERS_TO_DRAFT).to_a
@robdimarco
robdimarco / postgis.rb
Created February 22, 2013 22:36
Brew recipe to install postgresql 9.2 and postgis 1.5.8. To run brew install https://gist.github.com/robdimarco/5017114/raw/2e9d55c70ac2ed35d1978eee74780dbb211ecb89/postgis.rb
require 'formula'
def raster?
ARGV.include? '--with-raster'
end
def topology?
ARGV.include? '--with-topology'
end
@robdimarco
robdimarco / httpd-app.conf
Last active November 6, 2016 11:57
Changes to Bitnami Wordpress Multi-Site to work with sub directories.
<Directory "/opt/bitnami/apps/wordpress/htdocs">
Options +MultiViews +FollowSymLinks
AllowOverride None
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
@robdimarco
robdimarco / gist:8400889
Created January 13, 2014 14:10
Nginx configuration to set access control allow origin for fonts
location ~* "^.*?\.(eot)|(ttf)|(woff)$" {
add_header Access-Control-Allow-Origin *;
}
- if @profile.locations.empty?
.info-col.padding-sidegap10
%ul.unstyled
%li No Locations Specified
- elsif @profile.is_dynamic
.info-col
.alert.margin-topgap5.padding-gap10
%p.margin-gap0.dynamic-text
%span.inline-block You have chosen to display a dynamic serving area.
%br
@robdimarco
robdimarco / profile.rb
Created June 20, 2014 14:36
Profile Rails Startup
#! /usr/bin/env ruby -rruby-prof
# Profile the code
RubyProf.start
load "#{ENV['PWD']}/config/environment.rb"
result = RubyProf.stop
# Print a flat profile to text
printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT)
UPDATE call_source_partners
SET affiliate_slug = params->>'affiliate_slug', category_id = (params->>'category_id')::integer;