Skip to content

Instantly share code, notes, and snippets.

View mitliagkas's full-sized avatar

Ioannis Mitliagkas mitliagkas

View GitHub Profile
@mitliagkas
mitliagkas / evernoteWebClipperiPad
Created August 18, 2014 22:30
Javascript bookmark for iPad Evernote web clipper functionality
javascript:(function()%7BEN_CLIP_HOST='http://www.evernote.com';try%7Bvar%20x=document.createElement('SCRIPT');x.type='text/javascript';x.src=EN_CLIP_HOST+'/public/bookmarkClipper.js?'+(new%20Date().getTime()/100000);document.getElementsByTagName('head')%5B0%5D.appendChild(x);%7Dcatch(e)%7Blocation.href=EN_CLIP_HOST+'/clip.action?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title);%7D%7D)();
@mitliagkas
mitliagkas / pyspark-vector-accumulator.py
Created August 6, 2014 05:46
PySpark Vector Accumulator Class
# Taken almost verbatim from PySpark's doctest
from pyspark.accumulators import AccumulatorParam
class VectorAccumulatorParam(AccumulatorParam):
def zero(self, value):
return [0.0] * len(value)
def addInPlace(self, val1, val2):
for i in xrange(len(val1)):
val1[i] += val2[i]
return val1
xnew = sc.accumulator([0.0]*p, VectorAccumulatorParam())
@mitliagkas
mitliagkas / list-attributes.py
Created August 5, 2014 21:06
List all non-method object attributes along with their values
import inspect
for p in dir(sc):
if p[0]=='_':
continue
if inspect.ismethod(sc.__getattribute__(p)):
continue
print p, sc.__getattribute__(p)
print
@mitliagkas
mitliagkas / yannisPackages.tex
Created May 29, 2014 23:44
Commonly included latex packages
% Typesetting
%\usepackage[margin=1in]{geometry}
%\usepackage{fullpage}
\usepackage{verbatim}
% Fonts and stuff
%\usepackage{times}
%\usepackage{soul}
\usepackage{color}
%\usepackage[usenames,dvipsnames]{color}
@mitliagkas
mitliagkas / yannisDefinitions.tex
Created May 29, 2014 23:43
Common latex Definitions
\newcommand{\theHalgorithm}{\arabic{algorithm}}
%\newtheorem{theorem}{Theorem}
%\newtheorem{definition}[theorem]{Definition}
%\newtheorem{assumption}[theorem]{Assumption}
%\newtheorem{proposition}[theorem]{Proposition}
%\newtheorem{lemma}[theorem]{Lemma}
%\newtheorem{corollary}[theorem]{Corollary}
@mitliagkas
mitliagkas / truncate.py
Last active August 29, 2015 14:01
Truncate vector x, only keeping the s elements of largest magnitude.
part = np.argpartition(abs(x),len(x)-s,axis=0)
x[part[:-s]] = 0