Skip to content

Instantly share code, notes, and snippets.

View eregon's full-sized avatar

Benoit Daloze eregon

View GitHub Profile
@eregon
eregon / stats
Last active September 17, 2025 13:25
#!/usr/bin/env ruby
class Stats
def initialize(data)
@data = data
@sorted = data.sort
end
def size
@data.size
@kddnewton
kddnewton / json.rb
Last active December 18, 2024 17:34
JSON parser with pattern matching
require "json"
struct = { "a" => 1, "b" => 2, "c" => [1, 2, 3], "d" => [{ "e" => 3 }, nil, false, true, [], {}] }
source = JSON.dump(struct)
tokens = []
index = 0
until source.empty?
tokens <<
@eregon
eregon / inline_cext.rb
Created January 28, 2021 14:15
Mixing Ruby code and C extension code in a single file
require 'tmpdir'
require 'rbconfig'
def inline_c_extension(c_code)
Dir.mktmpdir('inline_c_extension') do |dir|
File.write("#{dir}/cext.c", c_code)
File.write("#{dir}/extconf.rb", <<~RUBY)
require 'mkmf'
create_makefile('cext')
RUBY
@eregon
eregon / 0_core_methods_in_ruby.md
Last active February 19, 2025 10:12
Core library methods defined with Ruby code and with a #source_location file starting with `<internal:`, by Ruby implementation and version
Ruby Core methods written in Ruby Total number of core methods % written in Ruby
CRuby 2.3 3 1637 0.2%
CRuby 2.4 3 1636 0.2%
CRuby 2.5 6 1680 0.4%
CRuby 2.6 5 1767 0.3%
CRuby 2.7 38 1802 2.1%
CRuby 3.0 89 1830 4.9%
CRuby 3.1 112 1884 5.9%
CRuby 3.2 128 1924 6.7%
@eregon
eregon / benchmark-block
Last active September 19, 2020 14:07
benchmark block - a prototype to benchmark a block without the block overhead
#!/usr/bin/env ruby
private def benchmark(name = nil, &block)
raise "needs a block" unless block
binding = block.binding
file, line = block.source_location
start_line = line - 1
lines = File.readlines(file)
indent = lines.fetch(start_line)[/^(\s+)/, 1]
@angela-d
angela-d / gpg-key-migration.md
Created April 1, 2018 23:57
Move GPG Keys from One Machine to Another

Migrate GPG Keys from One Workstation to Another

Replace [your key] with your key ID

To obtain your key ID

gpg --list-secret-keys --keyid-format LONG

Which returns something like

@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>
@k0kubun
k0kubun / benchmark_driver.optcarrot.log
Last active February 25, 2018 12:55
Optcarrot benchmark using benchmark_driver.gem: Intel 4.0GHz i7-4790K with 16GB memory under x86-64 Ubuntu 8 Cores
$ cat benchmark.yml
# Config for benchmark_driver.gem
type: command_stdout
name: optcarrot
command: bin/optcarrot --benchmark examples/Lan_Master.nes
metrics_type:
unit: fps
stdout_to_metrics: |
match = stdout.match(/^fps: (?<fps>\d+\.\d+)$/)
Float(match[:fps])
@chenxiaolong
chenxiaolong / DellXPS15_9560_AHCI_RAID.md
Created November 27, 2017 01:33
Switching between AHCI and RAID on the Dell XPS 15 (9560)

Switching between AHCI and RAID on the Dell XPS 15 (9560)

This guide likely applies to other models and, potentially, even laptops from other OEMs that have NVME drives. However, I've only tested this on my Dell XPS 15 (9560) with the OEM Windows installation from the Signature Edition model.

Switching from RAID to AHCI

Switching from RAID to AHCI is significantly simpler than switching from AHCI to RAID. All that's needed is a successful boot to Safe Mode.

  1. To set the default boot mode to Safe Mode, use msconfig.exe or open an admin cmd/PowerShell window and run:
@pierrejoubert73
pierrejoubert73 / markdown-details-collapsible.md
Last active December 11, 2025 07:53
How to add a collapsible section in markdown.

How to add a collapsible section in markdown

1. Example

Click me

Heading

  1. Foo
  2. Bar
    • Baz
  • Qux