Skip to content

Instantly share code, notes, and snippets.

View fcaylus's full-sized avatar

Fabien Caylus fcaylus

  • 12:49 (UTC +02:00)
View GitHub Profile
use num_traits::cast::ToPrimitive;
use num_traits::{abs, Pow, Zero};
use num_traits::real::Real;
// Formula from https://en.wikipedia.org/wiki/SRGB#From_sRGB_to_CIE_XYZ
pub fn srgb_to_cie_xyz(r: u8, g: u8, b: u8) -> (f64, f64, f64) {
fn value_to_linear(value: &f64) -> f64 {
if *value < 0.04045 {
*value / 12.92
} else {
@fcaylus
fcaylus / JsonToSmileEncoding.kt
Created September 20, 2021 08:27
JSON to Smile encoding in Kotlin
val json = "{\"a\":1}"
val builder = SmileXContent.contentBuilder()
val parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json)
builder.copyCurrentStructure(parser)
Files.write(Paths.get("test.sml"), BytesReference.toBytes(BytesReference.bytes(builder)))
lewis => blue jeans, red pants
medical, medic => emergency
@fcaylus
fcaylus / useful-commands.sh
Created May 18, 2020 11:51
Bash useful commands
# List top 20 biggest files/directory
sudo du -a / | sort -n -r | head -n 20
@fcaylus
fcaylus / cstringutil.h
Last active July 14, 2017 16:39
CStringUtil
// Returns true if str contains c
constexpr bool contains(const char* str, const char *c)
{
return (*str == 0) ? false : (str[0] == *c ? true: contains(++str, c));
}
constexpr int countOccurences(char* str, char* c)
{
return (*str == 0) ? 0 : (str[0] == *c ? 1 + countOccurences(++str, c) : countOccurences(++str, c));
}
@fcaylus
fcaylus / commands.sh
Last active February 23, 2017 18:29
Usefull commands
#############################################
# Windows
#############################################
# Compute a MD5 Hash
certutil -hashfile C:\path\to\file MD5
#############################################
# Linux
# -*- coding: utf-8 -*-
#
# Change a specified color to an another one for all *.png files in current dir
#
import glob
import numpy as np
from PIL import Image
# Original values
# -*- coding: utf-8 -*-
import tkinter as tk
import threading
class App(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.start()
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import matplotlib
matplotlib.use('TkAgg')
import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
# implement the default mpl key bindings
from matplotlib.backend_bases import key_press_handler
@fcaylus
fcaylus / common.py
Last active April 15, 2016 14:52
Common python functions
def isPrime(n):
""" All primes number greater than 3 can be expressed in the form 6k +/- 1 """
if n <= 0 or n == 1:
return False
elif n < 4: # Handle 2 and 3
return True
elif n%2==0:
return False
elif n < 9: # 4,6,8 are already excluded
return True