Skip to content

Instantly share code, notes, and snippets.

View juchiast's full-sized avatar

Duy Do juchiast

View GitHub Profile
@juchiast
juchiast / linear_regression.py
Created May 8, 2017 13:52
Approximating hidden function using scikit-learn linear regression model
import numpy as np
from sklearn.linear_model import LinearRegression
def f(x):
return 1 + 0.87*x[0] + 0.34*x[1] + 0.5*x[2]
X = np.random.random((2000, 3)) * 100
y = [f(x) for x in X]
lm = LinearRegression()
@juchiast
juchiast / screen.rs
Last active May 8, 2017 14:23
Automatically change linux background with feh
extern crate rand;
use ::std::path::PathBuf;
fn random(low: u64, high: u64) -> u64 {
low + rand::random::<u64>() % (high-low)
}
fn get_images_list(dir: &PathBuf) -> Vec<PathBuf> {
let paths: Vec<_> = std::fs::read_dir(dir).unwrap()
@juchiast
juchiast / rgb2lab.py
Last active April 28, 2017 05:56
Conver RGB to CIELab using D65 whitepoint
def rgb2lab (RGB):
for value in RGB:
value = value / 255
if value > 0.04045:
value = ((value + 0.055) / 1.055) ** 2.4
else:
value = value / 12.92
XYZ = [0, 0, 0]
XYZ[0] = (RGB[0] * 0.4124 + RGB[1] * 0.3576 + RGB[2] * 0.1805) / 95.047
XYZ[1] = (RGB[0] * 0.2126 + RGB[1] * 0.7152 + RGB[2] * 0.0722) / 100
/*
The MIT License (MIT)
Copyright (c) 2017 Do Duy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@juchiast
juchiast / thtrr5.7.rs
Last active March 27, 2017 14:20
TH Toán rời rạc bài 5.7
/*
The MIT License (MIT)
Copyright (c) 2017 Do Duy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is