Skip to content

Instantly share code, notes, and snippets.

View gjcourt's full-sized avatar

George Courtsunis gjcourt

View GitHub Profile
@gjcourt
gjcourt / iPhone Scale.js
Created October 29, 2010 07:19
get the scale on all iDevices
function scale() {
return document.body.clientWidth / window.innerWidth;
}
@gjcourt
gjcourt / minesweeper.py
Created July 13, 2017 01:46
Simple text-based minesweeper game
import math
import random
ROWS = 10
COLUMNS = 10
MINE_COUNT = 10
BOARD = []
require "benchmark"
$count = 5
$item_count = 100_000
$iterations = 1_000
def setup
(1..$count).map{|x| {:num => x, :data => (1..$item_count).to_a}}
end
def cumulative_remainder(amount, count)
(1..count).map do |i|
amount * i / count - amount * (i - 1) / count
end
end
puts cumulative_remainder(100, 3)
import hashlib
import hmac
import pytz # pip install pytz
from collections import namedtuple
from datetime import datetime, timedelta
from itertools import izip
from urllib import quote
def utcaware(dt):
from functools import wraps
def my_decorator(x=None):
def outer(func):
@wraps(func)
def inner(self):
y = 10
print "x + {0} = {1}".format(y, x + y)
func(self)
class Implementation(object):
def __init__(self, func, x):
self.func = func
self.x = x
def __call__(self, *args, **kwargs):
return self.decorator(*args, **kwargs)
#!/bin/sh
# Copyright (C) 2016 George Courtsunis, MIT license
#
# Script accepts -e -f -c -s -S -C arguments for calculating the spoke length
# based on the effective rim diameter, flange diameter, center to flange, spoke
# diameter, spoke number, and cross number. All measurements are expected in
# mm, however any unit as long as they are all consistent will work.
#
# --erd Effective rim diameter
include_recipe "python"
include_recipe "sudo"
package "htop"
package "tree"
package "libcurl3"
package "fail2ban"
package "unattended-upgrades"
package "logwatch"
@gjcourt
gjcourt / partition.py
Last active December 24, 2015 23:19
Partition a collection into bins of size K
def partiton(collection, size):
return zip(*[iter(collection)]*size)