Skip to content

Instantly share code, notes, and snippets.

View gist:2552549
let teamIds = nub $ concatMap ((\g -> [gameTeam1 g, gameTeam2 g]) . entityVal) games
$teamIds = array();
foreach($games as $e) {
$g = $e->getValue();
$teamIds[] = $g->getTeam1();
$teamIds[] = $g->getTeam2();
jhartikainen / gist:2522353
Created Apr 28, 2012
Multi-checkbox select field for Yesod
View gist:2522353
multiCheckBoxList :: (Eq a, RenderMessage master FormMessage, RenderMessage master msg) => [(msg, a)] -> Field sub master [a]
multiCheckBoxList = multiCheckBox . optionsPairs
multiCheckBox :: (Eq a, RenderMessage master FormMessage) => GHandler sub master (OptionList a) -> Field sub master [a]
multiCheckBox opts' = Field
{ fieldParse = \rawVals -> do
opts <- opts'
let (lefts, rights) = partitionEithers $ map (fieldParser opts) rawVals
if (length lefts) > 0
jhartikainen / QueryPaginator.php
Created Feb 1, 2012
Doctrine 2 pagination adapter for Zend_Paginator
View QueryPaginator.php
namespace Wantlet\ORM;
use Zend_Paginator_Adapter_Interface;
use Doctrine\ORM\Query;
* Zend_Paginator adapter for Doctrine 2 queries
class QueryPaginator implements Zend_Paginator_Adapter_Interface {
jhartikainen / gist:1635885
Created Jan 18, 2012
Example of using Array.prototype.some in a sequential flow control fashion
View gist:1635885
//following functions would perform some operations, which would either succeed or fail,
//which would be indicated by the function returning true or false
function a() {
//do something which returns true or false
function b() {
//do something which returns true or false
jhartikainen / gist:1596108
Created Jan 11, 2012
List of weapon names used by Battlefield 3 server admin protocol. How did it get this inconsistent, I have no clue.
View gist:1596108
jhartikainen / gist:1576557
Created Jan 8, 2012
Function for executing things in parallel, because I couldn't find any I liked =)
View gist:1576557
parallel = (ops) ->
results = []
numOps = ops.length
errHandler = null
hadError = false
okHandler = null
for op, num in ops
do (num) ->
jhartikainen / gist:1326104
Created Oct 30, 2011
Example Doctrine 2 uniqueness validator for Zend_Form or such
View gist:1326104
use Doctrine\ORM\EntityRepository;
class Wantlet_Validate_EmailAvailable extends Zend_Validate_Abstract {
const NOT_AVAILABLE = 'notAvailable';
protected $_messageTemplates = array(
self::NOT_AVAILABLE => "Email address '%value%' is already in use"
jhartikainen /
Created Oct 6, 2011
Very quick Battlelog soldier statistics scraper
# This script scrapes your soldier statistics from Battlelog
# NOTE: This is just a very quick demonstration, it doesn't really do much as-is, besides
# authenticate to Battlelog and get you a dict of your soldier's statistics.
# There is no error handling, no anything. It will only work if everything goes well.
# Input your Origin username and password into the params dict below and it should work.
# In the very bottom, the stats dict will contain the data from the Battlelog JSON response.
jhartikainen / DynLoad.hs
Created Aug 20, 2011
Module for loading modules dynamically in Haskell
View DynLoad.hs
{-# LANGUAGE ScopedTypeVariables #-}
module DynLoad (
) where
import Control.Exception (throw)
import GHC hiding (loadModule)
import GHC.Paths (libdir)
import HscTypes (SourceError, srcErrorMessages)
jhartikainen / gist:1053718
Created Jun 29, 2011
ZF controller plugin which fakes requests into XMLHttpRequests
View gist:1053718
* This plugin automatically converts requests made with GET parameter "dojo_io_iframe" into XMLHttpRequests
* This allows transparent handling of iframe transport requests with code that handles XHR requests, since they're
* both essentially the same anyway - only the transport is different.
class Wantlet_Controller_Plugin_IframeRequestHandler extends Zend_Controller_Plugin_Abstract {
private $isIframe = false;