Skip to content

Instantly share code, notes, and snippets.

Philip Nilsson philipnilsson

Block or report user

Report or block philipnilsson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:9200533
import Control.Monad (void)
import Control.Applicative
import Data.Foldable (for_)
import Data.Monoid
import Text.Printf
data Attributed m w a = Attributed (m a) w
instance Functor m => Functor (Attributed m w) where
fmap f (Attributed m w) = Attributed (fmap f m) w
View gist:9075346
import Text.Parsec
import Control.Applicative hiding ((<|>))
import qualified Data.Map as M
import Data.Either (partitionEithers)
import Data.List (intercalate)
import System.IO (hPutStrLn, stderr)
data Word = Splice String | Word String
deriving (Ord, Eq, Show)
@philipnilsson
philipnilsson / gist:8378133
Last active Feb 25, 2016
Waterflow python
View gist:8378133
import functools
def scanl(f,x,it):
return functools.reduce(lambda xs, y: xs + [f(xs[-1],y)], it, [x])
def scanl1(f, it):
return scanl(f, it[0], it[1:])
def scanr1(f, it):
return reversed(scanl1(f, list(reversed(it))))
@philipnilsson
philipnilsson / gist:8375266
Last active Jan 2, 2016
Missing integer in arithmetic sequence
View gist:8375266
#include <stdio.h>
int main(void) {
int n, e, i = 0;
scanf("%d\n", &n);
scanf("%d", &e);
int sum = e, first = e, last = e, len = 1;
int delta;
while (++i < n) {
scanf(" %d", &e);
View gist:6998139
-- | Experimental and very simple quasi-quotation of ECMAScript in
-- Haskell. Doesn't support anti-quotation as of now.
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE Rank2Types #-}
module Language.ECMAScript5.Syntax.QuasiQuote (js, jsexpr, jsstmt) where
import qualified Language.Haskell.TH as TH
import Language.Haskell.TH.Quote
@philipnilsson
philipnilsson / gist:6988512
Last active Dec 25, 2015
Language.ECMAScript5, unsafeCoerce to universally quantified constructor.
View gist:6988512
-- | Experimental and very simple quasi-quotation of ECMAScript in
-- Haskell. Doesn't support anti-quotation as of now.
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Language.ECMAScript5.Syntax.QuasiQuote (js, jsexpr, jsstmt) where
import qualified Language.Haskell.TH as TH
import Language.Haskell.TH.Quote
import Text.Parsec hiding (parse)
View gist:6069238
nonEmptySubsequences = foldr comb []
where comb x xs = xs ++ fmap (x:) ([]:xs)
findSum p = filter (p.sum) . nonEmptySubsequences
hasSum p = not.null . findSum p
-- Trying it in the REPL
You can’t perform that action at this time.