Skip to content

Instantly share code, notes, and snippets.

Steve Purcell purcell

Block or report user

Report or block purcell

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
@purcell
purcell / nginx.conf
Created Jan 30, 2014
nginx gzip snippet
View nginx.conf
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 Feb 13, 2014
Parsing spotify json in Haskell
View SpotifyPack.hs
{-# 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 Apr 11, 2014
iStat Menus breakage - console log
View 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
View FizzBuzz.hs
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
View FizzBuzz.hs
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
View FizzBuzz.hs
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]
View puzzle.hs
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 Nov 24, 2009
Hacky script to count words in RSS feeds
View feed_word_counter.rb
#!/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};/, '~')
View foo.clj
;; 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))
View *slime-repl clojure*
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
You can’t perform that action at this time.