Skip to content

Instantly share code, notes, and snippets.

View hiepph's full-sized avatar

Hiep Pham hiepph

View GitHub Profile
@hiepph
hiepph / genetic.py
Created February 24, 2020 15:44
Genetic algorithm
# refer: https://www.geeksforgeeks.org/genetic-algorithms/
import random
POPULATION_SIZE = 100
# Valid genes
GENES = """abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP
QRSTUVWXYZ 1234567890, .-;:_!"#%&/()=?@${[]}"""
@hiepph
hiepph / weird.py
Created February 14, 2020 10:25
Weird functional python
from toolz import *
from toolz.curried import *
import string
lines = open('./gt.txt').readlines()
imgs = pipe(
lines,
map(lambda l: l.split('\t')[0]),
list
@hiepph
hiepph / selenium.rb
Created February 12, 2020 09:42
Ruby selenium
# crawl images from gogole images search using Selenium
# requirement: geckodriver
# gem: selenium-webdriver nokogiri
require 'selenium-webdriver'
require 'nokogiri'
require 'open-uri'
require 'securerandom'
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "https://www.google.com/search?tbm=isch&q=single logos"
@hiepph
hiepph / func.hs
Created January 21, 2020 07:21
Haskell useful functions
import Data.Char (isSpace)
trim :: String -> String
trim = f . f
where f = reverse . dropWhile isSpace
@hiepph
hiepph / Main.hs
Created January 9, 2020 08:52
sample_haskell_main
module Main where
import Data.Char
import Data.List
strong :: String -> Bool
strong s = length s > 14 &&
any (\c -> c `elem` ['A'..'Z']) s &&
any (\c -> c `elem` ['a'..'z']) s &&
any (\c -> c `elem` ['1'..'9']) s
@hiepph
hiepph / image.py
Last active June 8, 2020 09:30
jupyter tricks
def display(img):
"Display single image"
_, ax = plt.subplots(1, 1, figsize=(10, 10))
#plt.axis('off')
#plt.title('Title')
plt.imshow(img); plt.show()
def display_grid(imgs):
"Display grid"
@hiepph
hiepph / resize_and_pad_image_to_square
Created November 13, 2019 07:32 — forked from jdhao/resize_and_pad_image_to_square
this script will resize and pad an image to desired square size and keep its aspect ratio unchanged. Before running the script, please change the size and image path to valid value.
from PIL import Image, ImageOps
import cv2
desired_size = 368
im_pth = "/home/jdhao/test.jpg"
# im = Image.open(im_pth)
# old_size = im.size # old_size[0] is in (width, height) format
# ratio = float(desired_size)/max(old_size)
@hiepph
hiepph / gdrive_download
Created November 5, 2019 07:40 — forked from darencard/gdrive_download
Script to download files from Google Drive using Bash
#!/usr/bin/env bash
# gdrive_download
#
# script to download Google Drive files from command line
# not guaranteed to work indefinitely
# taken from Stack Overflow answer:
# http://stackoverflow.com/a/38937732/7002068
gURL=$1
@hiepph
hiepph / tf.py
Last active November 5, 2019 04:12
Python warning
import tensorflow as tf
tf.logging.set_verbosity(tf.logging.ERROR) # level 2
@hiepph
hiepph / filter.py
Last active August 6, 2019 08:11
pypeln sample
from PIL import Image
from tqdm import tqdm
import sys
import os
from pypeln import process as pr
# python filter.py train 8
phase = sys.argv[1]