Skip to content

Instantly share code, notes, and snippets.

@jbgo
jbgo / curl-xml.sh
Created May 24, 2012 14:58
XML API requests with curl
# You can pipe the response to xmllint to format it so you can read it
curl -X POST -d @postdata.xml http://some_url.xml | xmllint --format -
@jbgo
jbgo / statsd-message.sh
Created May 2, 2012 22:20
Send a message to statsd from the command line
echo "foo.bar:1|c" | nc -u localhost 8125
@jbgo
jbgo / stage-deleted.sh
Created April 16, 2012 21:27
git: stage all deleted files
git rm $(git ls-files -d)
@jbgo
jbgo / git-recover-branch.md
Last active May 23, 2024 12:29
How to recover a git branch you accidentally deleted

UPDATE: A better way! (August 2015)

As pointed out by @johntyree in the comments, using git reflog is easier and more reliable. Thanks for the suggestion!

 $ git reflog
1ed7510 HEAD@{1}: checkout: moving from develop to 1ed7510
3970d09 HEAD@{2}: checkout: moving from b-fix-build to develop
1ed7510 HEAD@{3}: commit: got everything working the way I want
70b3696 HEAD@{4}: commit: upgrade rails, do some refactoring
@jbgo
jbgo / vsftpd-ftps.md
Created February 28, 2012 16:02
Configure vsftpd for FTPS

Generate a self-signed SSL certificate.

mkdir -p /etc/vsftpd/
openssl req -new -x509 -nodes -out /etc/vsftpd/vsftpd.pem -keyout /etc/vsftpd/vsftpd.pem

When generating the SSL key, you will be prompted to fill in a variety of fields such as "Country Name" and "Orginization Name". It is important to fill these in, even if you use fake values. In particular, I would get an error when using curl's -k option because I left "Common Name" field blank.

Enable SSL in /etc/vsftpd.conf.

Add these lines to the bottom of the file.

@jbgo
jbgo / commit-msg
Created February 23, 2012 19:16
Git hook to require a PT story# in your commit message
#!/usr/bin/env ruby
unless File.new(ARGV.first).read =~ /\[#\d+/
puts "Commit aborted! Missing reference to Pivotal Tracker story in commit message. (e.g. [#12345])"
exit 1
end
@jbgo
jbgo / unhide.bash
Created February 18, 2012 18:19
Unhide all hidden files in a directory
for x in .[a-z]*; do cp $x ${x:1}; done
@jbgo
jbgo / decorate_module.rb
Created February 8, 2012 23:14
A cleaner way to decorate all methods in a module
module Decorator
def self.decorate(target_klass, include_module, decorator_method)
proxy = Class.new { include include_module }.new
target_klass.class_eval do
include_module.instance_methods.each do |name|
undecorated_method = proxy.method(name)
define_method(name) do |*args, &block|
@jbgo
jbgo / decorate.rb
Created February 7, 2012 19:24
Decorate all methods in a module - don't try this at home
module Foo
def foo
puts bar
return 42
end
def what(a, b)
puts "#{bar} = #{a} + #{b}"
return 42
end
@jbgo
jbgo / .git-completion.bash
Created December 7, 2011 18:28
Bash completion for git branches that (still) sucks
_completion_list() {
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "$*" -- ${cur}) )
}
_complete_git() {
if [ -d .git ]; then
branches=`git branch | cut -c 3-`
tags=`git tag`
_completion_list $branches $tags
fi