Skip to content

Instantly share code, notes, and snippets.

View olbat's full-sized avatar

Luc Sarzyniec olbat

View GitHub Profile
@olbat
olbat / features-histogram.py
Last active November 24, 2017 09:56
Python3 matplotlib script that plots histograms for features of an ML corpus
#!/usr/bin/env python3
"""
usage: {} < corpus.json > plot.pdf
The corpus file must contain one JSON document per line,
features must be stored in a field names "{}",
classes in a field names "{}".
"""
import sys
@olbat
olbat / time_measure.rb
Last active November 10, 2017 10:18
Ruby time measurement (monotonic)
module Time::Measure
refine Time.singleton_class do
def measure(&_block)
tstart = Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield if block_given?
(Process.clock_gettime(Process::CLOCK_MONOTONIC) - tstart)
end
end
end
@olbat
olbat / process_kill_recursive.rb
Last active October 21, 2017 07:29
Ruby recursive Process.kill
module Process::KillRecursive
refine Process.singleton_class do
def children(pid)
pids = nil
if RbConfig::CONFIG['host_os'] =~ /linux/i
if File.exist?("/proc/#{pid}/task/#{pid}/children")
pids = File.read("/proc/#{pid}/task/#{pid}/children").split(/\s/)
end
elsif !Gem.win_platform?
pids = `ps --ppid #{pid} -o pid=`.split("\n")
@olbat
olbat / break_iterator_bench.cr
Created May 19, 2017 13:32
Small BreakIterator benchmark for icu.cr
require "benchmark"
require "./src/icu"
REPEAT=1_000
# from https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt
samples = [] of String
samples << <<-EOS
Σὲ γνωρίζω ἀπὸ τὴν κόψη
τοῦ σπαθιοῦ τὴν τρομερή,
@olbat
olbat / ruby_collapse_nested_module_defs.rb
Last active May 5, 2017 11:50
Ruby script that rewrite source code collapsing nested modules definitions
src = STDIN.read
# iterate on "1st level" module definitions
src.dup.scan(/^module [^;]+$.+?^end/m) do |mod|
# get the nested modules' definitions
mdefs = mod.scan(/^ *module [^\n]+$(?=\n +module)/m).map(&:to_s)
# stop if there is no nested module definition
next if mdefs.empty?
ndefs = mdefs.size
# get the last definition that's not extracted because of the look ahead
@olbat
olbat / icu_info.cr
Last active May 5, 2017 00:53
A Crystal program that returns information about the ICU install
require "xml"
require "c/dlfcn"
PKGNAME = "icu-uc"
TESTFUNC = "u_init"
{% if flag?(:darwin) %}
SOFILE = "libicuuc.dylib"
{% elsif flag?(:windows) %}
SOFILE = "libicuuc.dll"
{% else %}
@olbat
olbat / keybase.md
Created January 26, 2017 13:13
keybase.md

Keybase proof

I hereby claim:

  • I am olbat on github.
  • I am olbat (https://keybase.io/olbat) on keybase.
  • I have a public key whose fingerprint is D1CC 3AE0 5ADA FF27 BEE6 27B7 0B1A 5390 865E 24D7

To claim this, I am signing this object:

@olbat
olbat / Makefile
Created September 19, 2011 12:39
GNU/Linux Kernel module sample that read the current time on the RTC chip
obj-m += realtimeclock.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -c /lib/modules/$(shell uname -r)/build M=$(PWD) clean
@olbat
olbat / portscanner.c
Created September 19, 2011 12:14
Scan a specific machine to see which ports it's listening on
/*
* Copyright (C) 2006, 2007 Sarzyniec Luc <mail@olbat.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@olbat
olbat / printfile.c
Created September 19, 2011 12:03
Allow you to print (binary) files in a formated and readable output
/*
* Copyright (C) 2006, 2007 Sarzyniec Luc <mail@olbat.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of