Skip to content

Instantly share code, notes, and snippets.

View talwai's full-sized avatar

Aaditya Talwai talwai

View GitHub Profile
@talwai
talwai / gist:d1eb281ea53b8f087300
Created January 26, 2015 02:16
Use Brace expansion in Bash to move files within the same folder
mv blob/a_long_directory_name/{c/x.x,evenmore/y.y} # Moves blob/a_long_directory_name/c/x.x to blob/a_long_directory_name/evenmore/y.y
# Source: http://unix.stackexchange.com/questions/89555/cp-or-mv-files-to-same-directory-they-are-already-in-when-i-am-in-another
@talwai
talwai / servefile.sh
Created January 23, 2015 19:57
One-shot HTTP webserver to serve file contents using netcat
{ echo -ne "HTTP/1.0 200 OK\r\nContent-Length: $(wc -c <some.file)\r\n\r\n"; cat some.file; } | nc -l 8080
def ten_most_prolific(rows):
# Who are the top 10 most prolific artists in the data
# along with the number of their songs that appear in the data?
artists = [row['ARTIST CLEAN'] for row in rows]
c = Counter(artists)
sorted_c = sorted(c.items(), key=operator.itemgetter(1), reverse=True)
return sorted_c[:10]
@talwai
talwai / gist:68bdceccdd97c4c4916f
Created January 14, 2015 00:28
Python 2.7 Leaking scope in list comprehensions
# This leaks in Python 2.7 but does not in Python 3+
def bad_scope_list():
num = range(1,10)
i = 4
print [i for i in num]
print i # Prints 9 instead of 4
@talwai
talwai / list_venvs.sh
Created July 28, 2014 03:36
List Python versions and packages installed in all virtualenvs under a directory
#!/usr/bin/env bash
: <<'END'
Sample Run: ./list_venvs.sh /Users/talwai/
Sample Output:
-----------------------
DIRECTORY: /Users/talwai/qorpus_env
PYTHON_VERSION: 3.3.2
PACKAGES: