Skip to content

Instantly share code, notes, and snippets.

Avatar

Amit Upadhyay amitu

View GitHub Profile
@amitu
amitu / api.py
Last active Apr 10, 2018
Acko's api framework
View api.py
# -*- coding: utf-8 -*-
# License: BSD
import json
import os
import re
import time
from django import forms
from django.conf import settings
@amitu
amitu / gist:4633274
Created Jan 25, 2013
zsh preexec hook example
View gist:4633274
# less -F: Causes less to automatically exit if the entire file can be displayed on the first screen.
# .zshrc
function printc () {
print "printc" $1
}
autoload -Uz add-zsh-hook
@amitu
amitu / rails_tz.py
Created Nov 4, 2013
Python dictionary that maps rails specific timezones to standard timezones. http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html. Twitter returns timezones in this format.
View rails_tz.py
{
"Abu Dhabi": "Asia/Muscat",
"Adelaide": "Australia/Adelaide",
"Alaska": "America/Juneau",
"Almaty": "Asia/Almaty",
"American Samoa": "Pacific/Pago_Pago",
"Amsterdam": "Europe/Amsterdam",
"Arizona": "America/Phoenix",
"Astana": "Asia/Dhaka",
"Athens": "Europe/Athens",
@amitu
amitu / or.elm
Last active Jun 20, 2017
Elm Enhancement Proposal: Or (More of a thought experiment)
View or.elm
-- What if we have had an or keyword for creating types.
--
-- Motivation: I often have something that is of few other things.
--
-- Example 1 from my code:
-- this is my Main Msg. Main does not have any UI, it is an SPA, it delegates different
-- pages / Modules for UI and updated etc.
type Msg
View gist:fe548a624136a8be1031c0417062114e
### Keybase proof
I hereby claim:
* I am amitu on github.
* I am amitu (https://keybase.io/amitu) on keybase.
* I have a public key whose fingerprint is 0AE6 B0E1 9D24 7DD8 4DD0 2BB2 1514 4294 2930 5B79
To claim this, I am signing this object:
@amitu
amitu / com.amitu.waitforit.plist
Created Jun 10, 2016
waitforit launch agent plist for mac
View com.amitu.waitforit.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.amitu.waitforit</string>
<key>ProgramArguments</key>
<array>
@amitu
amitu / hindic-top1000.txt
Last active May 21, 2016
https://github.com/amitu/scriptic/blob/master/cmu.py generated transliteration for 1000 most frequently used words in english
View hindic-top1000.txt
you: Y UW1 => यू
I: AY1 => आय
to: T UW1 => टू
the: DH AH0 => दै
a: AH0 => ऐ
and: AH0 N D => ऐन्ड
that: DH AE1 T => दैट
it: IH1 T => इट
of: AH1 V => आव
me: M IY1 => मी
@amitu
amitu / encoded_key.py
Last active Apr 29, 2016
Django Model base class for encoded key. Useful for when you want to pass id in URL or JSON, but do not leak data to world (about how many objects you have of that kind).
View encoded_key.py
from Crypto.Cipher import AES
from Crypto import Random
import base64
import binascii
import struct
from django.db import models
from django.conf import settings
@amitu
amitu / Makefile
Created Apr 12, 2016
Self documenting makefile
View Makefile
.DEFAULT_GOAL := help
node_modules: ## Install dependencies.
node_modules: package.json
npm install
help: ## Show this help.
@IFS=$$'\n' ; \
help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##/:/'`); \
for help_line in $${help_lines[@]}; do \
@amitu
amitu / .zshrc
Last active Mar 17, 2016
ZSH: Print time to execute each command as it is executed.
View .zshrc
preexec () {
START="$(python -c 'import time; print time.time()')"
LAST_CMD=$1
}
precmd () {
LAST=$?
if [ -z ${START} ];
then
else