Skip to content

Instantly share code, notes, and snippets.

@pmav99
pmav99 / BootstrapTable.py
Created January 19, 2015 17:35
Bootstrap Table Helper
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: Panagiotis Mavrogiorgos
# email: gmail, pmav99
"""
A help class for generating bootstrap tables.
"""
from __future__ import division
@pmav99
pmav99 / foo.pgn
Created February 27, 2015 17:34
me vs malakas - correspondence game 1
[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"]
@pmav99
pmav99 / nearly_equal.py
Last active August 29, 2015 14:20
A pure python "nearly_equal" implementation
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
@pmav99
pmav99 / von_mises.py
Created May 4, 2015 08:45
Modified von Mises
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
@pmav99
pmav99 / virtualenv.md
Last active August 29, 2015 14:24
virtualenv + virtualenvwrapper instructions

Tested under zsh, should work under bash too.

  1. Install virtualenv & virtualenvwrapper. Depends on the distribution.

  2. 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

@pmav99
pmav99 / makefile
Created May 26, 2016 08:45
makefile template
.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
@pmav99
pmav99 / float_formatter.py
Created October 15, 2016 09:36
Python Float formatting
# first cell
import os
import glob
import locale
import numpy as np
import pandas as pd
from IPython.core.interactiveshell import InteractiveShell
@pmav99
pmav99 / sr.md
Last active January 10, 2017 12:49
Pure Python 3 search and replace

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).

@pmav99
pmav99 / extract.sh
Created January 30, 2017 12:23
Linux extract snippet
#!/bin/bash
# an extract command
x() {
local c e i
(($#)) || return
for i; do
c=''