Skip to content

Instantly share code, notes, and snippets.

Avatar

David Siegel dvdsgl

View GitHub Profile
View gist:153825
import System (system)
import System.Posix (sleep)
import Text.Printf (printf)
import Flickr.Monad
import Flickr.Types
import Flickr.Photos
import Flickr.URLs (photoSourceURL)
import Flickr.Groups.Pools (getPhotos)
View gist:155094
# Lists is an array of sorted lists (arrays):
# [ [...], [...], … ]
def ListMerge(Lists):
# The number of elements awaiting merge in each list.
sizes = [len(L) for L in Lists]
# Create a heap with a slot for each list.
heap = range(len(Lists))
for i in heap:
# Heap elements are (key, value) pairs of (element, List index)
heap[i] = (Lists[i][0], i)
View gist:155095
- (NSArray*)mergeSortArrayUsingSelector:(SEL)comparator
{
id buf[[self count]];
[self getObjects:buf];
mergesort_(buf, [self count], comparator);
return [NSArray arrayWithObjects:buf count:[self count]];
}
View gist:155103
void mergesort_(id* objs, size_t count, SEL cmp)
{
// Base case.
if (count < 2) return;
size_t left_count = count / 2;
size_t right_count = count – left_count;
id left_objs[left_count];
id right_objs[right_count];
// Function pointer for comparison IMP.
View gist:155116
data Tree a = Branch (Tree a) (Tree a)
| Leaf a
treeOp :: (a -> b) -> (b -> b -> b) -> Tree a -> b
treeOp fL fB (Leaf a) = fL a
treeop fL fB (Branch t1 t2) = treeOp fL fB t1 `fB` treeOp fL fB t2
myFringe :: Tree a -> [a]
myFringe = treeOp (:[]) (++)
View gist:163462
#!/bin/bash
# Install dependencies
sudo apt-get install ghc6 ghc6-prof ghc6-doc haddock libglut-dev happy alex \
libedit-dev zlib1g-dev checkinstall
# Get haskell-platform
wget http://hackage.haskell.org/platform/2009.2.0.2/haskell-platform-2009.2.0.2.tar.gz
tar -xzf haskell-platform-2009.2.0.2.tar.gz
cd haskell-platform-2009.2.0.2
View gist:171666
using System;
namespace Data
{
public struct Maybe<T> where T : class
{
public static implicit operator Maybe<T> (T value)
{
View gist:241521
== Solution: <name of solution> ==
=== Description ===
# Briefly describe the solution.
=== Advantages ===
# List advantages of the solution.
=== Disadvantages ===
# List at least one disadvantage of the solution.
View YataWindow.hs
module YataWindow ( YataWindow
, new, showAll
, onMessagePost
, displayTweets
)
where
import Control.Applicative
import Text.Printf (printf)
View jonometer.hs
#!/usr/bin/runhaskell
import Data.List (isInfixOf)
import Web.Twitter (getUserTimeline)
import Web.Twitter.Monad (runTM)
import Web.Twitter.Fetch (nullAuthUser)
import Web.Twitter.Types (Status (..))
username = "jonobacon"
patterns = ["rock", "awesome", "jam"]