Skip to content

Instantly share code, notes, and snippets.

View olbat's full-sized avatar

Luc Sarzyniec olbat

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / plot-histograms.py
Last active March 19, 2018 10:41
Python3 matplotlib script that plots histograms with data from text files (one number per line)
#!/usr/bin/python3
"""
usage: {} title data.txt [data2.txt ...] > histogram.png
"""
import sys
import math
import os.path
import matplotlib
matplotlib.use('Agg')
@olbat
olbat / strpreprocess.py
Last active March 20, 2018 09:30
Python string pre-processing for ML
#!/usr/bin/python3
import sys
import unicodedata
import regex # https://pypi.python.org/pypi/regex/
SPECIAL_CHARS = r"\-'" # FIXME: French specific
RE_WHITESPACES = regex.compile(r"\p{Zs}+")
RE_SENTENCE_TERMS = regex.compile(r" *\p{STerm}+ *")
@olbat
olbat / crypto-week-one.md
Created August 9, 2018 14:09 — forked from siddMahen/crypto-week-one.md
Coursera cryptography lecture notes, from week one.

Crypto Notes Week 1

The first half of the course will be about sym. enc. and the second half will be about public key enc.

Introduction and Prereqs

What is cryptography?

The core of cryptography is about:

  • establishing a secret key between two parties