Skip to content

Instantly share code, notes, and snippets.

@codingfoo
codingfoo / deploy.rb
Created March 11, 2014 20:15
Rails 4 Capistrano 2 local assets precompile
namespace :deploy do
namespace :assets do
desc 'Run the precompile task locally and rsync with shared'
task :precompile, :roles => :app, :except => { :no_release => true } do
system("bundle check"); exit if $? != 0
system("RAILS_ENV=#{stage} bundle exec rake assets:precompile"); exit if $? != 0
servers = find_servers :roles => :web, :except => { :no_release => true }
run <<-CMD.compact
cp -- #{shared_manifest_path.shellescape} #{current_path.to_s.shellescape}/assets_manifest#{File.extname(shared_manifest_path)}
CMD
@codingfoo
codingfoo / sublime.json
Created May 7, 2014 23:08
Sublime Config
{
"auto_complete_commit_on_tab": true,
"binary_file_patterns":
[
"*.jpg",
"*.jpeg",
"*.png",
"*.gif",
"*.ttf",
"*.tga",
@codingfoo
codingfoo / iron-worker-deploy.sh
Last active August 29, 2015 14:05
Script for deploying iron.io workers
#!/usr/bin/env sh
set -o nounset
set -o errexit
set -o pipefail
shopt -s nullglob
declare -a environments=("production" "staging" "development")
declare -a workers=(*.worker)
@codingfoo
codingfoo / monit-test
Last active August 29, 2015 14:19
Monit smoke test
check file alerttest with path /.nonexistent
if does not exist then alert
@codingfoo
codingfoo / load_secrets.rb
Last active October 7, 2015 00:07
Load a secrets file
require 'ostruct'
require 'yaml'
::Secrets = OpenStruct.new(YAML.load_file(File.expand_path('../secrets.yml', __FILE__))[Rails.env])
@codingfoo
codingfoo / url_exists.rb
Created July 14, 2012 22:54
Check if remote url exists
def remote_url_exists?(url)
begin
url = URI.parse(url)
Net::HTTP.start(url.host, url.port) do |http|
return http.head(url.request_uri).code == "200"
end
rescue
false
end
end
@codingfoo
codingfoo / README
Last active December 8, 2015 16:31
Bash script template
To perform a syntax check/dry run of your bash script run:
bash -n myscript.sh
To produce a trace of every command executed run:
bash -v myscripts.sh
To produce a trace of the expanded command use:
@codingfoo
codingfoo / javascript_parse_benchmark.rb
Last active December 11, 2015 20:59
Javascript parsing benchmark
script = open(ARGV[0]).read
require "benchmark"
include Benchmark
require 'rkelly'
require 'parsejs'
require 'violet'
require 'content_urls'
@codingfoo
codingfoo / sax_vs_dom.rb
Last active December 11, 2015 20:59
Benchmark sax vs dom parsing for nokogiri
require 'nokogiri'
class MyDoc < Nokogiri::XML::SAX::Document
attr_reader :result
def initialize
@result = ""
end
def xmldecl version, encoding, standalone
@codingfoo
codingfoo / README
Last active December 17, 2015 16:39
Basic iptables config
https://help.ubuntu.com/community/IptablesHowTo
Place the scripts in
/etc/network/if-pre-up.d and /etc/network/if-post-down.d