Skip to content

Instantly share code, notes, and snippets.

@garykpdx
garykpdx / concurrent_example.py
Last active Jul 12, 2016
Example of concurrent processusing Python builtin library(example modified from example in Python docs)
View concurrent_example.py
#!/usr/bin/env python
import os
from concurrent.futures import ProcessPoolExecutor
import math
import time
PRIMES = [
112272535095293,
112582705942171,
@garykpdx
garykpdx / enforced_parameters_decorator.py
Last active Aug 29, 2015
A decorator that enforces a particular type/subtype for each parameter of a function
View enforced_parameters_decorator.py
class enforce(object):
def __init__(self,*argtypes):
# the types that need to be enforced for each position arg[i]
self.argtypes = argtypes
def __call__(self,f):
def wrapper(*args):
# bail if the definition isn't set up to handle this many arguments
if len(self.argtypes) < len(args):
raise Exception('too many parameters passed in')
View FactorialExample.java
/**
* This program shows the different kinds of calls that can be made for functions like the factorial, and fibonacci
*
*/
public class FactorialExample {
public static void main(String[] args) {
System.out.println( factRecursive(5));
System.out.println( factTailRecursive(5));
System.out.println( factIterative(5));