Skip to content

Instantly share code, notes, and snippets.

@zed
zed / crop-resize.py
Created December 6, 2012 01:40
Resize the image to given size. Don't strech images, crop and center instead.
#!/usr/bin/env python
"""Resize the image to given size.
Don't strech images, crop and center instead.
"""
import os
import sys
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from fractions import Fraction
from functools import partial
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
/big.txt
/reporttime$py.class
@zed
zed / tree-grep.py
Created December 19, 2012 16:17
Filter directory tree using given regex pattern.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""`tree-grep.py [-i] DIR PATTERN` is similar to `tree DIR | grep [-i] PATTERN`
but it shows the whole branch upto the matched child node.
# Installation
* termcolor - helper functions for ANSII color formatting
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/bin/bash
#
# Print common lines between all given files
#
# exit on any error
set -e
# exit if no files given
USAGE="Usage: $0 file1 [file2 [file3...]]"
@zed
zed / german number separator.ipynb
Created January 11, 2013 23:04
german number separator
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zed
zed / time33.py
Last active April 15, 2019 09:04
time.process_time() and time.perf_counter() for Python 2 on Ubuntu.
"""time.process_time() and time.perf_counter() for Python 2 on Ubuntu."""
import ctypes
import errno
from ctypes.util import find_library
from functools import partial
CLOCK_PROCESS_CPUTIME_ID = 2 # time.h
CLOCK_MONOTONIC_RAW = 4
clockid_t = ctypes.c_int
@zed
zed / !README.md
Last active September 13, 2018 07:19
swig hello world example
""" http://stackoverflow.com/a/13704307
To convert datetime to np.datetime64 and back (numpy-1.6):
>>> from datetime import datetime
>>> import numpy as np
>>> np.datetime64(datetime(2012, 12, 4, 13, 34, 52, 827542)).astype(datetime)
datetime.datetime(2012, 12, 4, 13, 34, 52, 827542)
It works both on a single np.datetime64 object and a numpy array of np.datetime64.