Skip to content

Instantly share code, notes, and snippets.

View mkilling's full-sized avatar

Marvin Killing mkilling

View GitHub Profile
@mkilling
mkilling / joins-scopes.rb
Last active June 3, 2017 00:21
Illustrates a problem with scopes being applied to joins in unrelated queries
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", '= 4.2.8'
@mkilling
mkilling / examplemodule.lua
Created November 21, 2011 00:23
Better Lua Module Example
-- define a local table to store all references to functions/variables
local M = {}
function M:testFunction1()
print( "Test 1" )
end
function M:testFunction2()
print( "Test 2" )
end
[alias]
ci = commit
co = checkout
st = status
b = branch
lol = log --oneline --graph
stash-unapply = !git stash show -p | git apply -R
dt = difftool
mt = mergetool
[merge]
@mkilling
mkilling / functools.cs
Created May 3, 2011 16:39
Y combinator in C#
public static class FuncTools
{
public delegate Action Recursive(Recursive rs);
public static Action YCombinator(Func<Action, Action> f)
{
Recursive rec = r => () => f(r(r))();
return rec(rec);
}
// McMaster's algorithm
void Path::smoothPoints()
{
const int LOOKAHEAD = 50;
if (points_.size() < 5)
return;
std::list<PathPoint> newPoints;
for (std::list<PathPoint>::iterator it = ++points_.begin();
it != points_.end(); it++)
{
Vector curPos = it->getPosition();
Vector prevPos = (--it)->getPosition();
Vector vecFromPrev = curPos - prevPos;
float distance = vecFromPrev.abs();
it++;
if (distance > MAX_DISTANCE_BETWEEN_POINTS)
{
import string
def make_key_prefix():
import itertools
first_chars = "AAAA"
for i in itertools.combinations(string.letters, 8 - len(first_chars)):
yield first_chars + "".join(i)
def sum_up (seq):
return sum(seq) % 256