Skip to content

Instantly share code, notes, and snippets.

@Jyrsa
Jyrsa / fizzbuzz_decorators.py
Last active January 3, 2016 08:19
A fizzbuzz implementation using a decorator that takes parameters several times.
from functools import wraps
def replace_if_condition_met(condition, replacement):
def innerfunc(func):
@wraps(func)
def wrap(*args):
val = func(*args)
if condition(val):
return replacement
return val
@Jyrsa
Jyrsa / fizzbuzz_partial.py
Created January 15, 2014 11:49
Simple closure implementation for positional args in python and a fizzbuzz using said implementation.
def simple_partial(func, *args):
original_args = args + ()
def inner(*new_args):
args = original_args + new_args
return func(*args)
return inner
def divisible(divider, value, number):
if number % divider == 0 :
return value
@Jyrsa
Jyrsa / nosetest_and_coverage.sh
Created July 31, 2012 09:44
Jenkins test scripts for a Python project (ripped from
#!/bin/bash -ex
cd $WORKSPACE
#regular virtualenv stuff
virtualenv -q --no-site-packages ve
source ./ve/bin/activate
pip install -r subdirectory/requirements-test.pip
cd subdirectory
#nose.cfg should hav with-coverage=1 and with-xunit=1
#or you can pass them onc ommand line here
@Jyrsa
Jyrsa / WordUrl.java
Created July 25, 2012 10:18
Solution to T-79.5308 Assignment 2 in Java
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.util.GenericOptionsParser;
/*Everything in mapred is deprecated, don't use unless must*/
//import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
@Jyrsa
Jyrsa / wordurl.py
Created July 25, 2012 10:14
Solution to T-79.5308 Assignment 2 in Python with MRJob
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" A Mapred from helmet library data to other data
"""
from mrjob.job import MRJob
from mrjob.protocol import JSONValueProtocol
import json