Skip to content

Instantly share code, notes, and snippets.

View fl00r's full-sized avatar

Peter Yanovich fl00r

View GitHub Profile
@fl00r
fl00r / trie.lua
Created October 28, 2016 11:17
Trie
properties = box.schema.space.create('properties')
properties:create_index('primary', {parts = {1, 'str'}, type = 'HASH', unique = true, if_not_exists = true})
properties:replace({'node_id', 0})
nodes = box.schema.space.create('nodes')
nodes:create_index('primary', {parts = {1, 'num', 2, 'str'}, type = 'TREE', unique = true, if_not_exists = true})
function load_words()
local words = "/opt/dict/words"
for line in io.lines(words) do
@fl00r
fl00r / quartz_jdbc_store.sql
Last active August 29, 2015 14:26 — forked from ajbrown/quartz_jdbc_store.sql
The following script creates the schema required to use Postgres as the JDBC store for clustering Quartz. This was tested on Quartz 2.2.1 in Postgres 9.1 and 9.3
DROP TABLE qrtz_blob_triggers;
DROP TABLE qrtz_calendars;
DROP TABLE qrtz_cron_triggers;
DROP TABLE qrtz_fired_triggers;
DROP TABLE qrtz_job_details CASCADE;
DROP TABLE qrtz_locks;
DROP TABLE qrtz_paused_trigger_grps;
DROP TABLE qrtz_scheduler_state;
DROP TABLE qrtz_simple_triggers;
DROP TABLE qrtz_simprop_triggers;
small = (1..10).to_a
big = (1..5_000).to_a
Fiber.new do
puts "It's ok"
puts *small
puts "It is not ok"
puts *big
end.resume
class Player
def play_turn(warrior)
@max_health ||= warrior.health
case state(warrior)
when :lost
warrior.pivot!
when :captive
warrior.rescue!
when :enemyfar
@fl00r
fl00r / gist:7542994
Created November 19, 2013 09:56
Trie-like pure fuzzy search implementation on Ruby
class TrieDict
attr_reader :dict
def initialize
@dict = {}
end
def put(str)
d = nil
str.chars.each do |c|
@fl00r
fl00r / gist:5955566
Last active December 19, 2015 12:29
require 'rack/utils'
run proc{
res = "Hello World"
headers = Rack::Utils::HeaderHash.new
headers["Connection"] = "close"
headers["Content-Length"] = res.bytesize.to_s
headers["Access-Control-Allow-Origin"] = [ "http://mir.mail.ru", "http://my.mail.ru" ]
[200, headers, [res] ]
@fl00r
fl00r / gist:5955527
Created July 9, 2013 08:00
Simple rack app
run proc{
res = "Hello World"
[
200,
{
"Connection" => "close",
"Access-Control-Allow-Origin" => [ "http://domain1.com", "http://domain2.com" ] * "\n",
"Content-Length" => res.bytesize.to_s
},
[res]
@fl00r
fl00r / gist:5427088
Last active December 16, 2015 11:28
class Foo
def Foo.bar
end
class << Foo
def baz
end
end
end
# Ruby
module App
extend self
def call(env)
[
200,
{ 'Content-Type' => 'application/json' },
['{"message": "Hello World"}']
]
@fl00r
fl00r / gist:4203478
Last active October 13, 2015 13:37
Truncating CouchBase. Facepalm
module Helpers
module Truncate
def teardown
teardown_couch
end
def teardown_couch
helpers = connection.design_docs["helpers"]
unless helpers && helpers.views.include?("truncate")
create_view