Skip to content

Instantly share code, notes, and snippets.

View v-kolesnikov's full-sized avatar
✍️
I'm writing something just now! You can write me too! 😉

Vasily Kolesnikov v-kolesnikov

✍️
I'm writing something just now! You can write me too! 😉
View GitHub Profile

ROM-SQL and serialized YAML data

New projects that use rom-db interact with existing db schemas quite often, especially with schemas that are built on top of Rails applications. And you can probably came across to a serialized YAML data here. ActiveRecord provides API to store unstructured key-value data into single database column with serialize method:

# Serialize preferences as Hash using YAML coder.
class User < ActiveRecord::Base
  serialize :preferences, Hash
end
@v-kolesnikov
v-kolesnikov / timezone_helper.rb
Created March 8, 2018 19:57
Ruby timezone invariable tests
require 'faker'
RSpec.configure do |config|
config.before do
ENV['TZ'] = Faker::Address.time_zone
end
end
@v-kolesnikov
v-kolesnikov / Vagrantfile
Last active April 18, 2018 09:48
Nomad sandbox
# frozen_string_literal: true
# -*- mode: ruby -*-
# vi: set ft=ruby :
script = <<~SCRIPT
# Update apt and get dependencies
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y unzip curl vim \
apt-transport-https \
{
"title": "Diamond Cursor",
"rules": [
{
"description": "Change fn + I/J/K/L to Arrow Keys",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "i",
@v-kolesnikov
v-kolesnikov / latency.txt
Created November 10, 2017 14:52 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD

Keybase proof

I hereby claim:

To claim this, I am signing this object:

LLDB Cheat Sheet

A complete gdb to lldb command map.

Print out

  • Print object
(lldb) po responseObject
(lldb) po [responseObject objectForKey@"state"]
  • p - Print primitive type
require 'rom'
require 'rom-repository'
require 'sqlite3'
rom = ROM.container(:sql, 'sqlite::memory') do |conf|
conf.default.create_table(:bookings) do
primary_key :book_ref
end
conf.default.create_table(:tickets) do
class Jobs < ROM::Relation[:sql]
schema(:jobs) do
# ...
associations do
belongs_to :team
belongs_to :template
belongs_to :address
belongs_to :client
end
@v-kolesnikov
v-kolesnikov / _post.md
Created April 17, 2017 10:23 — forked from klapaucius/_post.md
spine-strict_lists

Строгость и нищета списков.

Map и структурная рекурсия.

Применить функцию к каждому элементу списка - это просто: ###GHC/Base.lhs

map _ []     = []
map f (x:xs) = f x : map f xs