Skip to content

Instantly share code, notes, and snippets.

@5outh
5outh / graphFromFile.hs
Created December 5, 2012 22:04
Graph from file
graphFromFile :: String -> IO (Graph String)
graphFromFile f = do
contents <- readFile f
let info = map words $ lines contents
verts = nub . concat $ info
conns = map (\[a, b] -> (a, b)) info
graph = Graph verts conns
return graph
<?php
/*
* Get all 52 weeks of the year and work days given the first day of the January of current year
* @link http://stackoverflow.com/a/14147613/367456
* @author hakre <http://hakre.wordpress.com/credits>
*/
/**
* Filter a DatePeriod by year
*/
@mplewis
mplewis / threePipeDemo.c
Created March 31, 2013 01:31
Here's an example of how to pipe three commands together using C. This one uses `ps aux | grep root | grep sbin`. This topic is horribly documented online so hopefully this'll help someone else out.
// This program is an example of how to run a command such as
// ps aux | grep root | grep sbin
// using C and Unix.
#include <stdlib.h>
#include <unistd.h>
int pid;
int pipe1[2];
int pipe2[2];
@aldanor
aldanor / graphsearch.hs
Created May 22, 2013 21:57
obscure graph hackage
import Data.List (unfoldr, minimumBy)
import Data.Char (isSpace)
import Data.Function (on)
import Data.Maybe (mapMaybe, fromMaybe)
import System.Environment (getArgs)
import qualified Data.ByteString.Char8 as L
import qualified Data.IntMap as IM
type GraphData = (IM.IntMap (IM.IntMap [(Int, Int)]), Int)
@owainlewis
owainlewis / GraphsAlgs.hs
Created May 29, 2013 12:58
Haskell Graph Stuff
module GraphsAlgs
where
import List
import While
import Assert
import Reasoning (update,updates)
reachable :: Eq a => [(a,a)] -> a -> [a]
@aronkerr
aronkerr / original.sql
Last active November 23, 2017 04:28
ZF2 Sql Exists sub query using ZF2 query helpers
SELECT *
FROM SOME_TABLE_ONE STO
WHERE EXISTS (
SELECT *
FROM SOME_TABLE_TWO STT
WHERE STO.STT_ID = STT.ID
)
@holabene
holabene / guzzle-cache-plugin.php
Last active January 23, 2020 15:57
Guzzle cache that actually works..
<?php
/**
* Caching to filesystem using ZendCache
* Cache as much as possible, very convenient for dev (default ttl = 3600)
*/
use Guzzle\Http\Client;
use Guzzle\Plugin\Cache\CachePlugin;
use Guzzle\Plugin\Cache\SkipRevalidation;
use Guzzle\Plugin\Cache\DefaultCacheStorage;
@lucabrunox
lucabrunox / http_header_parse.php
Created October 14, 2013 15:19
Parse HTTP headers in PHP.
$header = "...";
$parsed = array_map(function($x) { return array_map("trim", explode(":", $x, 2)); },array_filter(array_map("trim", explode("\n", $header))));
@correl
correl / filter.php
Created November 13, 2013 13:53
Manipulating multidimensional data structures in PHP
<?php
class KeyError extends Exception {};
function filter_tree($tree, $fields) {
if (empty($fields))
{
return $tree;
}
$result = array();
@5outh
5outh / DeMorgan.hs
Created November 13, 2013 17:04
DeMorgan
{-# LANGUAGE NoMonomorphismRestriction #-}
import Text.ParserCombinators.Parsec
import Text.ParserCombinators.Parsec.Token hiding (parens)
import Text.ParserCombinators.Parsec.Expr
import Control.Applicative hiding ((<|>))
import Control.Monad
import Prelude hiding (not)
data Expr = Not Expr | And Expr Expr | Or Expr Expr | Var Char | SubExpr Expr deriving Eq