Skip to content

Instantly share code, notes, and snippets.

View uppfinnarjohnny's full-sized avatar

Johnny Karhinen uppfinnarjohnny

View GitHub Profile
import RPi.GPIO as GPIO
import urllib.request
PIN = 5
LOW_CALLBACK_ADDRESS = 'http://google.com'
HIGH_CALLBACK_ADDRESS = 'http://facebook.com'
DEBOUNCE_TIME_MS = 200
<?php
/*
* File Name: Database.php
* Date: November 18, 2008
* Author: Angelo Rodrigues
* Description: Contains database connection, result
* Management functions, input validation
*
* All functions return true if completed
* successfully and false if an error
@uppfinnarjohnny
uppfinnarjohnny / playcount.py
Created April 20, 2012 05:54 — forked from archie/playcount.py
Playcount.py
import sys
import random
import math
from collections import defaultdict
if len(sys.argv) != 3:
print "Usage: ./playcount.py <file_to_parse> <output_counts_to_file>"
exit(1)
countmap = defaultdict(int)
@uppfinnarjohnny
uppfinnarjohnny / container.py
Created April 14, 2012 16:59
Simple DI Container for Python, inspired by Pimple (http://pimple.sensiolabs.org/)
class Container(dict):
def __init__(self, *args, **kwargs):
super(Container, self).__init__(*args, **kwargs)
self._shared = set()
self._instances = {}
def __getitem__(self, key):
if key in self._instances:
return self._instances[key]
@uppfinnarjohnny
uppfinnarjohnny / RegistrationForm.php
Created April 10, 2012 13:12
Validation rules for Kohana 3.2 (kinda)
<?php
class RegistrationForm extends Validation {
public function __construct(Array $array) {
parent::__construct($array);
$this->rule('username', 'not_empty');
$this->rule('password', 'not_empty');
$this->rule('password_confirmation', 'matches', array(':validation', 'confirm', 'password'));
}
public function check() {
@uppfinnarjohnny
uppfinnarjohnny / about_to_expire.php
Created March 14, 2012 12:20
PHP script to fetch .se domains about to expire from IIS
<?php
$data = file_get_contents('https://www.iis.se/data/bardate_domains.txt');
$limit = 4;
$domains = array();
foreach(explode("\n", $data) as $line) {
$parts = array_filter(array_map('trim', explode("\t", $line)));
if($parts && strlen($parts[0]) < $limit + 3)
$domains[$parts[0]] = $parts[1];
}
<?php
function val_somewhat_nested($name = null, $value = null, $is_mutable = false) {
static $values = array();
static $mutables = array();
if($name === null)
return $values;
if($value === null)
return isset($values[$name]) ? $values[$name] : null;
@uppfinnarjohnny
uppfinnarjohnny / ghs_newsletter.py
Created January 10, 2012 11:30
Script för att maila titel + länk från RSS-feeds från de x senaste dagarna
#!/usr/bin/python
import feedparser
import time
import sys
days_back = 7
feed_urls = ['http://gbg.hackerspace.se/site/feed', 'http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=gbghackerspace']
mail_to = '[email protected]'
mail_from = '[email protected]'
class Tag {
public $name;
public $contents;
public function __construct($name, $contents = array()) {
$this->name = $name;
$this->contents = $contents;
}
public function has_contents() {
@uppfinnarjohnny
uppfinnarjohnny / Kohana_Mustach.php
Created December 15, 2011 08:44
Mustache handling partials the Kohana way
<?php
class Kohana_Mustache extends Mustache {
protected function _getPartial($tag_name) {
$filename = Kohana::find_file('templates', $tag_name, 'mustache');
return file_exists($filename) ? file_get_contents($filename) : parent::_getPartial($tag_name);
}
}