Skip to content

Instantly share code, notes, and snippets.

View omg.md
class MassProcessThingsJob < ApplicationJob
  extend SequentialPerform
  perform_sequentially(enum_argument: 0, batch_size: 200, jitter_delay: 1..60)

  def perform(ids_of_things)
    # ...
  end
end
View main.rs
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 Apr 20, 2020 — forked from sirupsen/queuing.rb
Queuing theory exercise
View queuing.rb
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
View Dockerfile
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
View getaddr.c
#define _GNU_SOURCE
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main(int argc, char *argv[])
{
int i, ret;
View getaddrinfo_interrupt.rb
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)
View resolv_timeout.rb
require 'net/http'
require 'socket'
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)
sleep
end
View gist:bc6215a358578d6f4e395a2dcab4ccc5
int deserialize_String_vector(struct iarchive *in, const char *tag, struct String_vector *v)
{
int rc = 0;
int32_t i;
rc = in->start_vector(in, tag, &v->count);
v->data = calloc(v->count, sizeof(*v->data));
for(i=0;i<v->count;i++) {
rc = rc ? rc : in->deserialize_String(in, "value", &v->data[i]);
}
rc = in->end_vector(in, tag);
View shopify_deadlines.rb
class Deadline
def self.current=(value)
ActiveRecord::Base.deadline = value
end
def initialize(duration_seconds)
@deadline = now + duration_seconds.to_i
end
def extend_deadline(duration_seconds)
View omg.rb
# frozen_string_literal: true
require 'benchmark/ips'
require 'securerandom'
str = "#{SecureRandom.alphanumeric(1000)} SUBSTR"
Benchmark.ips do |x|
x.config(:time => 5, :warmup => 2)
x.report("=~") do |t|
100.times do
You can’t perform that action at this time.