Skip to content

Instantly share code, notes, and snippets.

View dvdsgl's full-sized avatar
🦋
Gliding

David Siegel dvdsgl

🦋
Gliding
View GitHub Profile
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)
# 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)
- (NSArray*)mergeSortArrayUsingSelector:(SEL)comparator
{
id buf[[self count]];
[self getObjects:buf];
mergesort_(buf, [self count], comparator);
return [NSArray arrayWithObjects:buf count:[self count]];
}
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.
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 (:[]) (++)
#!/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
using System;
namespace Data
{
public struct Maybe<T> where T : class
{
public static implicit operator Maybe<T> (T value)
{
== Solution: <name of solution> ==
=== Description ===
# Briefly describe the solution.
=== Advantages ===
# List advantages of the solution.
=== Disadvantages ===
# List at least one disadvantage of the solution.
module YataWindow ( YataWindow
, new, showAll
, onMessagePost
, displayTweets
)
where
import Control.Applicative
import Text.Printf (printf)
#!/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"]