Skip to content

Instantly share code, notes, and snippets.

View felixyz's full-sized avatar

Felix Holmgren felixyz

View GitHub Profile
@felixyz
felixyz / Intro to Common Table Expressions.md
Last active December 22, 2023 12:23
Introduction to transitive closure / Common Table Expressions / iterative queries in SQL

Teh Social Netswork!

CREATE TABLE users (
 id SERIAL PRIMARY KEY,
 name VARCHAR(10) NOT NULL
);

INSERT into users VALUES

@felixyz
felixyz / converter.rb
Last active May 23, 2020 18:40
dry-validation form => json schema
module DryJsonSchema
# Transforms a dry-validation form to json-schema-compatible objects (hash or array)
# Usage:
# DryJsonSchema::Converter.(my_form)
# => { :type => :object,
# :properties => { :abc => { :type => :integer },
# :xyz => { :type => :integer }
# },
# :required => [:abc]}
class Converter
@felixyz
felixyz / gist:329cdecebbd73d001005cdf530877cb5
Created May 20, 2018 21:49
pakcs-2.0.1 install failure log (OS X)
/Applications/Xcode.app/Contents/Developer/usr/bin/make config 2>&1 | tee -a make.log
cd scripts && /Applications/Xcode.app/Contents/Developer/usr/bin/make all
/Applications/Xcode.app/Contents/Developer/usr/bin/make /Users/felix/code/pakcs-2.0.1/bin/pakcs /Users/felix/code/pakcs-2.0.1/bin/pakcs-makecgi /Users/felix/code/pakcs-2.0.1/bin/cleancurry /Users/felix/code/pakcs-2.0.1/bin/pakcs-fcypp
mkdir -p /Users/felix/code/pakcs-2.0.1/bin
cat pakcs.sh | sed "s|^PAKCSBUILDDIR=.*$|PAKCSBUILDDIR=/Users/felix/code/pakcs-2.0.1|" | \
sed "s|^PAKCSINSTALLDIR=.*$|PAKCSINSTALLDIR=|" > /Users/felix/code/pakcs-2.0.1/bin/pakcs
chmod 755 /Users/felix/code/pakcs-2.0.1/bin/pakcs
mkdir -p /Users/felix/code/pakcs-2.0.1/bin
cat pakcs-makecgi.sh | sed "s|^PAKCSBUILDDIR=.*$|PAKCSBUILDDIR=/Users/felix/code/pakcs-2.0.1|" | \
sed "s|^PAKCSINSTALLDIR=.*$|PAKCSINSTALLDIR=|" > /Users/felix/code/pakcs-2.0.1/bin/pakcs-makecgi
@felixyz
felixyz / impuzzable.pi
Created November 26, 2017 21:24
Impuzzable in Picat
% Impuzzable
% https://nrich.maths.org/1388
import cp.
import util.
main =>
puzzle(Pieces),
time2(Arrangements = find_all_arrangements(Pieces)),
```
commit
[#world tick: 0]
[#time #system/timer resolution: 1000]
[#thing value: 1 delta: 1]
```
Update
~~~
search
@felixyz
felixyz / item_insert_benchmark.rb
Created September 16, 2013 15:40
Compares speed of two different methods of inserting items in an array.
require 'benchmark'
def insert_then_sort(results, missing_items)
missing_items.each do |id|
results << {id: id, val: nil}
end
results.sort_by!{|item| item[:id] }
results
end
@felixyz
felixyz / gist:5788285
Created June 15, 2013 14:15
Creating and running >120 Celluloid::IO actors raises an error on MRI, even when doing NO I/O
# Running on OS X
# JRuby + Celluloid = OK
# MRI + Celluloid = OK
# JRuby + Celluloid::IO = OK
# MRI + Celluloid::IO = Too many open files - pipe (Errno::EMFILE)
require 'celluloid/io'
class SimpleActor
# include Celluloid # Creating regular Celluloid actors works on MRI
@felixyz
felixyz / gist:5788375
Created June 15, 2013 14:44
MRI pipe limit (on OS X). This script fails on my Mac after creating 125 x 2 pipe endpoints, raising "Too many open files (Errno::EMFILE)" This is the cause of the problem illustrated here: https://gist.github.com/Felixyz/5788285
wakeups = []
wakers = []
puts "Creating pipes..."
200.times do |n|
puts "[#{n}]"
wakeup, waker = IO.pipe
wakeups << wakeup
wakers << waker
@felixyz
felixyz / celluloid_redis_bug.rb
Last active December 18, 2015 10:59
This illustrates celluloid-redis issue #9: https://github.com/celluloid/celluloid-redis/issues/9 A repo containing the below code and branches with variations that variously provoke the same bug or not can be found here: https://github.com/Felixyz/celluloid-redis-bug
require 'thread'
require 'celluloid/io'
require 'celluloid/redis'
KEY = "magic_key"
VALUE = {a: 1, b:2}
class RedisActor
include Celluloid::IO
@felixyz
felixyz / gist:5679768
Created May 30, 2013 17:57
Use Queue to keep synchronous interface while performing work in parallel. Queue is thread-safe, and extremely easy to use!
require 'thread'
def provider()
threads = []
queue = Queue.new
1.upto(10).each do |n|
threads << Thread.new {
sleep rand(0.1..2)
queue << n
}