This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lewis => blue jeans, red pants | |
medical, medic => emergency |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List top 20 biggest files/directory | |
sudo du -a / | sort -n -r | head -n 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################# | |
# Windows | |
############################################# | |
# Compute a MD5 Hash | |
certutil -hashfile C:\path\to\file MD5 | |
############################################# | |
# Linux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import tkinter as tk | |
import threading | |
class App(threading.Thread): | |
def __init__(self): | |
threading.Thread.__init__(self) | |
self.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder