This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cumulative_remainder(amount, count) | |
(1..count).map do |i| | |
amount * i / count - amount * (i - 1) / count | |
end | |
end | |
puts cumulative_remainder(100, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import random | |
ROWS = 10 | |
COLUMNS = 10 | |
MINE_COUNT = 10 | |
BOARD = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Implementation(object): | |
def __init__(self, func, x): | |
self.func = func | |
self.x = x | |
def __call__(self, *args, **kwargs): | |
return self.decorator(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo(object): | |
def __init__(self, **kwargs): | |
self.__attr = kwargs.pop('attr', None) | |
@property | |
def bar(self): | |
return self.__attr | |
def test_foo(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Storage = _.extend { Database: {} }, App.Storage | |
class App.Storage.Database.Statement | |
__error: (args...) -> | |
console.error args... | |
constructor: (@query, @args=[], @success=(->), @error=@__error) -> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Storage = _.extend { Database: {} }, App.Storage | |
class App.Storage.Database.Statement | |
__error: (args...) -> | |
console.error args... | |
constructor: (@query, @args=[], @success=(->), @error=@__error) -> | |
NewerOlder