Skip to content

Instantly share code, notes, and snippets.

View OzTamir's full-sized avatar

Oz Tamir OzTamir

View GitHub Profile
@OzTamir
OzTamir / pretty_tables.py
Created March 21, 2015 09:49
Print formatted tables in Python (Rows might overflow, but otherwise the output is pretty
def show_table(titles, rows, table_name=None, sep_rows=False):
'''
Print a pretty, formatted and spaced table
Parameters:
- header (iterable) : Sequence with titles for each column
- rows (iterable) : Sequence of rows in the table,
must contain len(header) items.
- table_name (str): if the caller want to, print a title
- sep_rows (bool): should the function print a seperetor between values
'''
@OzTamir
OzTamir / count_lines.sh
Created February 28, 2015 12:14
Aliases to count lines and get statistics about a git project (requires CLOC: http://cloc.sourceforge.net)
# Set aliases
# Count lines in a git repository
alias git_lines='git ls-files | xargs wc -l'
# Count lines of code using CLOC
alias cloc='/Applications/CLI/cloc'
# Lines in a project
alias lines="echo 'Total Lines:' ; git_lines | tail -1 ; echo ''; echo 'Statistics:' ; cloc . | tail -8"
@OzTamir
OzTamir / tear.py
Last active August 29, 2015 14:13
Warning: This script will make you cry
from PIL import Image
import urllib
import urllib2
import json
import os
import sys
API_ENDPOINT = 'http://rekognition.com/func/api/?'
TEAR_IMG_URL = 'http://i.imgur.com/7VAlEVf.png'
API_KEY = ''
@OzTamir
OzTamir / speed_date.py
Created January 5, 2015 10:24
Get a random arrangement for groups of people for few rounds
from random import shuffle, randrange
import sys
def get_pool(num_people, num_groups):
''' Get a list of available slots per group (for 1 round) '''
slots_per_group = num_people / num_groups
pool = []
for slot in xrange(slots_per_group):
for group in xrange(1, num_groups + 1):
pool.append(group)
@OzTamir
OzTamir / calc_catalan.py
Last active August 29, 2015 14:12
Calculate the n-th Catalan number
from __future__ import division
import sys
def calc_mod(n, m):
''' Calculate the n-th Catalan mod m'''
res = 1
tmp = 0
for k in xrange(2, n + 1):
tmp = ((n + k) / k) % m
res %= m
@OzTamir
OzTamir / database.py
Last active January 30, 2023 14:24
A simple MySQL wrapper (and UI utils!) in Python
from __future__ import print_function
import mysql.connector
from mysql.connector import errorcode
from mysql.connector.errors import *
import sys
class Database(object):
def __init__(self, dbhost, dbuser, dbpass, dbname, debug=False):
''' Intialize a Database object and connect to the database '''
self.host = dbhost
@OzTamir
OzTamir / sub_to_main.py
Created November 29, 2014 10:31
Copy all the files in the subfolders to main folder
import shutil
import os
# The current working directory
dest_dir = os.getcwd()
# The generator that walks over the folder tree
walker = os.walk(dest_dir)
# the first walk would be the same main directory
# which if processed, is
@OzTamir
OzTamir / wikigame.py
Last active August 29, 2015 14:08
Wikigame - Get to Philosophy from any given article
import urllib2
import sys
from bs4 import BeautifulSoup
import re
# Used for formating wiki links
wiki_endpoint = "http://en.wikipedia.org/wiki/"
# Count how many links were visited on the way
counter = 0
# Regular Pattren for link

Keybase proof

I hereby claim:

  • I am OzTamir on github.
  • I am oztamir (https://keybase.io/oztamir) on keybase.
  • I have a public key whose fingerprint is FE51 85BB 5A53 1286 543F 0F50 ABEB 411F C0A0 378B

To claim this, I am signing this object:

@OzTamir
OzTamir / linksParser.cpp
Last active August 29, 2015 14:06
Parse links from HTML <a> tags from an input file
#include <iostream>
#include <fstream>
#include <string>
#include <regex>
using namespace std;
void parseLinks(string file) {
// Pattern of a HTML link tag
string patt = "(<a href\\s*=\\s*)(\")([^<\"]*)";
// Regex object to match this pattern