Skip to content

Instantly share code, notes, and snippets.

@fcostin
fcostin / adventure generator pythons
Created August 23, 2012 13:31
attack of generator.send
In [10]: def adventure():
....: print 'there is cupcake. do you eat it?'
....: x = (yield)
....: if x:
....: print 'the cupcake is tasty'
....: print 'is this awesome?'
....: x = (yield)
....: if x:
....: print 'awesome!!'
....: while True:
@fcostin
fcostin / enumerated_casemap.py
Created November 2, 2012 04:12
enumerated_casemap
def enumerated_casemap(case_handlers, things):
i = 0
for x in things:
for p, f in case_handlers:
if p(x):
yield f(i, x)
i += 1
break
def main():
def make_display():
def naturals():
i = 0
while True:
yield i
i += 1
i = iter(naturals())
def display(a, b):
@fcostin
fcostin / enigma_1750.py
Created June 15, 2013 01:24
enigma number 1750 (brute force: enumerate all paths then filter)
import itertools
from collections import defaultdict
GRID_SIZE = 3
on_grid = lambda (a, b) : (0 <= a < GRID_SIZE) and (0 <= b < GRID_SIZE)
def gen_neighbours((a, b)):
for i, j in itertools.product((-1, 0, 1), repeat=2):
a_prime = a + i
// goal: typeDefinitions = {"FIDO" : {864 : ["SUPER_864"]}, "SPOT" : {432 : ["LUCKY_SPOT_432"], 576 : ["MERRY_SPOT_576"]}}
// works with g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
//
// g++ -Wall -Werror -pedantic -Wconversion --std=c++0x % && ./a.out
#include <vector>
#include <map>
#include <tuple>
#include <utility>
@fcostin
fcostin / test_if_ridulous_inequality_chain_works_like_is_sorted.py
Created August 20, 2013 07:43
answers to things you never wanted to know
import numpy
import py.test
MIN_SIZE = 2 # you cant have an unsorted array of size 1 !
MAX_SIZE = 1000
def is_sorted(a):
sa = numpy.sort(a)
return numpy.all(sa == a)
@fcostin
fcostin / minty_skypes.txt
Created December 20, 2013 10:59
setting up skype for some old debian flavoured mint
this is the way to go:
https://wiki.debian.org/skype
it Just Worked.
to enable your mic, open `mate-volume-control` and ensure the input device is unmuted...
this is also interesting: it gives you a way to meddle with webcam brightness / contrast / sharpening filters:
# HG changeset patch
# User Reuben Fletcher-Costin <[email protected]>
# Date 1409866198 -36000
# Fri Sep 05 07:29:58 2014 +1000
# Branch windows_support
# Node ID 88290ca7505a15b8f4a1fe1a4f94fafebd747d8e
# Parent 9051b4b72737edcd7b483716471c070c917c5fde
windows_support - use setuptools console_scripts entry point; combine wake.py and vulture into vulture.py
diff --git a/ez_setup.py b/ez_setup.py
@fcostin
fcostin / popmodel.py
Created June 25, 2015 04:11
a simple yet perhaps informative population model.
"""
a stupid population model
Simplifying assumptions:
assume everyone in each country behaves the same
everyone lives until their birth life expectancy
everyone has same number of kids [1]
uniform life expectancy (take geom average men and women) [2m 2f]
everyone pair-bonds into a couple and has kids
@fcostin
fcostin / TEST_nunit_foo.xml
Last active October 7, 2015 00:49
TEST_nunit_foo
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!--This file represents the results of running a test suite-->
<!--example comment-->
<!--another example comments. TFS VSO is a wonderful and intuitive test collection and reporting tool. -->
<test-results name="C:\Program Files\NUnit 2.6\bin\tests\mock-assembly.dll" total="2" errors="0" failures="1" not-run="0" inconclusive="0" ignored="0" skipped="0" invalid="0" date="2015-10-07" time="11:22:00">
<environment nunit-version="" clr-version="" os-version="Microsoft Windows NT 6.1.7600.0" platform="Any CPU" cwd="C:\Program Files\NUnit 2.6\bin" machine-name="CHARLIE-LAPTOP" user="charlie" user-domain="charlie-laptop" />
<culture-info current-culture="en-US" current-uiculture="en-US" />
<test-suite type="Assembly" name="FOO" executed="True" result="Failure" success="False" time="0.094" asserts="0">
<results>