Skip to content

Instantly share code, notes, and snippets.

View gjcourt's full-sized avatar

George Courtsunis gjcourt

View GitHub Profile
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)
@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 = []
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
@gjcourt
gjcourt / name_mangling.py
Last active August 29, 2015 14:20
Name Mangling example.
class Foo(object):
def __init__(self, **kwargs):
self.__attr = kwargs.pop('attr', None)
@property
def bar(self):
return self.__attr
def test_foo():
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):
@gjcourt
gjcourt / orm.coffee
Last active August 29, 2015 14:07
Database and ORM
App.Storage = _.extend { Database: {} }, App.Storage
class App.Storage.Database.Statement
__error: (args...) ->
console.error args...
constructor: (@query, @args=[], @success=(->), @error=@__error) ->
App.Storage = _.extend { Database: {} }, App.Storage
class App.Storage.Database.Statement
__error: (args...) ->
console.error args...
constructor: (@query, @args=[], @success=(->), @error=@__error) ->