Skip to content

Instantly share code, notes, and snippets.

View yxhuvud's full-sized avatar

Linus Sellberg yxhuvud

View GitHub Profile
class KnightTravails
def initialize size=8
@size = size
@board = Array.new(@size) { Array.new(@size)}
end
def knight_path start_node, end_node, forbidden_nodes
mark_forbidden forbidden_nodes
path = breadth_first_search start_node, end_node
@yxhuvud
yxhuvud / gist:2006599
Created March 9, 2012 13:54
python idiocy. (source: ceder).
# -*- tab-width:4 -*-
def x():
if 1:
if 0:
print "x 12 space"
print "x 1 tab plus 4 space"
# -*- tab-width:8 -*-
def y():
if 1:
irb(main):001:0> class A
irb(main):002:1> def foo
irb(main):003:2> puts 'foo'
irb(main):004:2> end
irb(main):005:1> def foo= bar
irb(main):006:2> puts 'bar'
irb(main):007:2> end
irb(main):008:1> end
=> nil
irb(main):009:0> x = A.new
class CacheDb
TABLE_POOL_LIMIT = 15
DB = :cache_db
AR_PROTOTYPE = Class.new(ActiveRecord::Base)
AR_PROTOTYPE.abstract_class = true # To avoid STI inheritance..
AR_PROTOTYPE.establish_connection DB
def self.connection
AR_PROTOTYPE.connection
Running 156 tasks using 4 parallel threads
1: CXX vm/builtin/constant_table.cpp
2: CXX vm/builtin/data.cpp
3: CXX vm/builtin/block_environment.cpp
4: CXX vm/builtin/compiled_code.cpp
In file included from /usr/lib/llvm-3.0/include/llvm/BasicBlock.h:18:0,
from /usr/lib/llvm-3.0/include/llvm/Function.h:23,
from /usr/lib/llvm-3.0/include/llvm/Module.h:18,
from /home/linus/prog/rubinius/vm/llvm/state.hpp:15,
from vm/builtin/block_environment.cpp:23:
@yxhuvud
yxhuvud / gist:679107b0edbb5bf2fcdb
Created September 21, 2014 18:33
stacktraces
The Rubinius process is aborting with signal: SIGSEGV
--- begin system backtrace ---
bin/rbx() [0x6574b9]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x10340) [0x7fc52c1f8340]
bin/rbx(_ZN8rubinius16GarbageCollector11scan_objectEPNS_6ObjectE+0x16c) [0x7071cc]
bin/rbx(_ZN8rubinius7BakerGC17handle_promotionsEv+0x34) [0x703264]
bin/rbx(_ZN8rubinius7BakerGC7collectEPNS_6GCDataEPNS_17YoungCollectStatsE+0x302) [0x703e82]
bin/rbx(_ZN8rubinius12ObjectMemory13collect_youngEPNS_5StateEPNS_6GCDataEPNS_17YoungCollectStatsE+0x7c) [0x644d2c]
bin/rbx(_ZN8rubinius12ObjectMemory13collect_maybeEPNS_5StateERNS_11GCTokenImplEPNS_9CallFrameE+0x23a) [0x6451ca]
bin/rbx(_ZN8rubinius2VM13collect_maybeERNS_11GCTokenImplEPNS_9CallFrameE+0x42) [0x6827d2]
"test".each_char do |char|
^~~~~~~~~
in ./test.cr:13: no overload matches 'Hash({Char | Symbol, Int32}, Item)#[]=' with types {Char, Int32}, Item
Overloads are:
- Hash({Char | Symbol, Int32}, Item)#[]=(key : {Char | Symbol, Int32}, value : Item)
foo[{char, 42}] = Item.new "foo"
^
@yxhuvud
yxhuvud / dig
Created November 12, 2016 15:54
class Hash
def dig(key : K, *args)
value = fetch(key, nil)
if args.size == 0 || value.nil?
return value
end
if value.responds_to?(:dig)
value.dig(*args)
else
raise ArgumentError.new
@yxhuvud
yxhuvud / errors..
Last active December 16, 2016 11:07
data = ['0', '1']
while data.size.even?
data = data.each_slice(2).map do |(a, b)|
a == b ? '1' : '0'
end
end
data
require "benchmark"
require "big"
struct Int
def binary_gcd(other)
u = self.abs
v = other.abs
shift = self.class.zero
return v if u == 0