Skip to content

Instantly share code, notes, and snippets.

Avatar

Amit Upadhyay amitu

View GitHub Profile
View Evolution of a Python programmer.py
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
View gist:2012204
<script src="http://cdn.gethammer.co/hammerlib.min.js"></script>
@amitu
amitu / gist:2022131
Created Mar 12, 2012
get username of the process that opened a connection, works only for case when both client and server are on same machine
View gist:2022131
import socket
import time
import commands
soc = socket.socket()
soc.bind(('0.0.0.0', 9996))
soc.listen(5)
while True:
client, address = soc.accept()
@amitu
amitu / demo.html
Created Mar 15, 2012
PingPong HTTP Callbacks base Hammer Application (python using web.py)
View demo.html
<script src="/static/hammerlib.min.js"></script>
<script>
$.fn.on_enter = function (callback) {
var ENTER_KEY = 13;
return this.keypress(function (e){
var key = e.charCode || e.keyCode || 0;
if (key != ENTER_KEY) return;
var value = $(this).val();
if (value === "") return false;
@amitu
amitu / demo.html
Created Mar 15, 2012
Stock Updater Hammer Application
View demo.html
<script src="/static/hammerlib.min.js"></script>
<script>
$(function(){
hammerlib.bind("hammerlib", "opened", function(data) {
hammerlib.subscribe("stock_ticker");
});
hammerlib.bind("stock_ticker", "updated", function(data) {
$.each(["hammer", "gamma", "spacemonkey", "unicorn"], function(i, stock) {
var key = stock + "_ticker";
@amitu
amitu / send.d
Created Mar 20, 2012
dtrace script to monitor all network send activity
View send.d
tcp:::send
/args[1]->dport == 80/
{
printf(
"Packet sent: %s:%u -> %s:%u on behalf of %s (PID: %d, UID: %d)\n",
args[1]->ip_saddr, args[1]->sport, args[1]->ip_daddr,
args[1]->dport, execname, pid, uid);
}
@amitu
amitu / t.m
Created Mar 21, 2012
changing mac input source (language)
View t.m
#import <Foundation/Foundation.h>
#import <Carbon/Carbon.h>
/*###############################################################################
# #
# changeInput #
# #
# author: Stefan Klieme (based on an idea by Craig Williams) #
# created: 2009-11-05 #
# Changes input language #
# Usage: changeInput prints current input language #
@amitu
amitu / force_language.akh
Created Mar 21, 2012
autohotkey script to force language to any given language for all apps
View force_language.akh
en := DllCall("LoadKeyboardLayout", "Str", "00000409", "Int", 1)
Loop
{
#IfWinActive
{
w := DllCall("GetForegroundWindow")
pid := DllCall("GetWindowThreadProcessId", "UInt", w, "Ptr", 0)
l := DllCall("GetKeyboardLayout", "UInt", pid)
@amitu
amitu / dtrace.js
Created Mar 29, 2012
dtrace based blocking http api to map local port to uid
View dtrace.js
var http = require('http');
var spawn = require('child_process').spawn;
var dtrace = spawn("dtrace", ["-s", "dtrace.d", "-C"]);
var known_ports = {};
var pending_requests = {};
dtrace.stdout.on("data", function(data){
var lines = data.toString().split("\n");
for (i in lines) {
@amitu
amitu / gist:3235949
Created Aug 2, 2012
django based mini framework, proposal 1
View gist:3235949
from amitu import d
# key advantages:
# 1. single file app
# 2. still fully compatible with existing django projects
# 3. auto matic url regex creation
# 4. all frequently used django functions/classes collected in d.* namespace
# Note: not yet sure if all of this is possible :-p
d( # callable modules are magic. some magic is good.
You can’t perform that action at this time.