This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cd_func () { | |
| cd "$1" | |
| echo "$PWD" > ~/lastdir | |
| } | |
| start_func() { | |
| if [ ! -f ~/lastdir ]; then | |
| echo "~" > ~/lastdir | |
| fi | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Node(object): | |
| def __init__(self, data): | |
| self.data = data | |
| self.next = None | |
| # ---------------------------------------------------------- | |
| class MyLinkedList(object): | |
| def __init__(self): | |
| self.head = None |
OlderNewer