Skip to content

Instantly share code, notes, and snippets.

View uppfinnarjohnny's full-sized avatar

Johnny Karhinen uppfinnarjohnny

View GitHub Profile
@uppfinnarjohnny
uppfinnarjohnny / get_google_spreadsheet.php
Created March 16, 2011 11:11
A simple way of getting the data from a Google Docs Spreadsheet in PHP
<?php
function get_google_spreadsheet($key) {
$url = "https://spreadsheets.google.com/feeds/list/{$key}/od6/public/values";
$google_sheet = file_get_contents($url);
$xml = simplexml_load_string($google_sheet);
$data = array();
foreach($xml->entry as $entry) {
$row = array();
// The fields are in the gsx: namespace, so we need to specify that to be able to access them through SimpleXML.
@uppfinnarjohnny
uppfinnarjohnny / gist:1051819
Created June 28, 2011 18:31
latest_video()
<?php
function latest_video($id_only = False) {
$url = trim(file_get_contents('/home/cyklarunt/latest'));
return $id_only ? end(explode('=', $url)) : $url;
}
@uppfinnarjohnny
uppfinnarjohnny / pick_by_keys.py
Created October 6, 2011 19:03
pick_by_keys()
def pick_by_keys(d, ks):
return dict((k, v) for k, v in d.iteritems() if k in ks)
d = {
'hello': 'world',
'foo': 'bar',
'romeo': 'juliet',
'alice': 'bob'
}
@uppfinnarjohnny
uppfinnarjohnny / admin.py
Created November 14, 2011 12:35
Django app for internal aliases
from alias.models import Alias
from django.contrib import admin
class AliasAdmin(admin.ModelAdmin):
list_display = ('path', 'target')
admin.site.register(Alias, AliasAdmin)
@uppfinnarjohnny
uppfinnarjohnny / php.php
Created November 24, 2011 14:20
Something about lists, references and stuff, in php & python
$some_array[$some_id]['key_one'] = $value_one;
$some_array[$some_id]['key_two'] = $value_two;
$some_array[$some_id]['key_three'] = $value_three;
@uppfinnarjohnny
uppfinnarjohnny / ActiveCollab.php
Created December 5, 2011 16:01
Simple API wrapper for ActiveCollab
<?php
class ActiveCollab {
protected $base_url;
protected $api_key;
public function __construct($base_url, $api_key) {
$this->base_url = $base_url;
$this->api_key = $api_key;
}
@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);
}
}
class Tag {
public $name;
public $contents;
public function __construct($name, $contents = array()) {
$this->name = $name;
$this->contents = $contents;
}
public function has_contents() {
@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]'
<?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;