Skip to content

Instantly share code, notes, and snippets.

Johnny Karhinen intedinmamma

Block or report user

Report or block intedinmamma

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gpio_callbacks.py
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
View gist:5478739
<?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
View 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)
@intedinmamma
intedinmamma / container.py
Created Apr 14, 2012
Simple DI Container for Python, inspired by Pimple (http://pimple.sensiolabs.org/)
View container.py
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]
@intedinmamma
intedinmamma / RegistrationForm.php
Created Apr 10, 2012
Validation rules for Kohana 3.2 (kinda)
View RegistrationForm.php
<?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() {
@intedinmamma
intedinmamma / about_to_expire.php
Created Mar 14, 2012
PHP script to fetch .se domains about to expire from IIS
View about_to_expire.php
<?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];
}
View val_somewhat_nested.php
<?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;
@intedinmamma
intedinmamma / ghs_newsletter.py
Created Jan 10, 2012
Script för att maila titel + länk från RSS-feeds från de x senaste dagarna
View ghs_newsletter.py
#!/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 = 'ghs@lists.hackerspace.se'
mail_from = 'johnny@nurrd.se'
View something.php
class Tag {
public $name;
public $contents;
public function __construct($name, $contents = array()) {
$this->name = $name;
$this->contents = $contents;
}
public function has_contents() {
@intedinmamma
intedinmamma / Kohana_Mustach.php
Created Dec 15, 2011
Mustache handling partials the Kohana way
View Kohana_Mustach.php
<?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);
}
}
You can’t perform that action at this time.