Skip to content

Instantly share code, notes, and snippets.

View edouardp's full-sized avatar

Edouard Poor edouardp

View GitHub Profile
@edouardp
edouardp / README.md
Last active March 8, 2021 04:48
Calling script to force MFA with AWS cli

TODO

  • Create a write-up on how this works
@edouardp
edouardp / DbProviderHelper.cs
Created June 27, 2016 08:09
Helper to make using DbProviderFactories.GetFactory() easier to use with dynamic provider loading (no app.config required)
class DbProviderHelper
{
const string AssemblyQualifiedName = "AssemblyQualifiedName";
const string Name = "Name";
const string InvariantName = "InvariantName";
const string Description = "Description";
internal class FactoryInfo
{
public string InvariantName { get; set; }
@edouardp
edouardp / raise_on_none.py
Last active August 29, 2015 14:25
Python decorator to raise a RuntimeError if any of the arguments are None when called
import inspect
def raise_on_none(f):
arg_spec = inspect.getargspec(f)
def new_f(*args, **kwargs):
bound_args = inspect.getcallargs(f, *args, **kwargs)
if(any([bound_args[a]==None for a in arg_spec.args])):
raise RuntimeError('Named arg is None')
if(arg_spec.keywords != None):
if(any([a==None for a in bound_args[arg_spec.keywords].values()])):
raise RuntimeError('Keyword arg is None')
@edouardp
edouardp / ignore_unused_args.py
Created July 18, 2015 20:13
Python decorator that ignores unneeded keyword arguments
import inspect
def ignore_unused_args(f):
arg_spec = inspect.getargspec(f)
def new_f(*args, **kwargs):
new_kwargs = {key:kwargs[key] for key in arg_spec.args if key in kwargs}
return f(*args, **new_kwargs)
new_f.spec = arg_spec
return new_f
@edouardp
edouardp / radiance_writer.py
Created July 11, 2012 10:47
Numpy based writer for Radiance HDR files
# Assumes you have a np.array((height,width,3), dtype=float) as your HDR image
import numpy as np
f = open("xxx.hdr", "wb")
f.write("#?RADIANCE\n# Made with Python & Numpy\nFORMAT=32-bit_rle_rgbe\n\n")
f.write("-Y {0} +X {1}\n".format(image.shape[0], image.shape[1]))
brightest = np.maximum(np.maximum(image[...,0], image[...,1]), image[...,2])
mantissa = np.zeros_like(brightest)
@edouardp
edouardp / visitor.py
Created June 21, 2012 10:02
Still can't figure out what a visitor is in Python
# -- Shapes -------------------------------------------------------------------
class Square:
def __init__(self, side_length, color):
self.name = 'square'
self.side_length = side_length
self.color = color
class Circle:
@edouardp
edouardp / distributions.py
Created May 1, 2012 08:59
Transform Random and Halton Uniform Generators into Normal Distribution
class UniformGenerator:
def __init__(self):
self.uniform = random.uniform
def next(self):
return self.uniform(0,1)
def haltonterm(i, base=2):
h = 0
fac = 1.0/base