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 / api.py
Last active April 10, 2018 21:14
Acko's api framework
# -*- coding: utf-8 -*-
# License: BSD
import json
import os
import re
import time
from django import forms
from django.conf import settings
@amitu
amitu / or.elm
Last active June 20, 2017 05:37
Elm Enhancement Proposal: Or (More of a thought experiment)
-- 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
### 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 / soa.py
Created August 16, 2016 11:30
service oriented architecture for django: pseudo code
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
class Settings(object):
def __init__(self):
self.settings = dict(
@amitu
amitu / com.amitu.waitforit.plist
Created June 10, 2016 09:32
waitforit launch agent plist for mac
<?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 / encoded_key.py
Last active April 29, 2016 11:00
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).
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 April 12, 2016 07:49
Self documenting 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 March 17, 2016 11:07
ZSH: Print time to execute each command as it is executed.
preexec () {
START="$(python -c 'import time; print time.time()')"
LAST_CMD=$1
}
precmd () {
LAST=$?
if [ -z ${START} ];
then
else
@amitu
amitu / CICharField.py
Created March 5, 2016 18:06
CICharField
class CICharField(models.CharField):
def db_type(self, connection):
assert connection
return 'CITEXT'
def from_db_value(self, value, expression, connection, context):
if value and isinstance(value, str):
value = value.decode("utf-8")
return value
@amitu
amitu / clone_schema.sql
Created February 7, 2016 09:35
clone schema
-- Function: clone_schema(text, text)
-- DROP FUNCTION clone_schema(text, text);
CREATE OR REPLACE FUNCTION clone_schema(
source_schema text,
dest_schema text,
include_recs boolean)
RETURNS void AS
$BODY$