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
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| int binarySearch(vector<int> v, int key) { | |
| int arrayLen = v.size(); | |
| int low = 0; | |
| int high = arrayLen - 1; | |
| int avg = (high + low) / 2; |
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
| # See: http://github.com/OzTamir/oZip | |
| class Compressor(object): | |
| """Base class for Compressors""" | |
| def __init__(self): | |
| super(Compressor, self).__init__() | |
| def compress(self, data): | |
| return data |
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
| # merge() takes two sorted lists and merge them into one sorted list | |
| from heapq import merge | |
| def merge_sort(m): | |
| ''' Sort a list in O(n * log(n)) ''' | |
| # If theres only one element in the list, return the list | |
| if len(m) <= 1: | |
| return m | |
| # Split the list into two equal-sized sub-lists | |
| middle = len(m) / 2 |
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
| # gister.py - Download the public gists of a certin GitHub user | |
| # By Oz Tamir | |
| # ---------- | |
| import os | |
| import json | |
| import urllib2 as urllib | |
| def download_gist(url): | |
| ''' Download a gist content (code) ''' |
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
| from PIL import Image | |
| def pixel_to_ascii(pixel): | |
| ''' Convert a single pixel to an ASCII based on it's color ''' | |
| if isinstance(pixel, tuple): | |
| pixel = pixel[0] | |
| if pixel > 128: | |
| return chr(176) | |
| return chr(219) |
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
| from random import choice | |
| from string import printable as ascii | |
| from string import whitespace | |
| from time import sleep | |
| def random_chars_gen(): | |
| while True: | |
| char = choice(ascii) | |
| if (not char in whitespace) or char == ' ': | |
| yield char |
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 | |
| class TreeNode: | |
| def __init__(self, key, value, left=None, right=None): | |
| self.key = key | |
| self.value = value | |
| self.left = left | |
| self.right = right | |
| class BinarySearchTree: | |
| def __init__(self): |
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
| ; repetition.asm | |
| ; Count how many repetition to a string are required to reach another string | |
| ; ---- | |
| ; To assamble (on Ubuntu), run: | |
| ; $ nasm -f elf repetition.asm ; gcc repetition.o -o repetition | |
| ; $ ./repetition | |
| ; Note: You may have to set execute permission to run. | |
| ; ---- | |
| ; Output Example: | |
| ; Enter first string: abc |
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
| <!DOCTYPE HTML> | |
| <html lang="en"> | |
| <head> | |
| <title>Particle Demo</title> | |
| <meta charset="utf-8"> | |
| <style type="text/css"> | |
| body { | |
| background-color: #000000; | |
| margin: 0px; |
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
| // Playground - noun: a place where people can play | |
| // My take - Let's play with Swift! | |
| func makeHey(toWhom : String, anythingElse:String = "") -> String { | |
| /* Create a greeting String with an optional message */ | |
| var hey = "Hello there, \(toWhom)." | |
| if !anythingElse.isEmpty { | |
| hey += " Also, \(anythingElse)" | |
| } | |
| return hey |