Skip to content

Instantly share code, notes, and snippets.

View airblade's full-sized avatar

Andy Stewart airblade

View GitHub Profile
@chriseppstein
chriseppstein / rbenv-each.sh
Created October 12, 2011 15:49
Execute the same command in each installed ruby via rbenv
#!/bin/bash
verbose=0
function usage() {
echo >&2 "Usage: rbenv each [-v] ..."
echo >&2 " -v Verbose mode. Prints a header for each ruby."
}
while getopts vh option
do case "$option" in
#!/usr/bin/env bash
# Reads lines from stdin in the format `VAR=value` and escapes
# them for the shell, prepending each line with `export`.
# Parameter substitution is allowed in `value` with `$VAR` and
# `${VAR}` syntax. You can escape `$` and `\` with a backslash.
sed \
-e "/^[ "$'\t'"]*[A-Za-z_][0-9A-Za-z_]*=/ !d" \
-e "s/'/'\\\\''/g" \
@drewreece
drewreece / hosts-to-vm.sh
Last active June 26, 2018 16:32
Import locally defined hosts into Windows VM hosts file
#!/bin/sh
# hosts-to-vm.sh
#
# Made for use alongside the excellent ievms -
# https://github.com/xdissent/ievms
#
# Will export the local hosts (from /etc/hosts)
# to a batch script & add that batch script to a Windows VM
# The batch script will be executed to import the hosts onto the VM
# The batch file seems convoluted, until you only want to append the new hosts.
@stephencelis
stephencelis / redcarpet.rb
Created August 29, 2011 05:54
Redcarpet (Markdown) template handler for Rails 3.1.
# config/initializers/redcarpet.rb
class ActionView::Template
class Redcarpet < Handler
include Handlers::Compilable
def compile template
::Redcarpet.new(template.source).to_html.inspect
end
end
task :cron => :environment do
DatabaseBackup.back_up_to_s3!
end
@mislav
mislav / cmd.rb
Created August 5, 2011 12:10
Execute a command, return its output, error stream and exit status
# returns [output string, err string, exit code]
def cmd(args, input = nil)
parent_read, child_write = IO.pipe
err_read, err_write = IO.pipe
child_read, parent_write = IO.pipe if input
pid = fork do
if input
parent_write.close
$stdin.reopen(child_read)
@topfunky
topfunky / new-github.sh
Created July 25, 2011 22:23
Shell shortcut to setup a Git repo with GitHub. Works with zsh or bash.
# Usage: new-github topfunky tidy_table
function new-github() {
git remote add origin [email protected]:$1/$2.git
git push origin master
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
git config push.default current
}
@indirect
indirect / better_logger.rb
Created July 19, 2011 07:00
Rails 3 logs with severity and PIDs
# You must require this file in application.rb, above the Application
# definition, for this to work. For example:
#
# # Syslog-like Rails logs
# if Rails.env.production?
# require File.expand_path('../../lib/better_logger', __FILE__)
# end
#
# module MyApp
# class Application < Rails::Application
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@namxam
namxam / gist:970361
Created May 13, 2011 11:11
typhoeus example
require 'rubygems'
require 'typhoeus'
hydra = Typhoeus::Hydra.new
# Create all your requests
request = Typhoeus::Request.new("http://your_image_url")
request.on_complete do |response|
# Check if the returned data really is an image