Skip to content

Instantly share code, notes, and snippets.

@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();
@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))));
@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;
@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
)
@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]
@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)
@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];
<?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
*/
@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
@staatzstreich
staatzstreich / ftp_download.php
Created November 30, 2012 12:45
Download a directory from an FTP Server
<?php
// ftp_sync - copy directory and file structure
// based on http://www.php.net/manual/es/function.ftp-get.php#90910
// main function witch is called recursivly
function ftp_sync($dir, $conn_id) {
if ($dir !== '.') {
if (ftp_chdir($conn_id, $dir) === FALSE) {
echo 'Change dir failed: ' . $dir . PHP_EOL;
return;