Skip to content

Instantly share code, notes, and snippets.

import pymongo
from datetime import datetime, timedelta, time
from calendar import monthrange
db = pymongo.MongoClient().test
def generate_events(n, step):
date = datetime.now()
for i in range(n):
@theorm
theorm / ec2_to_route53.py
Last active December 10, 2015 14:49
Extract hostname of an instance from a tag value (Name by default) and create A records with public and/or private IP address of the instance and hostname as name. Optionally update search domains and host name on the machine.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Author: Roman Kalyakin
#
# EC2 to Route53 magic
#
# https://gist.github.com/4449827
#
@theorm
theorm / flask_objectid_converter.py
Created January 8, 2013 11:19
MongoDB ObjectId converter for Flask framework.
-*- coding: utf-8 -*-
from werkzeug.routing import BaseConverter
from werkzeug.exceptions import BadRequest
import bson
class ObjectIdConverter(BaseConverter):
'''Converts string to :class:`~bson.objectid.ObjectId` and
vise versa::
@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)
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 / Makefile
Last active December 14, 2015 17:28
Convert properties file style dict to JSON style
test:
PYTHONPATH=. python test_dedot.py
@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__ = [
# 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 / README.md
Last active December 18, 2015 14:09
Load configuration from a YAML file.

Utilities for loading configuration from a YAML file.

# convert MTS files to MOV for FCPX
ffmbc -i inFile -vcodec copy -strict experimental outFile