Skip to content

Instantly share code, notes, and snippets.

@MasseR
MasseR / gist:176233
Created August 27, 2009 11:02
Simple session with tokyocabinet
from pytc import HDB, HDBOWRITER, HDBOCREAT
import os
class Session:
""" Simple session class example.
Reading is faster than writing, because every write causes db activity """
hdb = None
dbpath = "session.tch"
def __getitem__(self, key):
ans = getattr(self, key, None)
@MasseR
MasseR / bin.c
Created September 3, 2009 11:54
/* Argument to binary representation */
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int num = 0;
int i;
if(argc < 2)
#!/bin/bash -x
# Copyright (c) 2009 Mats Rauhala <[email protected]>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#!/bin/bash
# Removes valid ips' from denyhosts files. Checks that the input is not empty,
# no further checks are made
#
# Usage: validip.sh ip
if [ "x$1" == "x" ]; then
echo "Input value required"
exit 1
fi
workdir=/var/lib/denyhosts
#!/usr/bin/env python
import twitter
import pynotify
from time import sleep
from getpass import getpass
from sys import exit
from os import fork
pynotify.init("Identi.ca")
#!/bin/sh
# Combining a scanner and a printer as a copy machine. Idea from
# http://mulps.wordpress.com/2009/06/20/scanner-printer-copy-machine/
# with little enhancements.
# Filenames
export SANE_DEFAULT_DEVICE="plustek:libusb:002:002"
original=$(mktemp)
reoriented=$(mktemp)
/*
Copyright (c) 2010 Mats Rauhala <[email protected]>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
@MasseR
MasseR / gist:863061
Created March 9, 2011 21:40
Parsing uzbl history file
{-# LANGUAGE OverloadedStrings #-}
import Data.List (foldl', sort)
import Data.Text.Lazy (Text)
import qualified Data.ByteString.Lazy as BL (ByteString(..), readFile)
import qualified Data.Map as M (assocs, insertWith', empty)
import qualified Data.Text.Lazy as T (words, lines, unpack, pack, append)
import qualified Data.Text.Lazy.Encoding as TE (decodeUtf8)
import qualified Data.Text.Lazy.IO as TI (putStrLn)
import Network.URI(parseURI, uriAuthority, uriRegName)
{-# LANGUAGE OverloadedStrings, QuasiQuotes #-}
import Network.CGI
import Text.Hamlet
import Text.Cassius
import qualified Data.ByteString.Char8 as BS8
import System.Directory (doesFileExist)
import Data.Map (Map)
import qualified Data.Map as M
import Data.List (foldl')
import System.Environment
BEGIN;
CREATE TABLE Employee (Fname, Minit, Lname, Ssn PRIMARY KEY, Bdate,
Address, Sex, Salary, Super_ssn, Dno, FOREIGN KEY (Super_ssn)
REFERENCES Employee (Ssn));
CREATE TABLE Department (Dname, Dnumber PRIMARY KEY, Mgr_ssn, Mgr_start_date, FOREIGN KEY (Mgr_ssn) REFERENCES Employee (Ssn));
CREATE TABLE Dept_locations (Dnumber, Dlocation, PRIMARY KEY (Dnumber, Dlocation), FOREIGN KEY (Dnumber) REFERENCES Department (Dnumber));
CREATE TABLE Works_on (Essn, Pno, Hours, PRIMARY KEY (Essn, Pno), FOREIGN KEY (Essn) REFERENCES Employee (Ssn));
CREATE TABLE Project (Pname, Pnumber PRIMARY KEY, Plocation, Dnum, FOREIGN KEY (Dnum) REFERENCES Department (Dnumber));
CREATE TABLE Dependent (Essn, Dependent_name, Sex, Bdate, Relationship, PRIMARY KEY (Essn, Dependent_name), FOREIGN KEY (Essn) REFERENCES Emplyee (Essn));