Skip to content

Instantly share code, notes, and snippets.

View gregawoods's full-sized avatar

Greg Woods gregawoods

  • Mozilla
  • Indianapolis, IN
View GitHub Profile
@gregawoods
gregawoods / byword
Created July 28, 2011 04:07
Open a file in Byword
#!/bin/bash
touch $1
open -a /Applications/Byword.app $1
@gregawoods
gregawoods / handbrake.bat
Last active September 26, 2015 17:08
Encode the contents of a directory using Handbrake while wishing my media server was a Mac
:: Handbrake.bat
:: A batch script for losers
:: Set handbrake_exec to the location where your handbrake is installed
:: Set handbrake_preset to the desired preset (https://trac.handbrake.fr/wiki/BuiltInPresets)
:: Set source_dir to the folder containing the videos you wish to encode
:: Set output_dir to the destination where encoded videos should be saved
set handbrake_exec="C:\Program Files\Handbrake\HandBrakeCLI.exe"
set handbrake_preset="AppleTV 3"
@gregawoods
gregawoods / split_to_explode.sh
Created September 23, 2011 13:59
Search a directory for PHP files and replace instances of split() with explode()
for file in $(egrep --include=*.php -rl "([^a-zA-Z_]+)split\(" .)
do
# you might replace 'preg_split' with 'explode' if you don't require regex support
sed -E "s/([^a-zA-Z_]+)split\(/\1preg_split\(/g" $file > /tmp/tempfile.tmp
mv /tmp/tempfile.tmp $file
done
@gregawoods
gregawoods / ruby_passive_ftp.rb
Created January 24, 2013 14:43
FTP servers are supposed to respond to a PASV command by sending their respective passive port and IP address. Sometimes a misconfigured server that resides behind a NAT will respond with its private IP rather than a public one, which means your passive connection will fail. This little hack saved the day for me.
class IPAddr
def is_private?
return between?('172.16.0.0','172.31.255.255') || between?('10.0.0.0','10.255.255.255') || between?('192.168.0.0','192.168.255.255')
end
end
class Net::FTP
alias_method :parse227_original, :parse227
alias_method :connect_original, :connect
def connect(host, port = FTP_PORT)
@gregawoods
gregawoods / install-ruby-2-osx.sh
Created February 24, 2013 17:44
Getting started with Ruby 2.0 on OS X.
# openssl (homebrew)
brew update
brew install openssl
# ruby 2.0
curl -O ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.bz2
tar -xvf ruby-2.0.0-p0.tar.bz2
cd ruby-2.0.0-p0
./configure --with-opt-dir=`brew --prefix openssl`
make
@gregawoods
gregawoods / fizz_buzz_refinement.rb
Created February 24, 2013 18:10
Applying the experimental Ruby 2.0 Refinements feature to the classic FizzBuzz challenge. (http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html)
module FizzBuzz
refine Fixnum do
def to_s
if self % 3 == 0 && self % 5 == 0
"FizzBuzz"
elsif self % 3 == 0
"Fizz"
elsif self % 5 == 0
"Buzz"
else
@gregawoods
gregawoods / ksdiffdir.rb
Last active October 25, 2021 14:44
Show the diff between two folders in Kaleidoscope for OS X. While you can do this out of the box with the `ksdiff` command line tool it does not dive into subdirectories like I wanted. Usage: ksdiffdir.rb path/to/a path/to/b
#!/usr/bin/env ruby
# Usage:
# ksdiffdir.rb /path/to/a /path/to/b
FOLDER_A = ARGV[0]
FOLDER_B = ARGV[1]
def build_file_list(dir_path)
Dir.glob("#{dir_path}/**/*").select{ |f| File.file?(f) }.collect{ |f| f.gsub("#{dir_path}", '') }
@gregawoods
gregawoods / PaddedNumber.js
Created July 11, 2013 18:04
ExtJS number field that allows for zero padding. Useful for displaying hours/minutes selectors.
Ext.define('p7_ui_static.view.field.PaddedNumber', {
extend: 'Ext.form.field.Number',
alias: 'widget.paddednumberfield',
/**
* @cfg {Number} zeroPadding
* Number of digits to pad
* Defaults to 2
*/
zeroPadding: 2,
@gregawoods
gregawoods / opengem.sh
Created September 17, 2013 14:56
Place in your .bash_profile for easy gem source code viewing!
# open a gem in sublime text
opengem(){
gempath=`gem which $1`
if [ ! -z $gempath ]; then
slt "$gempath/../.."
fi
}
@gregawoods
gregawoods / delete_ruby_gem_logs.sh
Created October 9, 2013 14:13
Slightly ashamed to admit that this cleared up an entire gig of space on my drive. Criminy.
cd ~/.rvm
rm `find . -type f -name test.log`
rm `find . -type f -name development.log`