Skip to content

Instantly share code, notes, and snippets.

View tinnet's full-sized avatar
🐼

Martin Contento tinnet

🐼
View GitHub Profile
@tinnet
tinnet / zpipe.c
Created May 25, 2011 11:25
zpipe.c with modified magic numbers
/* zpipe.c: example of proper use of zlib's inflate() and deflate()
Not copyrighted -- provided to the public domain
Version 1.2 9 November 2004 Mark Adler */
/* Version history:
1.0 30 Oct 2004 First version
1.1 8 Nov 2004 Add void casting for unused return values
Use switch statement for inflate() return values
1.2 9 Nov 2004 Add assertions to document zlib guarantees
1.3 6 Apr 2005 Remove incorrect assertion in inf()
@tinnet
tinnet / gist:1026668
Created June 15, 2011 07:59
mysql timestamp fun
CREATE TABLE `mails` (
`id` bigint(20) NOT NULL auto_increment,
`email` varchar(250) NOT NULL,
`type` char(6) NOT NULL,
`time` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
KEY `time` (`time`),
KEY `type` (`type`)
) ENGINE=MyISAM;
@tinnet
tinnet / dateblacklist.py
Created July 6, 2011 08:07
string compare vs. precompiled regex
#Took: 6.605544 seconds
#Took: 15.969022 seconds
#Took: 4.270395 seconds
#Took: 3.229852 seconds
import re
import time
DATETIME_BLACKLIST = ['1970-01-01 01:00:00', '1970-01-01 00:00:00', '0000-00-00 00:00:00']
@tinnet
tinnet / radio7.py
Created September 7, 2011 16:42
radio7 watcher...
import time
import urllib2
from BeautifulSoup import BeautifulSoup
from pygame import mixer
log = open("radio7.log", "a")
mixer.init()
alert = mixer.Sound('alarm.wav')
lastpic = ""
@tinnet
tinnet / gist:1343179
Created November 6, 2011 17:02
anti-mongodb rant (mirror from pastebin)
Don't use MongoDB
=================
I've kept quiet for awhile for various political reasons, but I now
feel a kind of social responsibility to deter people from banking
their business on MongoDB.
Our team did serious load on MongoDB on a large (10s of millions
of users, high profile company) userbase, expecting, from early good
experiences, that the long-term scalability benefits touted by 10gen
@tinnet
tinnet / namespaces.php
Created December 13, 2011 16:46
using namespaces to override global functions(?)
<?php
namespace FOO;
function strlen($arg) {
return 42;
}
// "my" strlen
echo strlen('lala'), "\n";
@tinnet
tinnet / timed_runner.py
Created February 26, 2012 17:50
runs another python module for a maximum time
import imp
import os
import sys
import threading
USAGE = "python %s YOUR_MODULE TIMEOUT_IN_SECONDS arg1 arg2 arg3" % sys.argv[0]
class ModuleRunner(threading.Thread):
def __init__(self, module_name):
threading.Thread.__init__(self)
public class Main {
static interface InterfaceA {
public void speak();
}
static interface InterfaceB extends InterfaceA {
public void sit();
}
@tinnet
tinnet / flaskrouting.py
Created November 12, 2012 13:42
flask extension pluggable views routing errors
import flask
import flask.views
import logging
logging.basicConfig(level=logging.DEBUG)
class MyFlaskExt(object):
def __init__(self, app=None):
if app is not None:
self.init_app(app)
@tinnet
tinnet / urlchecker.py
Created January 10, 2013 11:11
Small python (2.7) script to check .csv files full of urls for their current status code (for example to verify if you fixed the issues google webmaster tools is reporting)
from __future__ import print_function
import argparse
import csv
import requests
import sys
_EPILOG = """
Script takes a list of .csv files, tries to guess their format (seperator),
then checks for a field called 'URL', tries to fetch that url and prints