Skip to content

Instantly share code, notes, and snippets.

@estebistec
estebistec / prime_factorization.py
Created Apr 28, 2018
Find prime factorizations of numbers, with small optimizations
View prime_factorization.py
import math
def require_int(n):
if not type(n) is int:
raise TypeError('argument must have type int; got {} which has type {}'.format(n, type(n).__name__))
def require_non_negative_int(n):
require_int(n)
if n < 0:
raise ValueError('argument must be an int >= 0; got {}'.format(n))
@estebistec
estebistec / morepath_conneg.py
Last active May 15, 2016
morepath #70: Content negotiation: Look at accept header in request
View morepath_conneg.py
# -*- coding: utf-8 -*
import morepath
import reg
from morepath import generic
from webob.acceptparse import MIMEAccept
from webob.exc import HTTPNotAcceptable
@estebistec
estebistec / dna.js
Created May 16, 2015
find complement strand
View dna.js
(function(export) {
var symbolComplements = {
"A": "T",
"T": "A",
"C": "G",
"G": "C"
};
export.DNA = {
complementStrand: function(strand) {
@estebistec
estebistec / base_type.py
Last active Aug 29, 2015
Methods for namedtuple instantiation that don't require all fields to be provided
View base_type.py
from collections import namedtuple
PersonTuple = namedtuple('PersonTuple', ['formal_name', 'preferred_name'])
View Array.prototype.forEach.js
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Polyfill
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(fun /*, thisArg */)
{
"use strict";
if (this === void 0 || this === null)
throw new TypeError();
@estebistec
estebistec / arrayWithPropsIter.js
Created May 23, 2014
Iterating over an array with extra properties
View arrayWithPropsIter.js
var a = [1,2,3];
a.hasNextPage = false;
console.log(a)
// [ 1,
// 2,
// 3,
// hasNextPage: false ]
// Uh oh...
@estebistec
estebistec / clean.sh
Created May 7, 2014
Remove untracked files in svn repos
View clean.sh
svn status | egrep '^\?' | cut -c8- | xargs rm -fr
View .zshrc
# Update brew
brew update; brew upgrade; brew cleanup --force; brew doctor
# pythonz
[[ -s $HOME/.pythonz/etc/bashrc ]] && source $HOME/.pythonz/etc/bashrc
# Update setuptools, pip, and virtualenvwrapper
pip install -U pip setuptools virtualenv virtualenvwrapper cookiecutter
# Setup virtualenvwrapper
View keybase.md

Keybase proof

I hereby claim:

  • I am estebistec on github.
  • I am estebistec (https://keybase.io/estebistec) on keybase.
  • I have a public key whose fingerprint is DD92 FC70 2457 D891 0CE7 DAB6 DEC1 C2F9 7E1A 8D95

To claim this, I am signing this object:

@estebistec
estebistec / intToBinStr.hs
Last active Aug 29, 2015
Haskell 4 Madhurima
View intToBinStr.hs
intToBinStr :: Int -> String
intToBinStr n =
let _shiftBits 0 s = s ++ "0"
_shiftBits 1 s = s ++ "1"
_shiftBits x s = _shiftBits (div x 2) (s ++ show (mod x 2))
in _shiftBits n ""
main :: IO ()
main = print $ intToBinStr 19