Skip to content

Instantly share code, notes, and snippets.

@dongho-jung
dongho-jung / cutting_the_log.py
Created July 27, 2019 04:27
Kyle help please
# input
# L -> the length of the log
# C -> the max number of times to cut
# xs -> the sorted list of possible positions to cut
L, _, C = map(int, input().split())
xs = sorted(map(int, input().split()))
min_val = L
def solve(start):
upper_bound = L
@dongho-jung
dongho-jung / linkedList.go
Created April 28, 2019 13:47
the double linked list structure with using go.
package main
import (
"fmt"
)
type LinkedList struct {
Head *Node
Tail *Node
}
@dongho-jung
dongho-jung / realtime_config.go
Last active April 29, 2019 15:13
read the config file automatically when the config changes detected, then reflect it.
package main
import (
"github.com/fsnotify/fsnotify"
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"reflect"
"time"
)
@dongho-jung
dongho-jung / inspectStruct.go
Created April 27, 2019 15:01
get information about the fields and methods of a struct.
package main
import (
"errors"
"fmt"
"reflect"
"strings"
)
var errNotStruct = errors.New("anyStruct must be struct")
def get_powersets(total_set, idx=0, sets=None):
if not sets:
return get_subsets(total_set, idx, [[]])
if len(total_set) > idx:
return get_subsets(total_set, idx+1, sets + [s + [total_set[idx]] for s in sets])
return sets
@dongho-jung
dongho-jung / oneline_sleepsort.py
Created February 19, 2019 13:25
sleep sort in only one statement (just for fun)
[__import__('threading').Thread(target=(lambda x:lambda:[__import__('time').sleep(x),print(x)])(n)).start()for n in map(int,input().split())]
@dongho-jung
dongho-jung / blender.py
Created August 5, 2018 19:24
the blender script for rendering 3D animation about test functions for optimization
import bpy
import math
import itertools
import numpy as np
import pickle
test_name = 'Beale' # Himmelblau, Matyas, Sphere, Rosenbrock, Rastrigin, Easom, Beale
fps = 10
@dongho-jung
dongho-jung / get_join_mask.py
Created August 3, 2018 14:14
pandas join multiple columns
def get_join_mask(*cols, unit=None):
'''Return a boolean mask based on first column by extracting the index
having the same value appears in every columns. If unit is specified then
given columns are truncated with the unit. unit follows pandas.Series.dt accessor format.
'''
if unit:
try:
cols = map(lambda x: x.map(operator.methodcaller(unit)), cols)
except Exception as e:
@dongho-jung
dongho-jung / usage_stratify.py
Created July 5, 2018 03:12
this snippet show the meaning of stratify parameter of test_train_split util from sklearn
import numpy as np
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
cancer = load_breast_cancer()
# this call with stratify parameter will produce
# the proportion of values as same as cancer.target which is provided by stratify parameter
X_train, X_test, y_train, y_test = train_test_split(
cancer.data, cancer.target, stratify=cancer.target
@dongho-jung
dongho-jung / numeric2text.sql
Created July 1, 2018 20:42
This query returns numeric type in words
-- below is postgresql
SELECT REGEXP_REPLACE(CASH_WORDS(level*100::MONEY),
'dollars? and zero cents',
''
) x
FROM generate_series(1, 100, 1) t1(level);
-- below is oracle
SELECT TO_CHAR(TO_DATE(level, 'J'), 'JSP') x
FROM DUAL