Skip to content

Instantly share code, notes, and snippets.

View Avantgarde95's full-sized avatar
😺
Working

Hunmin Park Avantgarde95

😺
Working
View GitHub Profile
@Avantgarde95
Avantgarde95 / tree.py
Last active May 9, 2016 18:27
Simple tree implementation in python
# simple tree implementation in python
class DepthError(Exception):
pass
class Tree(object):
''' simple implementation of tree '''
def __init__(self, value = None, childs = None):
''' class initialization '''
self.value = value # container
@Avantgarde95
Avantgarde95 / preserveDir.sh
Last active April 13, 2016 14:52
Store current directory after every 'cd', and open the most recent one when starting bash.
cd_func () {
cd "$1"
echo "$PWD" > ~/lastdir
}
start_func() {
if [ ! -f ~/lastdir ]; then
echo "~" > ~/lastdir
fi
@Avantgarde95
Avantgarde95 / gifextract.py
Created April 16, 2016 17:31 — forked from BigglesZX/gifextract.py
Extract frames from an animated GIF, correctly handling palettes and frame update modes
import os
from PIL import Image
'''
I searched high and low for solutions to the "extract animated GIF frames in Python"
problem, and after much trial and error came up with the following solution based
on several partial examples around the web (mostly Stack Overflow).
There are two pitfalls that aren't often mentioned when dealing with animated GIFs -
@Avantgarde95
Avantgarde95 / ex_timing.py
Created May 23, 2016 21:37
Example code for handling timeout in Tkinter.
# Tested on python 2.7
import random
import Tkinter as tk
class TestApp(tk.Frame, object):
''' When the player presses the button, the player and the enemy
chooses the numbers among 0 ... 10 randomly. If player >= enemy,
the player wins, otherwise the enemy wins.
If the player doesn't press the button in 2 seconds, the enemy wins.
@Avantgarde95
Avantgarde95 / opentest.py
Last active August 18, 2016 20:03
numpy.loadtxt vs file.readline
import timeit
import numpy
filename = 'output.txt'
def generate_file(num_lines):
line = '|'.join(str(i) for i in xrange(100)) + '\n'
with open(filename, 'w') as p:
p.write(line * num_lines)
@Avantgarde95
Avantgarde95 / mydict.py
Created August 31, 2016 00:01
Bydirectional dictionary
# -*- coding: utf-8 -*-
class MyDict(dict):
def __init__(self, *args, **kwargs):
super(MyDict, self).__init__(*args, **kwargs)
self.map_values = dict((value, key) for key, value in self.items())
def __setitem__(self, key, value):
key, mode = key
import random
def generate(count_max = -1, target = 'hello'):
target = ''.join(c for c in target.lower() if 'a' <= c and c <= 'z')
alphabets = map(chr, xrange(ord('a'), ord('z') + 1))
count = 0
print 'Target : %s (length %d)' % (target, len(target))
for i in xrange(len(target)):
ex6Tests = [ testF1 "allCodes test" allCodes
[ (1, [[Red], [Green], [Blue], [Yellow], [Orange], [Purple]]),
(2, [[Red, Red], [Red, Green], [Red, Blue],
[Red, Yellow], [Red, Orange], [Red, Purple],
[Green, Red], [Green, Green], [Green, Blue],
[Green, Yellow], [Green, Orange], [Green, Purple],
[Blue, Red], [Blue, Green], [Blue, Blue],
[Blue, Yellow], [Blue, Orange], [Blue, Purple],
[Yellow, Red], [Yellow, Green], [Yellow, Blue],
[Yellow, Yellow], [Yellow, Orange], [Yellow, Purple],
@Avantgarde95
Avantgarde95 / psm.c
Last active September 14, 2016 08:22
A simple script for approximating x^(1/n) I wrote when I was young.
// approximation of x^(1/n)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double ipow(double p, unsigned int q) {
unsigned int j = 0;
double prod = 1.0;
@Avantgarde95
Avantgarde95 / linkedlist.py
Created October 10, 2016 16:43
Singly linked list
class Node(object):
def __init__(self, data):
self.data = data
self.next = None
# ----------------------------------------------------------
class MyLinkedList(object):
def __init__(self):
self.head = None