Skip to content

Instantly share code, notes, and snippets.

@iliabylich
iliabylich / bench.c
Created May 7, 2024 08:02
prism bench
// usage:
// 1. build prism
// 2. clang bench.c -O3 -Lbuild -lprism -Iinclude -o bench
// 3. ./bench /path/to/dir/with/ruby/code
#include "include/prism.h"
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
@iliabylich
iliabylich / recursive_json_parser.rb
Last active October 29, 2020 01:11
recursive json parser
require 'strscan'
class Result
class Ok < self
def or(&block)
self
end
def and(&block)
chained = block.call(value)
#!/usr/bin/env ruby
require 'bundler/setup'
require 'parser/current'
require 'pry'
def each_file
return to_enum(:each_file) unless block_given?
Dir['app/**/*.rb'].sort.each { |f| yield f }
@iliabylich
iliabylich / 1.rb
Last active November 20, 2018 00:04
code samples from lecture
class Point
attr_reader :x, :y
def initialize(x ,y)
@x = x
@y = y
end
def [](attribute_name)
case attribute_name
# frozen_string_literal: true
# Cache store that gets automatically expired after each request
#
# @example
# UsersCache = RequestStore::Cache.new(namespace: 'users')
# UsersCache.read(:user1)
# # => nil
# UsersCache.fetch(:user1) { User.find(1) }
# # => #<User id:1 ...>
./configure
alias dev-ruby-rebuild="make DESTDIR=./ruby_build uninstall && make && make DESTDIR=./ruby_build install"
alias dev-ruby="./ruby_build/usr/local/bin/ruby -I ./ruby_build/usr/local/lib/ruby/2.5.0 -I ./ruby_build/usr/local/lib/ruby/2.5.0/x86_64-darwin17"
alias dev-irb="dev-ruby -e 'binding.irb'"
@iliabylich
iliabylich / parslet_json_parser.rb
Created June 29, 2017 16:21
parslet_json_parser
require 'parslet'
require 'json'
class JSONParser < Parslet::Parser
rule(:object) { str('{') >> spaces? >> object_content.maybe.as(:object) >> spaces? >> str('}') }
rule(:object_content) { (kv_pair >> (comma >> kv_pair).repeat).maybe }
rule(:kv_pair) { (key.as(:key) >> spaces? >> str(':') >> spaces? >> value.as(:value)).as(:kv_pair) }
rule(:key) { string }
rule(:value) { string | float | integer | object | array | _true | _false | null }
rule(:string) { str('"') >> (str('"').absent? >> any).repeat.as(:string) >> str('"') }
# racc json_parser.rb -o out.rb -v -g && ruby -rpry -rstrscan out.rb
class JsonParser
token tDOT tQUOTE
tLCURLY tRCURLY
tLBRACK tRBRACK
tCOMMA tCOLON
tSTRING tNUMBER
kTRUE kFALSE kNULL
rule
@iliabylich
iliabylich / 1runner.rb
Created October 13, 2015 13:27
opal tz
# gem install activesupport
# runner.rb | sh
require 'active_support/values/time_zone'
ActiveSupport::TimeZone::MAPPING.values.each do |zone|
puts "TZ=#{zone} opal -e 'print \"#{zone}: \"; puts Time.at(9999999).yday'"
end
@iliabylich
iliabylich / install.sh
Last active October 7, 2015 11:24
handlersocket installation
apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
echo "deb http://repo.percona.com/apt trusty main" > /etc/apt/sources.list.d/percona.list
echo "deb-src http://repo.percona.com/apt trusty main" >> /etc/apt/sources.list.d/percona.list
apt-get update
apt-get install -y percona-server-server-5.6
mysql -e "CREATE FUNCTION fnv1a_64 RETURNS INTEGER SONAME 'libfnv1a_udf.so'"
mysql -e "CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'libfnv_udf.so'"
mysql -e "CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME 'libmurmur_udf.so'"