Skip to content

Instantly share code, notes, and snippets.

View phil-monroe's full-sized avatar

Phil Monroe phil-monroe

View GitHub Profile
@phil-monroe
phil-monroe / install.sh
Last active May 10, 2019 15:02
Parallel, Multiple File Remote File Copy. Fills up network bandwidth while copying many files
#!/bin/bash
mkdir -p ~/bin/
curl -s -L https://gist.github.com/raw/4477190/pmrcp.rb > ~/bin/pmrcp
chmod +x ~/bin/pmrcp
@phil-monroe
phil-monroe / haproxy
Created January 11, 2013 01:47
HAProxy init.d script.
#!/usr/bin/env bash
# haproxyd
# Script to start|stop|restart haproxy from /etc/init.d/
# By Phil Monroe.
HAPROXY_PATH=/usr/sbin
HAPROXY_DAEMON=$HAPROXY_PATH/haproxy
HAPROXY_CONFIG=/etc/haproxy/haproxy.cfg
test -x $HAPROXY_DAEMON || exit 0
@phil-monroe
phil-monroe / tools.md
Last active December 11, 2015 07:28
Tools that I find useful and use everyday.

Development Tools

Productivity Tools

Asana

By far the best ToDo list I have ever used.

  • asana.com
  • Asana.app - Fluid app to make the Asana web interface seem like a native OS X App.
@phil-monroe
phil-monroe / permissions.sql
Created January 30, 2013 00:05
Gist to test postgres permissions so multiple apps can connect and use the same DB in a namespaced way
--- cleanup
drop database test;
drop user piston;
drop user crankshaft;
drop user identified;
--- setup
create database test;
\c test
@phil-monroe
phil-monroe / rufus.rb
Last active December 12, 2015 02:58
Embedding rufus scheduler within sidekiq. Put this file into your rails `config/initializers` folder.
require 'rufus/scheduler'
require 'redis'
require 'redis-lock'
if $0 == 'sidekiq'
$redis = Redis.new
def run_rake task
$redis.lock_for_update(task, 100, 0) do
puts "scheduling #{task}"
@phil-monroe
phil-monroe / ruby-install.sh
Created February 20, 2013 19:28
Things I did to install Ruby 1.9.3 on OS X Mountain Lion (10.8)
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zprofile
echo 'eval "$(rbenv init -)"' >> ~/.zprofile
exec $SHELL -l
brew install readline openssl
@phil-monroe
phil-monroe / normalize.rb
Created April 25, 2013 18:03
Normalize a query from to just lowercase letters and single spaces
def query
@query ||= params[:query].to_s.tap do |q|
q.strip!
q.downcase!
q.gsub!(/[^a-z\s]/, '')
q.gsub!(/\s+/, ' ')
end
end
@phil-monroe
phil-monroe / recompile_gems.sh
Created April 30, 2013 21:35
Recompiles all gems that have native extensions
#!/bin/bash
bundle exec ruby -e <<RUBY
require 'rubygems/commands/uninstall_command'
require 'bundler/cli'
Gem.loaded_specs.select{|k,v| !v.extensions.empty?}.keys.map do |gem|
Gem::Commands::UninstallCommand.new
.handle_options ['-x', '-I', gem]
.execute rescue nil
@phil-monroe
phil-monroe / pg_top.rb
Created June 18, 2013 18:58
Simple ruby script to view Postgres stats
require 'yaml'
require 'terminal-table'
loop do
# Get Running Processes
rows = %w(pid client_addr state waiting query_start query)
stats = `psql identified_production -t -c 'select #{rows.join(', ')} from pg_stat_activity order by state DESC'`
stats = stats.split("\n")
stats.map! { |s| s.split('|').map(&:strip) }
@phil-monroe
phil-monroe / 01-Faye Rails.md
Last active March 14, 2016 12:35
Embed scalable Faye into Rails app hosted with Puma, Thin, etc.

This is just a jotting of notes on how to embed Faye into a single Rails process. Makes it nice to do simple real time things without the need for a separate Faye server/process.

Also uses Faye Redis to work across load balanced Rails apps.

You also need to copy the compiled javascript into vendor/assets/javascripts and include into application.js manifest.

Ignore the numbers in the file names... just used to add order to the Gist.

This uses the faye/faye Github repo at edc5b42f6560d31eae61caf00f6765a90e1818d1 since I wanted to use with the Puma rack server and that is only available in the master branch (until Faye 1.0)