Skip to content

Instantly share code, notes, and snippets.

View yxhuvud's full-sized avatar

Linus Sellberg yxhuvud

View GitHub Profile
def shuffle(arr)
xs = 0xdeadbeef_u32
arr.size.times do |i|
xs ^= xs << 13
xs ^= xs >> 17
xs ^= xs << 5
j = xs % (i + 1)
arr[i], arr[j] = arr[j], arr[i]
end
end
@yxhuvud
yxhuvud / keybase.md
Created April 19, 2022 14:53
keybase.md

Keybase proof

I hereby claim:

  • I am yxhuvud on github.
  • I am yxhuvud (https://keybase.io/yxhuvud) on keybase.
  • I have a public key ASAW4peGXvEbn2Nta19DfXLsDLBmXzHLrN1NxHL7iM1PiAo

To claim this, I am signing this object:

module LinkedList(T)
macro included
include Enumerable(T)
property _next, _prev : T | Nil
end
def append(node : T)
node.next = @_next
node.prev = self
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
@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
@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
"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 / 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]
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:
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