Skip to content

Instantly share code, notes, and snippets.

@theorm
theorm / howto_tilemill_osm
Created November 5, 2013 12:52
Tilemill + OSM
Follow this instruction: https://www.mapbox.com/tilemill/docs/guides/osm-bright-mac-quickstart/
Instead of downloading huge OSM datasets, download smaller areas from http://www.openstreetmap.org/export
@theorm
theorm / sync.sh
Created September 5, 2013 05:43
Rsync two external hard drives.
#!/bin/bash
SRC='/Volumes/apple-a'
DST='/Volumes/apple-b'
[ -d $SRC ] || {
echo "$SRC is not mounted";
exit 1;
}
@theorm
theorm / mongobak.py
Created August 29, 2013 05:54
Backup/Restore MongoDB collections or databases to/from S3
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
import logging
import subprocess
import shutil
import tarfile
import tempfile
import argparse
# convert MTS files to MOV for FCPX
ffmbc -i inFile -vcodec copy -strict experimental outFile
@theorm
theorm / README.md
Last active December 18, 2015 14:09
Load configuration from a YAML file.

Utilities for loading configuration from a YAML file.

# Emperor uWSGI script
description "uWSGI Emperor"
start on runlevel [2345]
stop on runlevel [06]
exec uwsgi --master --die-on-term --emperor /etc/uwsgi --logto=/var/log/uwsgi/emperor.log
@theorm
theorm / __init__.py
Last active April 14, 2020 18:45
Pluggable API using Flask MethodView.
# -*- coding: utf-8 -*-
from .bananas import Bananas
from .base import the_api
the_api.add_url_rule('/bananas', view_func=Bananas.as_view('bananas'))
the_api.add_url_rule('/farm/<farm_id>/bananas', view_func=Bananas.as_view('bananas_from_a_farm'))
__all__ = [
@theorm
theorm / Makefile
Last active December 14, 2015 17:28
Convert properties file style dict to JSON style
test:
PYTHONPATH=. python test_dedot.py
1.
===============
xxx// Can you sehis?
// Given as input: 3 + 4 + 6 * 7 * 2 + 8 ...
// Assume just single digits, + and *
// Evaluate it.
// Walk through the following case:
// 3
@theorm
theorm / longest_palindrome.py
Created January 31, 2013 05:26
Find longest palindrome substring in linear time.
# 1. palindrome window the size of string
# 2. split the window in half (omit central character is window size is odd)
# 3. compare substrings
# 4. if substings are equal - they are the longest palindrome
# 5. else slide the window to the right and repeat
# 6. if sliding the window right overflows the string, decrease the window and start again.
def find_longest_palindrome(input):
window_size = len(input)