Skip to content

Instantly share code, notes, and snippets.

View joonas-yoon's full-sized avatar
🎃
Focusing

Joona Yoon joonas-yoon

🎃
Focusing
View GitHub Profile
@joonas-yoon
joonas-yoon / value x to rgb
Last active May 9, 2023 08:31
f(x) = [r, g, b] ; from (1, 0, 0) to (0, 1, 0) to (0, 0, 1) for 0 <= x <= 1
def vec3(x):
return [
max(0.0, min(1.0 - 2.0*x, 1.0)),
abs(1.0 - abs(2.0*x - 1.0)),
max(0.0, min(2.0*x - 1.0, 1.0))
]
for i in range(100+1):
x = i/100
print(x, vec3(x))
@joonas-yoon
joonas-yoon / print_json_as_tree.py
Last active September 24, 2020 05:30
Python print json as tree
import sys
sys.setrecursionlimit(10 ** 6)
def is_json(json):
return type(json) == type({})
def is_list(lst):
return type(lst) == type([])
HTML
- Semantic HTML
- Event delegation
- Accessibility / ARIA
CSS
- Specificity
- Pseudo-elements
- Pseudo-selectors
- Combinators
@joonas-yoon
joonas-yoon / vector.cpp
Created March 19, 2020 08:07
alternative for STL (vector)
template<typename T>
class vector {
public:
vector(int capacity = 4) {
_a = new T[capacity]();
_cap = _size = capacity;
}
vector(int capacity, const T value) {
_a = new T[capacity]();
_cap = _size = capacity;
@jonaskirch
jonaskirch / react-root-importer.txt
Last active September 11, 2022 10:39
react root importer
STEP 1 (override webpack generated default by create-react-app and to add babel-plugin-root-import):
yarn add customize-cra react-app-rewired -D
yarn add babel-plugin-root-import -D
add file config-overrides.js:
const { addBabelPlugin, override } = require('customize-cra');
module.exports = override(
addBabelPlugin([
'babel-plugin-root-import',
@joonas-yoon
joonas-yoon / segment-tree.cpp
Last active August 3, 2023 08:10
Efficient and easy segment tree
// Based from http://codeforces.com/blog/entry/18051
#define MAX_N 10000
int n;
int t[MAX_N * 2];
void init() {
for (int i = n - 1; i > 0; --i){
t[i] = t[i << 1] + t[i << 1 | 1];
@stefanonardo
stefanonardo / early_stopping.py
Last active February 28, 2024 19:21
Early Stopping PyTorch
# MIT License
#
# Copyright (c) 2018 Stefano Nardo https://gist.github.com/stefanonardo
#
# 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
# furnished to do so, subject to the following conditions:
@michaelneu
michaelneu / README.md
Last active December 29, 2023 04:06
A basic, but fast git prompt.

bash-basic-git-prompt

This is a considerably faster, but much more basic alternative to bash-git-prompt.

When adding this script to your .bash_profile or .bashrc, it'll display the selected branch of the current folder (if it's a git repo), and whether it's modified (yellow) or contains staged files (cyan).

example

The script makes the assumption, that a .git folder only exists when the directory is a git repo. Also, it checks for the english version of the git status command, so if you're using git in a different locale, make sure to adjust this.

@fliptopbox
fliptopbox / string.compress.js
Created October 15, 2013 12:32
JavaScript String compression
/*
@fliptopbox
LZW Compression/Decompression for Strings
Implementation of LZW algorithms from:
http://rosettacode.org/wiki/LZW_compression#JavaScript
Usage:
var a = 'a very very long string to be squashed';
var b = a.compress(); // 'a veryāăąlong striċ to bečquashed'