Skip to content

Instantly share code, notes, and snippets.

View iamaziz's full-sized avatar
🎲

Aziz Alto iamaziz

🎲
View GitHub Profile
@iamaziz
iamaziz / calculate_ams.py
Last active August 29, 2015 14:04
Calculate the evaluation metric "AMS" of Higgs Boson competition at Kaggle https://www.kaggle.com/c/higgs-boson/details/evaluation
# Calculate the evaluation metric "AMS" of Higgs Boson competition at Kaggle
# https://www.kaggle.com/c/higgs-boson/details/evaluation
"""
__Author__ = "Aziz Alto"
"""
import numpy as np
import pandas as pd
@iamaziz
iamaziz / cmd_arg.py
Last active August 29, 2015 14:04
execute a terminal command in python with passing arguments
# execute a terminal command in python with passing arguments
# python command-line arguments
import os
arg1 = "first_argument"
arg2 = "second_argument"
terminal_command = "python test.py {0} {1}".format(arg1, arg2)
os.system(terminal_command)
@iamaziz
iamaziz / treeme.sh
Last active August 29, 2015 14:04
Script to create an html page as a tree of current directory, based on tree: http://mama.indstate.edu/users/ice/tree/
#!/bin/bash
# create a tree of current directory in an html page `readme.html`
# to use it: place treeme.sh somewhere and add it your path
# (add/remove any extension to EXECLUDE to be displayed/execluded)
TITLE="Tree of:"
PWD=$(pwd)
OUTPUT="readme.html"
@iamaziz
iamaziz / replace_chars.py
Last active August 29, 2015 14:05
recursively replace each char (substring) in *args from a given text
def rep_chars(txt, *args):
"""recursively replace each char (substring) in *args from a given text"""
chars = [str(c) for c in args]
if len(chars) < 1:
return txt
else:
txt = txt.replace(chars.pop(), ' ' )
return rep_chars( txt, *chars ) # repeat rep_chars() until *args is None
a = 'abcdefgh'
@iamaziz
iamaziz / Pandoc-to-dash.py
Last active August 29, 2015 14:14
Generate Dash docset for Pandoc
# quick-and-dirty script to generate Pandoc docset for Dash.app
#----------------------------------
# built-in packages
import sqlite3
import os
import urllib
import plistlib
#----------------------------------
@iamaziz
iamaziz / Kivy-docset-to-dash.py
Created February 24, 2015 02:08
Generate Dash docset for Kivy
#----------------------------------
# built-in packages
import sqlite3
import os
import urllib
import plistlib
#----------------------------------
# third party packages + httrack
@iamaziz
iamaziz / change-file-names.py
Created March 8, 2015 21:18
Change file names in a directory and its sub-directories.
import os
for dpath, dnames, fnames in os.walk('/path/to/dir'):
for f in fnames:
os.chdir(dpath)
if f.endswith('.pdf'):
os.rename(f, f.replace(' ', '-'))
@iamaziz
iamaziz / gensim-to-docset.py
Created July 17, 2016 03:21
generate gensim docset
# generate gensim docset
# http://radimrehurek.com/gensim/
#----------------------------------
# built-in packages
import sqlite3
import os
import urllib
import plistlib
@iamaziz
iamaziz / xor.ipynb
Created June 2, 2017 18:46
learning XOR
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@iamaziz
iamaziz / list.py
Last active July 16, 2017 02:48
naive implementation for list data structure (int type)
"""
Create a data structure that mimics Python's list.
IDEA: convert each element to a base representation with a fixed size (byte / binary / octal / hexadecimal ... etc)
then, concat elements as a string.
Based on meetup: https://www.meetup.com/Deep-Dive-into-Python-Know-Thy-Interpreter/events/238587475/
"""
class List(object):