Skip to content

Instantly share code, notes, and snippets.

@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 / .gitattributes
Last active August 16, 2019 12:17
gitattributes
## GITATTRIBUTES FOR WEB PROJECTS
#
# These settings are for any web project.
#
# Details per file setting:
# text These files should be normalized (i.e. convert CRLF to LF).
# binary These files are binary and should be left untouched.
#
# Note that binary is a macro for -text -diff.
######################################################################
@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=''
@pmav99
pmav99 / flask-uWSGI-nginx.md
Created July 10, 2017 08:22 — forked from bluekvirus/flask-uWSGI-nginx.md
How To Serve Flask Applications with uWSGI and Nginx on Ubuntu 14.04+

How To Serve Flask Applications with uWSGI and Nginx on Ubuntu 14.04

@credit Yan Zhu (https://github.com/nina-zhu)

Introduction

Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions, it can help you get your Python application or website off the ground. Flask includes a simplified development server for testing your code locally, but for anything even slightly production related, a more secure and powerful web server is required.

In this guide, we will demonstrate how to install and configure some components on Ubuntu 14.04 to support and serve Flask applications. We will configure the uWSGI application container server to interface with our applications. We will then set up Nginx to reverse proxy to uWSGI, giving us access to its security and performance features to serve our apps.

Prerequisites and Goals

@pmav99
pmav99 / check_digit.rb
Created July 22, 2017 21:02 — forked from stuartbain/check_digit.rb
Calculate check digits for SEDOL, CUSIP, ISIN and BBGID (Bloomberg Global Id) codes
module CheckDigit
class SEDOL
SEDOL_WEIGHTS = [1,3,1,7,3,9]
SEDOL_PATTERN = /[B-Db-dF-Hf-hJ-Nj-nP-Tp-tV-Xv-xYyZz\d]{6}/ # http://regexlib.com/REDetails.aspx?regexp_id=1044
def self.calculate(sedol)
raise 'Invalid pattern' unless sedol =~ SEDOL_PATTERN
@pmav99
pmav99 / config.py
Last active February 11, 2018 21:49
yaml based configuration for python logging
#!/usr/bin/env python
# module: <package>/__init__.py
# author: Panagiotis Mavrogiorgos <pmav99,gmail>
import logging.config
import pathlib
import yaml
try:
from yaml import CLoader as YLoader, CDumper as YDumper
@pmav99
pmav99 / gist:e643646f8df816373dd75a911fc93a36
Created February 16, 2018 14:58 — forked from ymirpl/gist:1052094
Python unicode e-mail sending
#coding: utf-8
from cStringIO import StringIO
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header
from email import Charset
from email.generator import Generator
import smtplib
# Example address data
@pmav99
pmav99 / vtk_python_mesh.py
Created February 26, 2018 11:57 — forked from Hodapp87/vtk_python_mesh.py
Simple VTK example in Python to load an STL mesh and display with a manipulator.
#!/bin/env python
"""
Simple VTK example in Python to load an STL mesh and display with a manipulator.
Chris Hodapp, 2014-01-28, (c) 2014
"""
import vtk
def render():
@pmav99
pmav99 / vtk-unstructuredgrid-to-stl.py
Created February 26, 2018 11:57 — forked from thewtex/vtk-unstructuredgrid-to-stl.py
Convert a .vtk UnstructuredGrid file to .stl file.
#!/usr/bin/env python
"""Convert UnstructuredGrid in .vtk files to STL files."""
import sys
import vtk
if len(sys.argv) < 2 or sys.argv[1] == '-h' or sys.argv[1] == '--help':
print('Usage: vtk-unstructuredgrid-to-stl.py <input.vtk> <output.stl>')
sys.exit(1)