Skip to content

Instantly share code, notes, and snippets.

@esebastian
esebastian / dump_obj.py
Last active January 1, 2016 16:09
Dump the state of a Python object
'from http://stackoverflow.com/a/192184/1663589
def dump(obj):
for attr in dir(obj):
print "obj.%s = %s" % (attr, getattr(obj, attr))
@esebastian
esebastian / gist:9068949
Created February 18, 2014 11:11
Mount routes from extension in Sinatra
# add requires as needed...
# main app
class App < Sinatra::Base
register Sinatra::Namespace
# mount routes from extension
register Sinatra::Guides
mount_guides
@esebastian
esebastian / dos2unix
Last active August 29, 2015 13:59
Convert DOS CRLF newlines to Unix/Linux LF
find . -type f -print0 | xargs -0 perl -pi -e 's/\r\n/\n/'
@esebastian
esebastian / binary_pending_commit
Created April 14, 2014 07:20
Get the list of not yet committed binary files in a repo
git status -sb | awk '{ print $2 }' | sed -e '1d' | xargs perl -le 'for (@ARGV) { print unless -f && -T }'
@esebastian
esebastian / non_binary_pending_commit
Last active August 29, 2015 13:59
Get the list of not yet committed non binary files in a repo
git status -sb | awk '{ print $2 }' | sed -e '1d' | xargs perl -le 'for (@ARGV) { print if -f && -T }'
@esebastian
esebastian / git-dos2unix
Created June 10, 2014 15:37
Convert DOS CRLF newlines to Unix/Linux LF in all text files in a Git repo
git ls-files | xargs perl -le 'for (@ARGV) { print if -f && -T }' | xargs perl -pi -e 's/\r\n/\n/'
@esebastian
esebastian / git-amend
Last active May 18, 2022 13:14
Amend the commit message of one specific git commit and rebase to apply the changes
#!/bin/sh
# Amend the commit message one specific commit and rebase
# to apply the changes. Given the SHA hash or a reference
# of the commit to amend, it checkouts the commit, amends
# it interactively and rebases the repo history in master.
#
# This action is destructive to your repo's history and this
# should not be performed on a repo that has been shared with
# others, because it will force them to reset their history.
#
@esebastian
esebastian / git-author
Created July 5, 2014 18:04
Rewrite git history replacing both author and commiter data for a given matching email
#!/bin/sh
# Git script to rewrite history replacing both author and commiter data for a given matching email,
# based upon this nice gist: https://help.github.com/articles/changing-author-info
# As the original source states, this action is destructive to your repo's history.
# It's best to do this on a clone, just in case. Also beware that this should not be performed on
# a repo that has been shared with others without forcing them to reset their history.
#
# Use at your own risk.
#
@esebastian
esebastian / git-unvoid-messages
Created July 5, 2014 18:08
Apply messages from provided input file to git commits with empty messages
#!/bin/sh
# Apply messages from provided input file to commits with empty messages
# The messages are applied in inverse order (first line in the file applied to older commit with void message)
# and only up to the number of commits with empty messages.
#
# This action is destructive to your repo's history. It's best to do this on a clone,
# just in case. Also beware that this should not be performed on a repo that has been
# shared with others without forcing them to reset their history.
#
# Use at your own risk.
@esebastian
esebastian / git-fix-dates
Created July 5, 2014 18:15
Reset the commit dates to their corresponding author dates
#!/bin/sh
# Reset the commit dates to their corresponding author dates, in the current
# branch. Usually useful to preserve the original timestamps after a rebase.
#
# This action is destructive to your repo's history and this should not
# be performed on a repo that has been shared with others, because it
# will force them to reset their history.
#
# Use at your own risk.
#