Permalink
Browse files

add script to add # encoding to a bunch of ruby files & gn script

  • Loading branch information...
1 parent 28af099 commit 69a52bf6461d3056388668ff72e38d6c286489ab @jeffrydegrande committed Dec 22, 2011
Showing with 41 additions and 0 deletions.
  1. +10 −0 bin/add_encoding_to_ruby_file.sh
  2. +31 −0 bin/gn
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+for f in $*; do
+ TMPFILE=`mktemp /tmp/add_encoding_to_ruby_file.XXXXXX` || exit 1
+
+ echo '#coding: UTF-8' > $TMPFILE
+ cat $f >> $TMPFILE
+
+ mv $TMPFILE $f
+done
View
31 bin/gn
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+
+#
+# Print a diff summary like:
+#
+# $ git diff 'master~10..master' | gn
+# 293 lines of diff
+# 185 lines added
+# 19 lines removed
+# +166 lines net change
+
+import sys, os, re, fileinput
+
+def get_lines(diff_lines):
+ # Added lines start with '+' (but not '+++', because that marks a new
+ # file). The same goes for removed lines, except '-' instead of '+'.
+ added_lines = [line for line in diff_lines
+ if line.startswith('+') and not line.startswith('+++')]
+ removed_lines = [line for line in diff_lines
+ if line.startswith('-') and not line.startswith('---')]
+ return added_lines, removed_lines
+
+
+if __name__ == '__main__':
+ diff_lines = list(fileinput.input())
+ added_lines, removed_lines = get_lines(diff_lines)
+ print '%i lines of diff' % len(diff_lines)
+ print '%i lines added' % len(added_lines)
+ print '%i lines removed' % len(removed_lines)
+ print '%+i lines net change' % (len(added_lines) - len(removed_lines))
+

0 comments on commit 69a52bf

Please sign in to comment.