Skip to content

Instantly share code, notes, and snippets.

View ptigas's full-sized avatar
🐙

Panagiotis Tigas ptigas

🐙
View GitHub Profile
--Applescript direct
on replaceText(find, replace, subject)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set subject to text items of subject
set text item delimiters of AppleScript to replace
set subject to "" & subject
set text item delimiters of AppleScript to prevTIDs
@ptigas
ptigas / gist:1388592
Created November 23, 2011 12:51
get variables list from a SMARTY template
cat [file] | grep -o '\$[^} ;&?"-]*' | sort -u
@ptigas
ptigas / gist:1451403
Created December 9, 2011 12:49
Check postfix logs for memory issues
cat /var/log/maillog* | grep "$(date '+%b %d' | sed 's/0\([0-9]\)/ \1/g')" | grep "Cannot allocate memory"
@ptigas
ptigas / gist:1730997
Created February 3, 2012 16:34
letter frequency
from itertools import groupby
[(i, len(list(j))) for i,j in groupby(sorted('hullabaloo'))]
@ptigas
ptigas / names.csv
Created March 3, 2012 10:43
names.csv
We can't make this file beautiful and searchable because it's too large.
John,1,male,1880
Mary,9655,female,1880
William,2,male,1880
Anna,9533,female,1880
James,3,male,1880
Emma,5927,female,1880
Charles,4,male,1880
Elizabeth,5348,female,1880
George,5,male,1880
Minnie,5126,female,1880
@ptigas
ptigas / loop_detection.py
Created March 3, 2012 21:18
Example of Floyd algorithm for loop detection
'''
Example of Floyd algorithm for loop detection
'''
class Node :
def __init__(self, data) :
self.next = None
self.data = data
def __str__(self) :
@ptigas
ptigas / stack.c
Created March 4, 2012 13:17
quick and dirty stack implementation in C
#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
struct node *next;
};
struct list {
struct node *head;
@ptigas
ptigas / singleton.py
Created March 6, 2012 19:47
example of singleton design pattern in python
counter = 1
class TestSingleton:
__instance = None
__var = 0
def __init__(self):
global counter
self.__var = counter
counter += 1
@ptigas
ptigas / memento_fib.py
Created March 6, 2012 20:17
memento decorator applied on fibonacci
class Memento :
__mem__ = {}
def __init__(self, f) :
self.f = f
def __call__(self, arg) :
if arg not in self.__mem__ :
self.__mem__[arg] = self.f(arg)
return self.__mem__[arg]
@ptigas
ptigas / gist:2036981
Created March 14, 2012 14:48
bash animations
while true; do echo -n "◐\r"; sleep .1; echo -n "◓\r"; sleep .1; echo -n "◑\r"; sleep .1; echo -n "◒\r"; sleep .1; done
while true; do echo -n "◜\r"; sleep .1; echo -n "◠\r"; sleep .1; echo -n "◝\r"; sleep .1; echo -n "◞\r"; sleep .1; echo -n "◡\r"; sleep .1; echo -n "◟\r"; sleep .1; done
while true; do a=$a" "; echo -n "\r" $a "✈ "; sleep .1; done
while true; do a=$a" "; echo -n "\r" $a "\xcf\x80\xce\xbf\xcf\x8d\xcf\x84\xcf\x83\xce\xb1 "; sleep .1; done