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 / 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 / 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 / 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 / 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 / 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):
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 / debug.conf
Created September 10, 2013 22:21
Dummy plugin for logstash.
input {
stdin {
type => "foo"
}
}
filter {
if [type] == "foo" {
foo {
message => "Hello world!"
}
@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 / views.py
Created September 15, 2013 17:28
djangothis with labels
from importd import d
from path import path
from datetime import datetime
from djangothis.app import dotslash, read_yaml, watchfile
from django.shortcuts import render
posts = None
labels = {}
@amitu
amitu / load_keen.py
Last active December 24, 2015 07:49
Upload some test data to keen.io
# find the list of backup files
# for each file see the position till where we have read the file from "stack"
# for each file see if there is more in it.
# if there is more, start reading and writing to keen
# find total size of all files
# go thru in ls -t order so we always traverse them in same order
from progressbar import ProgressBar
import keen, pdb, json, time