Skip to content

Instantly share code, notes, and snippets.

View eregon's full-sized avatar

Benoit Daloze eregon

View GitHub Profile
require 'benchmark'
N = 10_000_000
def foo(a: 1)
a
end
10.times do
p Benchmark.realtime {
require 'ffi'
class S < FFI::Struct
layout :next, :pointer
end
p S.new[:next] # <Pointer address=0x0>
if defined?(Rubinius)
p Rubinius
require 'csv'
require 'benchmark'
dir = "data"
Dir.mkdir(dir) unless Dir.exist?(dir)
input = "#{dir}/extract.csv"
unless File.exist?(input)
Dir.chdir(dir) do
i = ARGF.read
s=[]
S=/"(?:\\["\\\/bfnrtu]|[^"\\])*"/
while i[S];s<<$`<<$&;i=$';end
s<<i
I=s.each{|e|e.gsub!(/\s+/,'')if e[0]!=?"}.join
G=/
(?<obj>\{(?:\g<pair>(?:,\g<pair>)*)?\}){0}
@eregon
eregon / common.h
Last active May 23, 2018 09:37
A collection of extconf.h for the OpenSSL Ruby C extension
#ifndef EXTCONF_H
#define EXTCONF_H
#define HAVE_OPENSSL_SSL_H 1
#define HAVE_SSLV3_METHOD 1
#define HAVE_TLSV1_1_METHOD 1
#define HAVE_TLSV1_2_METHOD 1
#define HAVE_ENGINE_LOAD_BUILTIN_ENGINES 1
#define HAVE_ENGINE_LOAD_DYNAMIC 1
#define HAVE_ENGINE_LOAD_CRYPTODEV 1
#define HAVE_EVP_CIPHER_CTX_NEW 1
@eregon
eregon / precise_time.c
Last active September 22, 2019 13:44
A variant of time(1) to measure startup precisely, able to show real time in milliseconds and max RSS in MB. Moved to https://github.com/eregon/precise-time
#include <sys/time.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <spawn.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
require 'benchmark/ips'
class Array
def to_proc
if self[0].is_a? Symbol
method, *arguments = self
-> receiver { receiver.send method, *arguments }
elsif self[1].is_a? Symbol
receiver, method, *arguments = self
-> argument { receiver.send method, argument }
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
public class Main {
public static final Map<String, Integer> MAP = new ConcurrentHashMap<>();
public static void main(String[] args) {
int n = Integer.parseInt(args[args.length - 1]);
NP = 5
ROW = 8 + NP
COL = 8
$p = []
$b = []
$no = 0
def piece(n, a, nb)
nb.each{|x|
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
void on_signal(int sig) {
printf("\nIN handler\n");
//nothing
}