Skip to content

Instantly share code, notes, and snippets.

View purcell's full-sized avatar

Steve Purcell purcell

View GitHub Profile
@purcell
purcell / nginx.conf
Created January 30, 2014 14:27
nginx gzip snippet
gzip on;
gzip_vary on;
gzip_disable "msie6";
gzip_comp_level 3;
gzip_buffers 16 8k;
gzip_min_length 150;
gzip_proxied any;
gzip_types text/plain text/xhtml text/css text/js text/csv application/javascript application/x-javascript application/json application/xml text/xml application/atom+xml application/rss+xml;
@purcell
purcell / SpotifyPack.hs
Created February 13, 2014 13:16
Parsing spotify json in Haskell
{-# LANGUAGE OverloadedStrings #-}
module SpotifyPack
where
import qualified Network.URI as URI
import Network.HTTP (simpleHTTP, getRequest, getResponseBody)
import Data.Aeson (FromJSON, parseJSON, decode, (.:))
import qualified Data.Aeson.Types as T
import qualified Data.ByteString.Lazy.Char8 as BSL
import Control.Applicative ((<$>), (<*>))
import Control.Monad (mzero)
@purcell
purcell / console.log
Created April 11, 2014 09:55
iStat Menus breakage - console log
11/04/2014 10:49:11.070 SystemUIServer[10295]: Could not load menu extra NSBundle </Library/Application Support/iStat Menus 4/extras/iStatMenusMemory.menu> (not yet loaded) for Class (null)
11/04/2014 10:49:11.071 SystemUIServer[10295]: Cannot find executable for CFBundle 0x7f9bf255df80 </Library/Application Support/iStat Menus 4/extras/iStatMenusDrives.menu> (not loaded)
11/04/2014 10:49:11.071 SystemUIServer[10295]: Could not load menu extra NSBundle </Library/Application Support/iStat Menus 4/extras/iStatMenusDrives.menu> (not yet loaded) for Class (null)
11/04/2014 10:49:11.463 iStatMenusAgent[10329]: Loading istat menus agent
11/04/2014 10:49:11.463 iStatMenusAgent[10329]: iStat Menus Agent version 4.21 (450)
11/04/2014 10:49:11.514 iStatMenusAgent[10329]: iStat Menus Agent - Update checker enabled
11/04/2014 10:49:54.681 SystemUIServer[160]: Cannot find executable for CFBundle 0x7f8dca5181d0 </Library/Application Support/iStat Menus 4/extras/MenuCracker.menu> (not loaded)
11/04/2014 10:49:54.682 SystemU
@purcell
purcell / FizzBuzz.hs
Created October 29, 2014 22:49
fizzbuzz
module FizzBuzz where
data FizzBuzz = Fizz | Buzz | FizzBuzz deriving Show
fizzbuzz :: Integral a => a -> Either FizzBuzz a
fizzbuzz n = case (n `rem` 3, n `rem` 5) of
(0, 0) -> Left FizzBuzz
(0, _) -> Left Fizz
(_, 0) -> Left Buzz
_ -> Right n
@purcell
purcell / FizzBuzz.hs
Created October 30, 2014 11:22
fizzbuzz
module FizzBuzz where
import Data.Maybe
data FizzBuzz = Fizz | Buzz deriving Show
whenDivisible :: Integral a => a -> b -> a -> Maybe b
whenDivisible d x n = if n `rem` d == 0 then Just x else Nothing
fizzbuzz :: (Show a, Integral a) => a -> String
fizzbuzz n = if null tags then show n else concatMap show tags
@purcell
purcell / FizzBuzz.hs
Created October 30, 2014 12:18
fizzbuzz
module FizzBuzz where
fizzbuzz :: (Show a, Integral a) => a -> String
fizzbuzz n = case (n `rem` 3, n `rem` 5) of
(0, 0) -> "FizzBuzz"
(0, _) -> "Fizz"
(_, 0) -> "Buzz"
_ -> show n
main = mapM_ (putStrLn . fizzbuzz) [1..50]
module Puzzle where
valid :: Integer -> Bool
valid abcde = divisibleBy bcde && divisibleBy cde && divisibleBy de && divisibleBy e
where divisibleBy n = n /= 0 && ((abcde `mod` n) == 0)
bcde = abcde `mod` 10000
cde = bcde `mod` 1000
de = cde `mod` 100
e = de `mod` 10
@purcell
purcell / feed_word_counter.rb
Created November 24, 2009 16:21
Hacky script to count words in RSS feeds
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
class String
def strip_tags
gsub(/&lt;/, '<').gsub(/&gt;/, '>').gsub(/<.*?>/, ' ').gsub(/&amp;#\d{4};/, '~')
;; Feedback on http://www.fatvat.co.uk/2009/07/merging-rss-feeds.html
;; Original
(defn join-all
"Join the lists provided using f to select an element each time"
[f & lists]
(let [l (remove empty? lists)]
(when-not (empty? l)
(let [n (reduce f (map first l))
c (count (filter #(= (first %) n) l))
user> (pprint (macroexpand-1 '(bar-chart (map (comp str first) d) (map (comp #(/ % 1000.0) second) d) :title "Distance by week" :x-label "Week" :y-label "km")))
(clojure.core/let
[opts__1904__auto__
(clojure.core/when
'(:title "Distance by week" :x-label "Week" :y-label "km")
(clojure.core/assoc
{}
:title
"Distance by week"
:x-label