This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$some_array[$some_id]['key_one'] = $value_one; | |
$some_array[$some_id]['key_two'] = $value_two; | |
$some_array[$some_id]['key_three'] = $value_three; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from alias.models import Alias | |
from django.contrib import admin | |
class AliasAdmin(admin.ModelAdmin): | |
list_display = ('path', 'target') | |
admin.site.register(Alias, AliasAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function latest_video($id_only = False) { | |
$url = trim(file_get_contents('/home/cyklarunt/latest')); | |
return $id_only ? end(explode('=', $url)) : $url; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include('posts_model.php'); | |
$posts = get_posts(); | |
include('view.php'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function word_pairs($string, $min_matches = 1) { | |
$pair_counts = array(); | |
$words = explode(' ', $string); | |
$previous_word = FALSE; | |
foreach($words as $word) { | |
if($previous_word) | |
$pair_counts[$previous_word.' '.$word]++; | |
$previous_word = $word; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function rollover($max, $value) { | |
return $value < $max ? $value : rollover($max, $value - $max); | |
} | |
function caesar_cipher($string, $offset = 3) { | |
$letter_numbers = array_map('ord', str_split(strtolower($string))); | |
foreach($letter_numbers as &$number) | |
if($number >= 97 && $number <= 122) | |
$number = rollover(25, $number - 97 + $offset) + 97; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function swedish_date($date = NULL) { | |
if(is_null($date)) | |
$date = time(); | |
elseif( ! is_numeric($date)) | |
$date = strtotime($date); | |
set_locale(LC_TIME, 'sv_SV'); | |
return strftime('%A den %e %B %Y' , $date); | |
} |