Skip to content

Instantly share code, notes, and snippets.

View juchiast's full-sized avatar

Duy Do juchiast

View GitHub Profile
@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
/*
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 / 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
@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 / 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 / tmux.conf
Created May 26, 2017 13:30
My tmux configuration
# unbind all key
unbind -a
# start new session without login shell
set -g default-command bash
# allows faster key repetition
set -s escape-time 0
# copy-paste
@juchiast
juchiast / karatsuba.rs
Last active November 27, 2020 01:27
Karatsuba algorithm implemented in Rust
const B: u64 = 1000000000; // Base
const SIZE: usize = 9; // Digit size
const M: [u64; SIZE] = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000];
fn alloc(n: usize) -> Vec<u64> {
let mut r = Vec::with_capacity(n);
r.resize(n, 0);
r
}
@juchiast
juchiast / Cargo.toml
Last active December 22, 2017 14:13
Rename files with Rust
[package]
name = "jslife"
version = "0.1.0"
authors = ["Do Duy"]
[dependencies]
walkdir = "2.0"
#!/usr/bin/env python
"""A simple starfield example. Note you can move the 'center' of
the starfield by leftclicking in the window. This example show
the basics of creating a window, simple pixel plotting, and input
event management"""
import random, math, pygame
from pygame.locals import *
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
struct point {
double x, y;
};
bool cmp_x(const point &a, const point &b) {