Skip to content

Instantly share code, notes, and snippets.

View huklee's full-sized avatar

Hyeonguk Lee huklee

View GitHub Profile
@huklee
huklee / modifyExifGeoDate.py
Last active July 22, 2018 16:38
modify exif format with geo & date info in Python3
import piexif
import pickle
from PIL import Image
def saveExifFromPickle(exif_dict, outFile):
pickle.dump(exif_dict, open(outFile, "wb"))
def loadExifFromPickle(inFile):
return pickle.load(open(inFile, "rb"))
@huklee
huklee / find_k_pairs_with_smallest_sums.py
Created May 30, 2018 00:51
Leetcode solution : find-k-pairs-with-smallest-sums
# 1) using Min-Heap logN
# 1. make a min heap(Heap Queue : python heapq) S with sum value
# 2. pick first Elem in S and j++ then, push it again
# 3. iterate k times till every j < len(b)
# T(n) = O(klogN)
from heapq import *
class Solution:
@huklee
huklee / sort_2key.py
Created May 30, 2018 00:49
how to sort by 2 keys for list in python3
import functools
def sorted_by(a,b):
if a[0] == b[0]:
return a[1] - b[1]
else:
return a[0] - b[0]
cmp = functools.cmp_to_key(sorted_by)
@huklee
huklee / generateTree.py
Last active May 1, 2018 16:07
generateTree from a parsed Tree
class Tree():
def __init__(self, val):
self.val = val
self.child = []
def addChild(self, t):
children = self.child
children.append(t)
def print(self, lev = ""):
@huklee
huklee / MyLogger.py
Last active January 6, 2024 18:06
python Logger using example with Singleton Pattern
# -*- coding: utf-8 -*-
import logging
import os
import datetime
import time
class SingletonType(type):
_instances = {}
@huklee
huklee / walking-the-approximate-longest-path_manhlx_300695.cpp
Created March 22, 2017 15:46
walking-the-approximate-longest-path_manhlx_300695
#include <bits/stdc++.h>
// #include <iostream>
// #include <cstdio>
// #include <cstring>
// #include <cmath>
// #include <algorithm>
// #include <stack>
// #include <queue>
// #include <set>
// #include <map>
@huklee
huklee / cImg_sample_read.cpp
Last active March 12, 2017 11:44
cImg simple read & display a file example
#ifndef cimg_plugin
#define cimg_plugin " "
#include "CImg.h"
using namespace cimg_library;
#ifndef cimg_imagepath
#define cimg_imagepath "img/"
#endif
@huklee
huklee / allCombinationsOfString.cpp
Last active March 6, 2017 12:03
solution : get the all combinations of a string
#include <iostream>
#include <string>
using namespace std;
// bitwise operation solution
void solve(string s){
// assert (s.size() <= 32);
for (int i=1; i < (1 << s.size()); i++){
string result;
for (int j=0; j < s.size(); j++){
@huklee
huklee / printAllCombinationsString.cpp
Last active March 6, 2017 12:02
print all combinations of 2D string array
// author : huklee
// source : JTD 2017-03-05
// print all combinations of string 2D list
#include <vector>
#include <string>
#include <iostream>
using namespace std;
string print_combination(vector<int> &index_list, vector<vector<string> > &v){
@huklee
huklee / printAllCombinationsString.py
Last active March 6, 2017 12:02
print all combinations of 2D string array
# author : huklee
# source : JTD 2017-03-05
# print all combinations of string 2D array
def printComb(a, sl):
s = ""
for i in range(len(a)):
s += sl[i][a[i]]
return s