Some functions for helping timing stuff.
Note: The best timer is platform dependent. So always use from timeit import default_timer
.
Some functions for helping timing stuff.
Note: The best timer is platform dependent. So always use from timeit import default_timer
.
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# author: Panagiotis Mavrogiorgos | |
# email: gmail, pmav99 | |
""" | |
A help class for generating bootstrap tables. | |
""" | |
from __future__ import division |
[Event "Let's Play!"] | |
[Site "Chess.com"] | |
[Date "2015.02.18"] | |
[Round "?"] | |
[White "pmav99"] | |
[Black "RedPawn81"] | |
[Result "*"] | |
[WhiteElo "1913"] | |
[BlackElo "1564"] | |
[TimeControl "1 in 5 days"] |
def nearly_equal(a, b, epsilon): | |
""" | |
Return `True` if the "difference" between `a` and `b` is smaller than `epsilon`, `False` otherwise. | |
This function tries to solve the problem of float comparison in a way that handles all cases | |
(i.e. comparing floats with `inf`, `nan` etc). | |
Do take note that when the difference between `a` and `b` is "equal" to `epsilon` then the | |
results may not be what you expect them to be... For example:: | |
a = 1 | |
b = a + 1e-7 | |
epsilon = 1e-7 |
def von_mises(S11, S22, S12, fc, ft): | |
""" | |
Returns the type of failure according to the modified Von Mises | |
failure criterion. | |
Input | |
----- | |
S11 : float | |
Normal stresses (σx) | |
S22 : float |
Tested under zsh
, should work under bash
too.
Install virtualenv
& virtualenvwrapper
. Depends on the distribution.
Put in .zshrc
(.bashrc
if you use bash
):
# Virtualenvs
if which virtualenvwrapper.sh &> /dev/null; then
mkdir -p $HOME/Prog
export WORKON_HOME=$HOME/.virtualenvs
.PHONY: list | |
list: | |
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs |
# first cell | |
import os | |
import glob | |
import locale | |
import numpy as np | |
import pandas as pd | |
from IPython.core.interactiveshell import InteractiveShell |
This script is similar to:
ag pattern -l | xargs sed -i 's;pattern;replace;g'
with the added benefit that you can use proper regular expressions (e.g. grouping, lookaheads etc which are not supported on sed...).
Since ag
is being used for searching the files, performance shouldn't be too bad (especially on SSDs).
#!/bin/bash | |
# an extract command | |
x() { | |
local c e i | |
(($#)) || return | |
for i; do | |
c='' |