Skip to content

Instantly share code, notes, and snippets.

View talwai's full-sized avatar

Aaditya Talwai talwai

View GitHub Profile
@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:
@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
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 / 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
@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 / docker_env.sh
Created February 9, 2015 05:28
Export Docker envars immediately after boot2docker up
boot2docker up && env | grep DOCKER | sed 's/^/export /' > docker.conf && . docker.conf
@talwai
talwai / profile.dmp
Created May 18, 2015 20:58
Example output of profiling the network check in dd-agent
(venv)Aadityas-MacBook-Pro:dd-agent aadityatalwai$ python agent.py check network --profile
2015-05-18 16:56:36,856 | INFO | dd.collector | config(config.py:922) | initialized checks.d checks: ['ntp', 'consul', 'network']
2015-05-18 16:56:36,856 | INFO | dd.collector | config(config.py:923) | initialization failed checks.d checks: []
2015-05-18 16:56:36,856 | INFO | dd.collector | checks.collector(collector.py:443) | Running check network
2015-05-18 16:56:36,873 | INFO | dd.collector | checks(__init__.py:654) |
network
Memory Before (RSS): 18206720
Memory After (RSS): 18243584
Difference (RSS): 36864
Memory Before (VMS): 2534727680
@talwai
talwai / statsd_send.sh
Created November 23, 2015 01:33
Send Metric to Containerized StatsD on Mac OS X via docker-machine
# Mac OS X
echo "aaditya.test.metric:100|g" | nc -u -w0 $(docker-machine ip default) 8125
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --new-window "https://app.datadoghq.com/account/settings" \
"https://app.datadoghq.com/infrastructure/map?fillby=avg%3Acpuutilization&sizeby=avg%3Anometric&groupby=availability-zone&nameby=aws_name&nometrichosts=false&tvMode=false&nogrouphosts=false&palette=hostmap_blues&paletteflip=false"\
"https://app.datadoghq.com/dash/71811/demo---cassandra?live=true&page=0&is_auto=false&from_ts=1453149091364&to_ts=1453235491364&tile_size=m"\
"https://app.datadoghq.com/monitors#/create" "https://app.datadoghq.com/monitors#183575?group=all&live=4h"\
"https://app.datadoghq.com/event/stream?tags_execution=and&show_private=true&per_page=30&aggregate_up=true&use_date_happened=false&display_timeline=true&from_ts=1452632400000&is_zoomed=false&to_ts=1453237200000&is_auto=false&incident=true&only_discussed=false&no_user=false&page=0&live=true&bucket_size=10800000"\
"https://www.datadoghq.com/customers/"\
"https://github.com/DataDog/dd-agent"\
--- /opt/datadog-agent/agent/checks.d/openstack.py 2016-02-01 11:12:37.000000000 -0500
+++ /opt/datadog-agent/agent/checks.d/openstack_patch.py 2016-02-03 14:49:22.000000000 -0500
@@ -281,7 +281,7 @@
nova_version = nova_api_version or DEFAULT_NOVA_API_VERSION
catalog = json_resp.get('token', {}).get('catalog', [])
- nova_match = 'novav21' if nova_version == 'v2.1' else 'nova'
+ nova_match = 'nova'
for entry in catalog: