Skip to content

Instantly share code, notes, and snippets.

View hansent's full-sized avatar

Thomas Hansen hansent

View GitHub Profile
@hansent
hansent / index.md
Created August 10, 2013 23:25
Euclid's algorithm

Euclid's algorithm

Euclid's algorithm is a method for computing the greatest common divisor (GCD) of two (usually positive) integers, also known as the greatest common factor (GCF) or highest common factor (HCF). It is named after the Greek mathematician Euclid, who described it in Books VII and X of his Elements.

In Python

def gcd(a, b):
#find_meeting_time.py
#scheduling is hard :/
def find_meeting_time(person):
meeting_time = person.suggest()
for p in pythonistas:
if p.has_conflict(meeting_time):
meeting_time = find_meeting_time(p)
return meeting_time
"""
find_meeting_time.py
scheduling is hard :/
"""
def find_meeting_time(person):
meeting_time = person.suggest()
for p in pythonistas:
if p.has_conflict(meeting_time):
meeting_time = find_meeting_time(p)
# This file describes how to build hipache into a runnable linux container with all dependencies installed
# To build:
# 1) Install docker (http://docker.io)
# 2) Clone hipache repo if you haven't already: git clone https://github.com/dotcloud/hipache.git
# 3) Build: cd hipache && docker build .
# 4) Run:
# docker run -d <imageid>
# redis-cli
#
# VERSION 0.2
root@hygge:/code/hipache# docker build .
Caching Context 112640/? (n/a)
FROM ubuntu:12.04 ()
===> 8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list (8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c)
===> 4b993f7c57b3aa051881dd0dac6de9ac88b37f39e477cc6698b8a173a8bf1fee
RUN apt-get -y update (4b993f7c57b3aa051881dd0dac6de9ac88b37f39e477cc6698b8a173a8bf1fee)
===> c38b066d6c172abb1019d778762076e67cb81ba69b6613694d916f1779034b24
RUN apt-get -y install wget git redis-server supervisor (c38b066d6c172abb1019d778762076e67cb81ba69b6613694d916f1779034b24)
===> 1e677fa1516eeb4d0bfb890ca94f035690894462616495d4fd46850d508918c2
#!/bin/bash
set -x
#install some general dependencies
apt-get update -yqq
apt-get install -yq python-software-properties
apt-get install -yq software-properties-common
#add apt repositories
@hansent
hansent / scroll_effects.py
Last active December 15, 2015 23:10
scroll-effects
import time
from kivy.app import App
from kivy.factory import Factory as F
from kivy.lang import Builder
from kivy.properties import *
from kivy.clock import Clock
from kivy.graphics.transformation import Matrix
from kivy.utils import interpolate
from kivy.event import EventDispatcher
@hansent
hansent / damping.py
Last active December 15, 2015 15:38
import time
from kivy.app import App
from kivy.factory import Factory as F
from kivy.lang import Builder
from kivy.properties import *
from kivy.clock import Clock
from kivy.graphics.transformation import Matrix
from kivy.utils import interpolate
from kivy.event import EventDispatcher
import time
class KinematicEffect(EventDispatcher):
velocity = NumericProperty(0)
friction = NumericProperty(0.08)
threshold = NumericProperty('20sp')
fx = NumericProperty(0)
# -*- coding: utf-8 -*-
from kivy.app import App
from kivy.lang import Builder
kv_ui = """
BoxLayout:
padding: 10
Label:
valign: 'middle'
text_size: self.size