Skip to content

Instantly share code, notes, and snippets.

View amitu's full-sized avatar
😀
Building fastn.com

Amit Upadhyay amitu

😀
Building fastn.com
View GitHub Profile
@amitu
amitu / jdk7.sls
Created September 11, 2013 20:10
installing jdk7 via salt
java7_ppa:
cmd.run:
- name: add-apt-repository ppa:webupd8team/java --yes && apt-get update
- user: root
accept-license:
cmd.run:
- name: echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
- unless: debconf-get-selections | grep -q shared/accepted-oracle-license-v1-1
- user: root
@amitu
amitu / debug.conf
Created September 10, 2013 22:21
Dummy plugin for logstash.
input {
stdin {
type => "foo"
}
}
filter {
if [type] == "foo" {
foo {
message => "Hello world!"
}
with table_stats as (
select psut.relname,
psut.n_live_tup,
1.0 * psut.idx_scan / greatest(1, psut.seq_scan + psut.idx_scan) as index_use_ratio
from pg_stat_user_tables psut
order by psut.n_live_tup desc
),
table_io as (
select psiut.relname,
sum(psiut.heap_blks_read) as table_page_read,
@amitu
amitu / luigi_example.py
Created October 14, 2015 13:18
Luigi Example
import luigi
class SimpleTask(luigi.Task):
name = luigi.Parameter()
def output(self):
return luigi.LocalTarget(self.name)
def run(self):
@amitu
amitu / gist:3235949
Created August 2, 2012 09:45
django based mini framework, proposal 1
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.
@amitu
amitu / dtrace.js
Created March 29, 2012 11:22
dtrace based blocking http api to map local port to uid
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 / force_language.akh
Created March 21, 2012 15:12
autohotkey script to force language to any given language for all apps
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 / demo.html
Created March 15, 2012 06:40
Stock Updater Hammer Application
<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 / demo.html
Created March 15, 2012 06:35
PingPong HTTP Callbacks base Hammer Application (python using web.py)
<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 / gist:2022131
Created March 12, 2012 14:04
get username of the process that opened a connection, works only for case when both client and server are on same machine
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()