Skip to content

Instantly share code, notes, and snippets.

PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE list (id VARCHAR(64) NOT NULL, value VARCHAR(64) NOT NULL, PRIMARY KEY(id));
INSERT INTO list VALUES('AF','Afghanistan');
INSERT INTO list VALUES('AL','Albania');
INSERT INTO list VALUES('DZ','Algerie');
INSERT INTO list VALUES('AS','Amerikansk Samoa');
INSERT INTO list VALUES('AD','Andorra');
INSERT INTO list VALUES('AO','Angola');
INSERT INTO list VALUES('AI','Anguilla');
@kirs
kirs / vrep.rb
Created July 27, 2021 09:54
scrappy ruby script to manage vreplication streams
# ruby version of https://github.com/vitessio/contrib/blob/master/vreplgen/vreplgen.go
require 'shellwords'
require 'json'
# Grab your tablet ID with `vtctlclient ListAllTablets zone1`
TABLET_ID = 'zone1-0428408676'
VTCTLD_ADDR = 'localhost:15999'
def list_all
@kirs
kirs / why.md
Created February 1, 2021 07:51
Top level method
def handler(event:, context:)
  "Hello, world!"
end

While this code appears straightforward, it’s important to remember what it actually does. It adds this “function” as a private method on the Object class, the base class of the Ruby class hierarchy. In other words, the “function” has been added to nearly every object in the Ruby virtual machine. (Unless, of course, the application changes the main object and class context when loading the file, a technique that carries other risks.) At best, this breaks encapsulation and single responsibility. At worst, it risks interfering with the functionality of your application, its dependencies, or even the Ruby standard library. This is why such “top level” methods, while common in simple single-file Ruby scripts and Rakefiles, are not recommended in larger Ruby applications.

From https://daniel-azuma.com/blog/2021/01/20/designing-a-ruby-serverless-runtime

require 'webrick'
# How much of this is solved by frozen string literal?
Ractor.make_shareable(WEBrick::Config::HTTP)
Ractor.make_shareable(WEBrick::LF)
Ractor.make_shareable(WEBrick::CRLF)
Ractor.make_shareable(WEBrick::HTTPRequest::BODY_CONTAINABLE_METHODS)
Ractor.make_shareable(WEBrick::HTTPStatus::StatusMessage)
# To pick up changes from https://github.com/ruby/ruby/pull/4007
Object.send(:remove_const, :URI)
class MassProcessThingsJob < ApplicationJob
  extend SequentialPerform
  perform_sequentially(enum_argument: 0, batch_size: 200, jitter_delay: 1..60)

  def perform(ids_of_things)
    # ...
  end
end
use futures::stream::StreamExt;
use rand::Rng;
use std::collections::VecDeque;
use std::net::SocketAddr;
use std::thread;
use tokio::net::TcpListener;
use tokio::net::TcpStream;
use tokio::prelude::*;
use tokio::runtime::Runtime;
use tokio::sync::mpsc::channel;
@kirs
kirs / queuing.rb
Created April 20, 2020 15:00 — forked from sirupsen/queuing.rb
Queuing theory exercise
class Node
attr_accessor :edges, :jobs, :id
def initialize(id, arrivals_per_tick)
@id = id
@jobs = 0.0
@tick = 0
@edges = []
@arrivals_per_tick = arrivals_per_tick
end
FROM ubuntu:bionic
ENV DEBIAN_FRONTEND=noninteractive
# tools you need to build MRI
RUN apt-get update && apt-get install -y tzdata git ruby autoconf bison gcc make zlib1g-dev libffi-dev libreadline-dev libgdbm-dev libssl-dev build-essential
#define _GNU_SOURCE
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main(int argc, char *argv[])
{
int i, ret;
require 'net/http'
require 'socket'
# to run on Ubuntu/Debian with sudo access
def with_unresponsive_dns
fake_dns_ip = "127.0.0.1"
th = Thread.new do
server = UDPSocket.new
server.bind(fake_dns_ip, 53)
server.recvfrom(16)