Skip to content

Instantly share code, notes, and snippets.

View ExcelConverter.java
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
@ethanal
ethanal / print_template.tex
Created Jun 25, 2015
A LaTeX template for printing syntax-highlighted code nicely in grayscale
View print_template.tex
\documentclass[11pt]{article}
\usepackage[letterpaper]{geometry}
\geometry{top=0.5in, bottom=0.5in, left=0.7in, right=0.7in}
\usepackage{courier}
\usepackage{listings}
\usepackage{fancyhdr}
\pagestyle{fancy}
@ethanal
ethanal / text_styles.py
Created Jun 25, 2015
Python text styling with ANSI codes
View text_styles.py
import os
import sys
import platform
def _style(code):
def wrapper(string):
if os.isatty(sys.stdout.fileno()) and platform.system() != "Windows":
return "\033[{:02}m{}\033[00m".format(code, string)
return string
@ethanal
ethanal / profiler.py
Created Jun 25, 2015
Simple python profiler
View profiler.py
import functools
from time import time
from .text_styles import *
class ProfileItem(object):
def __init__(self, name, elapsed, stats):
self.name = name
self.elapsed = elapsed
View keybase.md

Keybase proof

I hereby claim:

  • I am ethanal on github.
  • I am ethanal (https://keybase.io/ethanal) on keybase.
  • I have a public key whose fingerprint is 178B 38FA 151F C237 625D 55B0 944F E97D 33AB DB60

To claim this, I am signing this object:

View Random Walk Coin Game.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ethanal
ethanal / encode_polyline.py
Created Oct 3, 2014
Encode Polyline for Google Static Maps API
View encode_polyline.py
def invert(b):
return "".join(str(int(not int(c))) for c in b)
def encode_float(f):
b = bin(abs(int(round(f * 1e5))))[2:]
b = ("0" * (32 - len(b))) + b
if f < 0:
b = invert(b)
@ethanal
ethanal / baseconv.py
Last active Aug 29, 2015
Base conversion with arbitrary alphabets
View baseconv.py
def baseconv(v1, a1, a2):
if v1 == a1[0]: return a2[0]
v2 = ""
n1 = {c: i for i, c in enumerate(a1)}
b1 = len(a1)
b2 = len(a2)
d1 = 0
for i, c in enumerate(v1):
d1 += n1[c] * pow(b1, len(v1) - i - 1)
@ethanal
ethanal / moarjpeg.py
Last active Aug 29, 2015
Script to to optimize images for maximum jpeg
View moarjpeg.py
import cStringIO as StringIO
from random import randint
import sys
from PIL import Image
import wand.image
input_filepath = sys.argv[1]
img = Image.open(input_filepath)
@ethanal
ethanal / fizzbuzz.py
Last active Aug 29, 2015
FizzBuzz Code Golf
View fizzbuzz.py
print([(i%3==0)*"Fizz"+(i%5==0)*"Buzz" or i for i in range(100)])