Skip to content

Instantly share code, notes, and snippets.

View makmanalp's full-sized avatar

Mehmet Ali "Mali" Akmanalp makmanalp

View GitHub Profile
from itertools import chain, starmap
def remove_spans(s, spans):
to_drop = set(chain(*starmap(range, spans)))
return ''.join(c for (i, c) in enumerate(s) if i not in to_drop)
@ianonavy
ianonavy / decorators.py
Last active August 29, 2015 14:03
Memoize to File
def memoize_to_file(func=None, **options):
"""Wraps a function definition so that if the function is ever
called with the same arguments twice, the results are pulled from
a cache stored in a file. The filename is specified when decorating
the memoized function. Iterable objects like dicts, lists or
pandas DataFrames are cast to a tuple before being hashed, and
everything else uses the object's __repr__ definition.
Usage:
language: python
python:
- "2.6"
- "2.7"
env:
- DJANGO=1.2.7 SUITE=tests
- DJANGO=1.3.1 SUITE=tests
- DJANGO=1.4 SUITE=tests
- DJANGO=1.4 SUITE=lint
install:
@lifthrasiir
lifthrasiir / no-box.md
Last active June 27, 2017 08:46
Idiomatic Rust: Yes I'm really trying to write something similar

No Box<T>

tl;dr: Avoid Box<T> in general.

Actually, this rule is so important that the Rust Pointer Guide explicitly says the same. Therefore without a further ado, you should avoid Box<T> except for these three cases:

  1. When you absolutely need a trait object (Box<Trait>). But review carefully to see if it is indeed absolutely needed; you may try to generalize things too far, for example.

  2. When you have a recursive data structure. This may be mandatory when you have an inherently recursive data (e.g. scene graph), but it may also be a sign of the premature optimization. Again, review carefully to see if you need to write a separate data structure yourself, and use the collection crate if possible.

@agounaris
agounaris / xelatex_macos.txt
Last active September 22, 2017 19:32
Jupyter notebook pdf export fix on macos
Download and install xelatex from http://www.texts.io/support/0001/
Based on the exact version etc add the executable on path
export PATH="$PATH:/usr/local/texlive/2016basic/bin/x86_64-darwin"
install all the following
sudo tlmgr update --self
sudo tlmgr install collectbox
sudo tlmgr install ucs
sudo tlmgr install adjustbox
@mrocklin
mrocklin / kalman.py
Created September 11, 2012 17:45
The Kalman filter represented in Theano syntax
import theano
import theano.sandbox.linalg as linalg
mu = theano.tensor.matrix('mu')
Sigma = theano.tensor.matrix('Sigma')
H = theano.tensor.matrix('H')
R = theano.tensor.matrix('R')
data = theano.tensor.matrix('data')
dot = theano.tensor.dot
@uranusjr
uranusjr / install_ensurepip.py
Created August 22, 2014 02:44
Script to install ensurepip to Python. “Fix” the Ubuntu 14.04 / Debian Sid bug. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=732703
import os
import sys
import io
import tarfile
import urllib.request
ARCHIVE_URL = 'http://d.pr/f/YqS5+'
@uniphil
uniphil / gist:7777590
Created December 3, 2013 21:13
send_from_directory

Say you have a package with this layout:

my_project/
    my_app/
        files/
            im_a_file.txt
        __init__.py
    run_my_app.py
@searls
searls / git-undo
Last active June 19, 2018 09:57
git undo script -- obviously git lacks a real undo feature, but sometimes in a moment frustration it can be worrying to not have the most common commands in mind after one makes a mistake. Just add a file named `git-undo` to a directory on your PATH and then run it with `git undo`
#!/usr/bin/env bash -e
cat <<TEXT
Git has no undo feature, but maybe these will help:
===================================================
## Unstage work
Unstage a file