Skip to content

Instantly share code, notes, and snippets.

View ptigas's full-sized avatar
🐙

Panagiotis Tigas ptigas

🐙
View GitHub Profile
@ptigas
ptigas / workshop_car.ino
Created February 16, 2017 11:07
workshop car
// connect the distance sensor
#define trigPin 13
#define echoPin 12
// connect motor controller pins to Arduino digital pins
// motor one
int enA = 3;
int in1 = 4;
int in2 = 5;
@ptigas
ptigas / antiDDOS.sh
Last active March 31, 2016 21:06
mitigate linode DDOS
#!/bin/bash
function join { local IFS="$1"; shift; echo "$*"; }
IFS=$'\n'
LIMIT=20
STATS=$(netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n | grep -v Address | grep -v servers)
BLACKLISTED=""
BLACKLISTED_IPS=()
EMAIL="ptigas@gmail.com"
@ptigas
ptigas / message.html
Created January 28, 2013 20:37
the message behind the voice
<html>
<head>
</head>
<body>
</body>
</html>
@ptigas
ptigas / gist:4155731
Created November 27, 2012 17:32
unifying python api response
import json
class API :
ERROR = -1
OK = 0
class APIResponse(API) :
def __init__(self, code, data) :
self.code = code
self.data = data
@ptigas
ptigas / gist:4052387
Created November 10, 2012 20:30
bootstrap django
Django==1.4
South==0.7.6
django-dbsettings==0.2
django-grappelli==2.3.8
pyechonest==4.2.21
simplejson==2.6.0
@ptigas
ptigas / latex_escape.py
Created August 31, 2012 12:44
latex escape
# -*- encoding: utf-8 -*-
def latex_decode( s ) :
'''
A simple function which taks a latex escaping command
and returns the appropriate unicode character according
to this table (via wikipedia):
LaTeX command Sample Description
\`{o} ò grave accent
@ptigas
ptigas / latency.txt
Created May 31, 2012 13:14 — forked from jboner/latency.txt
Latency numbers every programmer should know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 25 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 3,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns
Read 1 MB sequentially from memory 250,000 ns
Round trip within same datacenter 500,000 ns
Disk seek 10,000,000 ns
@ptigas
ptigas / gist:2835530
Created May 30, 2012 11:04
change base of integer
'''
convert a number (given in string format) from a base f to base t
'''
import string
def convertbase( n, f, t ) :
digits = list(string.digits+string.uppercase)
rev_digits = {}
@ptigas
ptigas / gist:2829701
Created May 29, 2012 17:45
intersection algorithm in python
def intersection( *A ) :
res = []
while True :
# check if the heads are the same
all_same = True
for i in range(1, len(A)) :
if len(A[i]) > 0 and len(A[i-1]) > 0 and A[i-1][0] == A[i][0] :
pass
else :
all_same = False
@ptigas
ptigas / gist:2820165
Created May 28, 2012 17:21
linked list implementation in python
class Node :
def __init__( self, data ) :
self.data = data
self.next = None
self.prev = None
class LinkedList :
def __init__( self ) :
self.head = None