Skip to content

Instantly share code, notes, and snippets.

@alixedi
alixedi / LilLambda.ipynb
Created July 13, 2017 08:52 — forked from vakila/LilLambda.ipynb
Anjana Vakil, "Mary had a little lambda", EuroPython 2017: https://ep2017.europython.eu/conference/talks/mary-had-a-little-lambda
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alixedi
alixedi / default_ami_setup.sh
Created January 6, 2017 10:18 — forked from darron/default_ami_setup.sh
Ubuntu 14.04 AWS Instance Store HVM build - actually worked - built and booted. Much thanks to: https://github.com/Lumida/packer/wiki/Building-Ubuntu-12.04-and-14.04-HVM-Instance-Store-AMIs
#!/bin/bash
# server-jre-8u5-linux-x64.tar.gz
DEBIAN_FRONTEND=noninteractive
UCF_FORCE_CONFFNEW=true
export UCF_FORCE_CONFFNEW DEBIAN_FRONTEND
apt-get update
apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" dist-upgrade
#!/usr/bin/python
#By Steve Hanov, 2011. Released to the public domain
import time
import sys
DICTIONARY = "/usr/share/dict/words";
TARGET = sys.argv[1]
MAX_COST = int(sys.argv[2])
# read dictionary file
@alixedi
alixedi / nutshell.py
Last active July 7, 2016 13:18
Python tool to make long CLI commands interactive
#! /usr/bin/env python
'''
Nutshell - make long CLI commands interactive
---------------------------------------------
I am lazy. I am forgetful. I often have to write long CLI commands.
The shell history does an awesome job of remembering them for me but too often
I end up working too hard in trying to find the line I wrote a couple of days
back and having to change something simlple e.g. name of a file etc.
@alixedi
alixedi / xtemplate.py
Created January 8, 2016 15:42
Generate templates from text.
def xtemplate(toks, str):
'''
A function that generates templates from given tokens and
strings. We are using this to generate email templates:
>>> sep = [(',', ','), ('-', '-'), ('_', '_')]
>>> ini = [('$fini', 'a'), ('$lini', 'z')]
>>> name = [('$fname', 'ali'), ('$lname', 'zaidi')]
>>> toks = sep + ini + name
>>> xtemplate(toks, 'ali.zaidi')
'$fname.$lname'
@alixedi
alixedi / half_orm.py
Last active September 16, 2015 11:19
Neat trick to deal with bunch of JSON records.
import json
class Record(object):
"""
A simple trick that allows you to do `record.name`, 'record.age'
instead of `record['name']`, `record['age']`.
>>> import json
>>> data = json.dumps([{'name': 'jack', 'user': {'id': 21}}])
>>> recs = Record.make_records(data)
@alixedi
alixedi / Hello
Created July 24, 2015 21:08
Test for gist.io
Hello World!
============
I am **Ali**.
@alixedi
alixedi / .vimrc
Created July 24, 2015 18:10
My .vimrc
" @alixedi - My .vimrc based on:
" Sample by Martin Brochhaus: github.com/mbrochh/
" Automatic reloading of .vimrc
autocmd! bufwritepost .vimrc source %
" Better copy & paste
" When you want to paste large blocks of code into vim, press F2 before you
@alixedi
alixedi / fibonacci.py
Last active August 29, 2015 14:24 — forked from trtg/fibonacci.py
#from functools import lru_cache#python >=3.2
from functools32 import lru_cache#python 2.7
#from repoze.lru import lru_cache#python 2.7
#NOTE: you can use python -m trace --count fibonacci.py
#to see how many times each instruction is called
#@lru_cache(maxsize=500)#repoze.lru needs maxsize arg
@lru_cache()#using functools32
def fibonacci(n):
@alixedi
alixedi / correlation.py
Created April 16, 2015 09:21
Pearson product-moment correlation
from math import sqrt
from random import sample
from datetime import datetime
def correlation(ser1, ser2):
"""Computes Pearson product-moment correlation coefficient for the given 2
time series. See: http://bit.ly/1PHG1jy
>>> from correlation import correlation
>>> s1 = [random()*100 for i in range(100)]
>>> _s1 = [100-s1[i] for i in range(100)]