Skip to content

Instantly share code, notes, and snippets.

View Burgestrand's full-sized avatar
🙃
(:

Kim Burgestrand Burgestrand

🙃
(:
View GitHub Profile
@Burgestrand
Burgestrand / MagicDot.hs
Created September 22, 2009 00:05
Re-implemented dot operator using fmap.
module MagicDot ((.)) where
import Prelude hiding ((.))
import Control.Monad.Instances
(.) :: (Functor f) => (a -> b) -> f a -> f b
a . b = a `fmap` b
infixr 9 .
@Burgestrand
Burgestrand / Ternary.hs
Created October 26, 2009 20:07
Ternary operator for haskell
module Ternary where
-- | Ternary operator.
-- Usage: (i > 0) ? i $ 1
(?) :: Bool -> a -> a -> a
True ? x = const x
False ? _ = id
-- | Higher order ternary operator.
-- Usage: (not . null) ?? "" $ "default"
@Burgestrand
Burgestrand / lcdir.php
Created November 15, 2009 15:17
Count the total number of lines in files in a directory.
#!/usr/bin/env php
<?php
// Konfiguration
$dir = NULL; // Mapp du vill räkna rader ur
$verbose = TRUE; // visa antal rader för varje fil
/* Arbetande kod
-------------------------------------------------------------------------*/
$path = isset($argv[1]) ? $argv[1] : (is_null($dir) ? '.' : $dir);
$path = realpath($path);
@Burgestrand
Burgestrand / expanding-textarea.htm
Created January 16, 2010 14:00
A self-expanding textarea similar to Facebook’s implementation
<!DOCTYPE html>
<html>
<head>
<title>Self-expanding textarea</title>
</head>
<body>
<textarea id="expand" rows="8" cols="40"></textarea>
<script type="text/javascript" charset="utf-8">
var textarea = document.getElementById('expand')
var div = document.createElement('div')
@Burgestrand
Burgestrand / gist:316729
Created February 27, 2010 14:50
Find and replace (recursively) in multiple files
ack -l -Q 'gpl-3.0.txt' | xargs sed -i .bak 's#http://www.gnu.org/licenses/gpl-3.0.txt#http://sam.zoy.org/wtfpl/#g'
@Burgestrand
Burgestrand / exempel.php
Created March 1, 2010 00:08
A paging example
<?php
require 'html.php';
// Lite variabler
$page = isset($_GET['start']) ? max((int)$_GET['start'], 1) : 1; // nuvarande sida
$items_per_page = 25; // antal saker per sida
$total_items = 10000; // antal saker (totalt), fås troligtvis från en “SELECT COUNT(*) FROM …” query
$paging = paging($page, ceil($total_items / $items_per_page), 3);
// Paging innehåller nu all HTML som behövs för din paging, skriv ut den på rätt plats
@Burgestrand
Burgestrand / kim@burgestrand.se.asc
Created March 1, 2010 13:52
Kim Burgestrands’ public PGP key
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQGiBEuLwZMRBACm0cVIw+vNU5ny8nBy28D6IVOJCm5YVAhyuISZLCmKs2u0zPkn
+35TKhjTBo0w9wflYa/nFfQjY3N6V9zVOCbDSlEfFwo+rSS0xAGYpu0y6r0R9FvK
h5LjAGIG+thFLYD9LJgRjuewlCu5bTJxznmzGV4Btq3p3uJPPA5CjAj9YwCgyyuA
uDOHvaRkJ/h6dIUjoyaGHjUEAIW0FyR4mrBpwBWUPWH8OyNWaf8C91ZspkRXABE7
t2R1YHJz2Gbk6dhIpfSlkBPS80rWtbCZIPLbEImAWkkmLtsoiHkdLI9DEZ2XIP6q
SBCk6xCeJMLcBGfazbma7ADb5vi9V1tiurvWPBOVDPOUFRjU6JqYuOMK+tuDWHJN
UDNDA/9lKIInAYaL7NR+p2KTYbM3qv9Zcw059T/htbEwIFZ4Mywgl4WK8eZ54PCR
1dpr/5LI+nJEnPxCRkgZ+ald5loottS2gZYsVAertrdrON3ohrvxdJEdGw9+qQb9
@Burgestrand
Burgestrand / View.php
Created March 14, 2010 12:52
An example of a View pattern
<?php
class View
{
private $_file;
private $_locals = array();
/**
* Skapa en ny View med rätt fil och lokal data
*
* @param string sökväg till fil
@Burgestrand
Burgestrand / auth.php
Created March 22, 2010 13:09
Ett Auth-exempel med “kom ihåg mig”-funktion
<?php
class Auth
{
protected $_session;
protected static $_instance;
protected function __construct()
{
// Hämta en sessionsinstans
$this->_session = Session::instance();
@Burgestrand
Burgestrand / index.php
Created April 26, 2010 16:31
Namninsamlingsscript
<?php
require './model.php';
$model = new Namninsamling;
/**
* Returnerar det givna indexet ur en array om det finns, annars $default
*
* @param array
* @param mixed $index
* @param mixed $default