Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / git-recover-branch.md
Last active March 29, 2024 05:04
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 / stage-deleted.sh
Created April 16, 2012 21:27
git: stage all deleted files
git rm $(git ls-files -d)
@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 / 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 / skip_callbacks.rb
Created June 14, 2012 18:40
Update attributes without callbacks
class SomeModel < ActiveRecord::Base
before_save :some_callback
after_save :some_other_callback
# stuff...
def update_attributes_without_callbacks(attributes={})
self.class.where(id: id).update_all(attributes)
end
@jbgo
jbgo / render-markdown.md
Created June 19, 2012 15:28
Render markdown READMEs on the fly

This is my new favorite thing to do when I want to read a README file written in markdown. This assumes you are macosx and have the redcarpet gem installed.

alias readme='redcarpet README.md > readme.html; open readme.html'
readme
@jbgo
jbgo / postgresql_cheatsheet.md
Created August 24, 2012 15:22
PostgreSQL Cheatsheet

This is still a work in progress. I'm just adding things as I come across them.

Common command line tasks

Create database: createdb db_name

Drop database: dropdb db_name