Skip to content

Instantly share code, notes, and snippets.

View faif's full-sized avatar

Sakis Kasampalis faif

View GitHub Profile
@faif
faif / except.sql
Last active August 29, 2015 14:08
except and join
SELECT s.student_id
FROM students s
EXCEPT
SELECT g.student_id
FROM grades g;
@faif
faif / voltmeter.cpp
Last active December 20, 2015 08:19
mbed USB voltmeter
#include "voltmeter.h"
float voltage(const float m)
{
return m * VOLTAGE_FACTOR;
}
int main(void)
{
float i = 0;
@faif
faif / sort.rb
Last active December 18, 2015 12:58
Ruby sort strings numerically native
irb(main):002:0> ['A3', 'A5', 'A11', 'A8', 'A10'].sort
=> ["A10", "A11", "A3", "A5", "A8"]
@faif
faif / myqueue.py
Last active December 10, 2015 12:48
queue
class myqueue:
def __init__(self):
self._contents = list()
def __str__(self):
return '{}'.format(self._contents[::-1])
def __iter__(self):
return iter(self._contents)
@faif
faif / strutils.py
Created October 3, 2012 19:57
remove duplicate characters
def remDupl(s):
return None
@faif
faif / sortstack.py
Last active October 11, 2015 01:48
stack
from stack import stack
def sort(unsorted):
sortedStack = stack()
while len(unsorted):
top = unsorted.pop()
while len(sortedStack) and sortedStack.peek() < top:
unsorted.push(sortedStack.pop())
sortedStack.push(top)
@faif
faif / mychmod.c
Created January 29, 2012 16:27
plan9 chmod
#include <u.h>
#include <libc.h>
const int STDERR = 2;
static void
usage (void)
{
fprint (STDERR, "usage: %s 0644 file1 [file2] ...\n", argv0);
exits ("usage");
@faif
faif / answers.py
Created January 5, 2012 20:16
Web logon
import urllib.request, urllib.parse
MAX_TRIES = 3
if __name__ == '__main__':
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor())
urllib.request.install_opener(opener)
params = urllib.parse.urlencode(dict(login='username@yahoo.com',
passwd='y0uRpas5'))
utf_params = params.encode('utf-8')
@faif
faif / fibo-timeit.py
Created January 4, 2012 19:28
using the timeit module
ERR = 'n must be >= 0'
def fibonacci(n):
assert(n >= 0), ERR
if n == 0 or n == 1:
return n
res = fibonacci(n-1) + fibonacci(n-2)
return res
known = {0:0, 1:1}