Skip to content

Instantly share code, notes, and snippets.

@gmanley
gmanley / gist:3710063
Created September 12, 2012 21:29
Dtrace msyql
sudo dtrace -qn 'pid$target:mysqld:*mysql_parse*:entry { printf("%Y %s\n", walltimestamp, copyinstr(arg1)) }' -p `pgrep -x mysqld`
@gmanley
gmanley / gist:3555759
Created August 31, 2012 16:51
Date Regex
date = '03/27/1992'
year = /(?<year>(20)?(07|08|09|10|11|12))/
month = /(?<month>0[1-9]|1[012])/
day = /(?<day>0[1-9]|\.[1-9]|[12][0-9]|3[01])/
NUMERAL_DATE_REGEX = /#{year}(?<separator>\.|\-|\/|_)?#{month}(\k<separator>)?#{day}/
if match = NUMERAL_DATE_REGEX.match(@file_name)
Date.parse(date).strftime("%y.%m.%d")
end
require 'bundler/setup'
Bundler.require
module Soshified
def self.setup!
config = YAML.load_file(File.join(File.dirname(__FILE__), 'config/db.yml'))
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, config['ipgallery'])
end
@gmanley
gmanley / gist:2490296
Created April 25, 2012 14:48
Make rvmrc function!
function mkrvmrc () {
latest_ruby="$(rvm list strings | tail -n -1)"
echo "rvm $latest_ruby@$(basename $PWD) --create" > .rvmrc
source .rvmrc
}
@gmanley
gmanley / gist:2469307
Created April 23, 2012 07:11
Regexp MatchData to_hash monkey patch
class MatchData
def to_hash
Hash[[names, captures].transpose]
end
alias :to_h :to_hash
end
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
rm -f ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
brew uninstall memcached
brew install https://raw.github.com/gist/2421766/1a210dbd360486631ff4fb22fd74a0eed5983d91/memcached.rb
cp /usr/local/Cellar/memcached/1.4.13/homebrew.mxcl.memcached.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
tail -f /usr/local/var/log/memcached.log
#(^|\s|\)|\(|\{|\}|>|\]|\[|href=\S)((http|https|news|ftp)://(?:[^<>\)\[\"\s]+|[a-zA-Z0-9/\._\-!&\#;,%\+\?:=]+))(</a>)?#
#(^|\s|\)|\(|\{|\}|>|\]|\[|href=\S)(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))(</a>)?#
@gmanley
gmanley / imgur_dl.rb
Created February 19, 2012 23:09
Concurrent imgur album downloader using typhoeus.
# encoding: UTF-8
# requires ruby 1.9.3 and up
# gem install nokogiri typhoeus
require 'nokogiri'
require 'typhoeus'
module Imgur
class AlbumDownloader
@gmanley
gmanley / vim_notes.txt
Created February 19, 2012 08:28
VIM Notes
# Various notes relating to my switch vim
ctrl-o in insert mode to switches you to normal mode for one command
then back to insert mode.
Key Movement
h Left
l Right
k Up a line
@gmanley
gmanley / gist:1732830
Created February 3, 2012 21:38
Quick example of how to use backbone-rails
rvm use 1.9.3@rails_backbone_example --create
gem install rails
rails new rails_backbone_test --skip-bundle
cd rails_backbone_test
Add `gem 'rails-backbone'` to Gemfile
bundle
rails g backbone:install
rails g scaffold Post title:string content:string
rails g backbone:scaffold Post title:string content:string
rake db:migrate