Skip to content

Instantly share code, notes, and snippets.

View md2perpe's full-sized avatar

Per Persson md2perpe

View GitHub Profile
@svebal
svebal / modifier.parseXML.php
Created June 10, 2011 05:55 — forked from derpixler/modifier.parseXML.php
Smarty Modifier parseXML to Array
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage PluginsModifier
*/
/**
* Smarty {$xml|parseXML} function plugin
*
<?php
require_once "lib/compra.php";
require_once "lib/sheen.php";
require_once "lib/beggar.php";
use compra\Compra;
use sheen\View;
use beggar\Request;
function templatize($req, $res) {
@dg
dg / ObjectTrait.php
Created July 2, 2011 04:20
Nette\ObjectTrait
<?php
/**
* This file is part of the Nette Framework (http://nette.org)
*
* Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
*/
@luqui
luqui / continuous.mkd
Created July 2, 2011 07:38
Continuous well-orders

Let [ ] : Ord -> Relation Nat be a function that realizes an ordinal into a well-ordering of the naturals with that order type.

Given a relation R on the naturals, we define the restricted relation R(<n) to be R but just acting on the first n naturals.

Defn: [ ] is continuous iff for every series of ordinals a_i whose limit is l, for every natural n, there exists an i such that for all j > i, [a_i](<n) = [l](<n).

Intuitively, if you are only looking at a finite prefix of the naturals, you can get to a limit ordinal by going finitely high up its limit sequence.

@fundon
fundon / aop.php
Created July 6, 2011 09:40
PHP, Aspect Oriented Programming(AOP). @author: wuzhenyu
<?php
function e($str){echo $str , "\n";}
class AOP
{
static function getInstance()
{
$args = func_get_args();
$class = array_shift($args);
@axman6
axman6 / gist:1074170
Created July 10, 2011 02:17
Binary tree that allows lazy reading from disk (if used with bytestring-mmap)
data BTree a
= Null
| Leaf a
| Node a (BTree a) (BTree a)
deriving (Show)
-- makeTree :: [a] -> BTree a
-- makeTree xs =
instance Binary a => Binary (BTree a) where
{
process := make(chan *feat.Feature)
buffer := make(chan *feat.Feature, 1000)
wg := new(sync.WaitGroup)
if *cores < 2 {
*cores = 2
}
for i := 0; i < *cores-1; i++ {
go func(){wg.Add(1); processServer(intervalTree, process, buffer); wg.Done()}
}
-- This changes bookAuthorCredit from AuthorCreditReference to AuthorCredit
loadAuthorCredit :: Book -> Model Book
-- This changes all PersonReference's in an AuthorCredit to just Person
loadForAuthorCredits :: AuthorCredit -> Model AuthorCredit
-- This gets the AuthorCredit for a Book
bookAuthorCredit :: Book -> AuthorCredit
-- This 'sets' the AuthorCredit for a Book (returning a new Book)
bookResource :: Controller ()
bookResource = do
gid <- ((fromString . unpack . fromJust) <$> getParam "gid") >>= (\gid' -> gid' `onNothing` "Invalid BBID")
maybeBook <- model $ getBook gid
case maybeBook of
Nothing -> generic404 "The request book could not be found"
Just book -> do
book <- model $ loadAuthorCredit book
book <- model $ set lBookAuthorCredit book <$> (loadForAuthorCredits $ bookAuthorCredit book)
editions <- model $ findBookEditions book
modelIO :: IO a -> Model a
modelIO action = do
Model $ ReaderT (\_ -> action)
insertBook :: Book -> Model (LoadedCoreEntity Book)
insertBook bookSpec = do
bookGid <- (modelIO randomIO) :: Model UUID
bookRow <- head `fmap` query insertQuery [ toSql "Hello" ]
return $ bookFromRow bookRow
where insertQuery = unlines [ "INSERT INTO book (name)"