Skip to content

Instantly share code, notes, and snippets.

View OzTamir's full-sized avatar

Oz Tamir OzTamir

View GitHub Profile
@OzTamir
OzTamir / binary_search.cpp
Created September 4, 2014 14:27
A binray search in C++
#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;
@OzTamir
OzTamir / lz78.py
Created September 2, 2014 13:52
A LZ78 in Python, written (originally) for use in oZip
# 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
@OzTamir
OzTamir / merge_sort.py
Created August 21, 2014 14:08
Merge sort in Python
# 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
@OzTamir
OzTamir / gister.py
Created July 7, 2014 17:17
All your gist are belong to us
# 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) '''
@OzTamir
OzTamir / img2ASCII.py
Last active August 29, 2015 14:03
Create ASCII representation of images
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)
@OzTamir
OzTamir / textEvolution.py
Created July 7, 2014 15:33
Watch as the random string evolve into the input.
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
@OzTamir
OzTamir / data_structures.py
Last active August 29, 2015 14:03
Python utilities, as preparation for the TAU CS1001.py Final Exam
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):
@OzTamir
OzTamir / repetition.asm
Last active August 29, 2015 14:03
Count how many repetition to a string are required to reach another string
; 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
@OzTamir
OzTamir / particles.html
Created June 16, 2014 15:30
A Three.js particle example (Demo: http://oztamir.com/js-demo/particles.html)
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Particle Demo</title>
<meta charset="utf-8">
<style type="text/css">
body {
background-color: #000000;
margin: 0px;
@OzTamir
OzTamir / HeySwift.swift
Last active August 29, 2015 14:02
Give it up for our new friend, Swift!
// 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