Skip to content

Instantly share code, notes, and snippets.

nbogie

Block or report user

Report or block nbogie

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
@nbogie
nbogie / DamageDice.md
Last active Aug 29, 2015
Hoodlums problem - D&D Damage Dice
View DamageDice.md

Here's a simple problem which I found quite fun to implement.

Suggested hoodlums problem (beginner level):

Dungeons and Dragons Damage Dice

Context:

In the game of dungeons and dragons, an example damage expression might be:

View CrapJsonWebsocketServer.hs
-- don't do it like this, especially the json!
import Network.WebSockets (shakeHands, getFrame, putFrame)
import Network (listenOn, PortID(PortNumber), accept, withSocketsDo)
import System.IO (Handle, hClose)
import qualified Data.ByteString as B (append, null)
import Data.ByteString.UTF8 (fromString) -- this is from utf8-string
import Control.Monad (forever)
import Control.Concurrent (forkIO, threadDelay)
import Data.List (intercalate)
View CrapJsonWebsocketClient.html
<html>
<!-- for use with equally crap server at https://gist.github.com/821606 -->
<!-- you'll need jquery and flot -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Flot Log presenter with External json file</title>
<link href="./clientsupport/layout.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript" src="./clientsupport/jquery.js"></script>
<script language="javascript" type="text/javascript" src="./clientsupport/jquery.flot.js"></script>
@nbogie
nbogie / gist:822659
Created Feb 11, 2011
Nokogiri shortcut for using whatever namespace the doc announced
View gist:822659
envNodes = mydoc.xpath '//xmlns:environment', mydoc.root.namespaces
@nbogie
nbogie / GroupExample.hs
Created Mar 5, 2011
Still avoiding bytestring, and without anticipating next stage. Perf ok: 1 million lines in 2 sec and 1 Mb ram, with -O2
View GroupExample.hs
import Data.Function (on)
import Data.List (groupBy)
import Data.Maybe (mapMaybe)
import qualified Data.List.Utils as U
type Domain = String
type NameServer = String
main :: IO ()
main = interact (processLines . lines)
@nbogie
nbogie / GroupExample.hs
Created Mar 5, 2011
break out parseInput - it's good to have dedicated parse stage indicating parsed type.
View GroupExample.hs
import Data.Function (on)
import Data.List (groupBy)
import Data.Maybe (mapMaybe)
import qualified Data.List.Utils as U
type Domain = String
type NameServer = String
main :: IO ()
main = interact process
@nbogie
nbogie / CompactNameServers.hs
Created Mar 17, 2011
Compacts lists of nameservers "a.y.z", "b.y.z" into z(y(a,b))
View CompactNameServers.hs
import qualified Data.List.Utils as U
import Data.List (sort, groupBy, intercalate)
import Data.Function (on)
-- -------------------------------------------------
-- example data
-- -------------------------------------------------
examples :: [(Domain, [NameServer])]
examples = [("pachube.com",["7.f.c",
"5.f.c",
View PodParser.hs
{-- snippet all --}
module PodParser where
import PodTypes
import Text.XML.HaXml
import Text.XML.HaXml.Parse
import Text.XML.HaXml.Posn
import Text.XML.HaXml.Html.Generate(showattr)
import Data.Char
import Data.List
@nbogie
nbogie / haxml_showattr_bugdemo.hs
Created Mar 23, 2011
A demonstration of a problem calling showattr in HaXml
View haxml_showattr_bugdemo.hs
module Main where
import Text.XML.HaXml
import Text.XML.HaXml.Posn
main :: IO ()
main = processXmlWith (hexagrams `o` tag "IChing")
hexagrams :: Content Posn -> [Content Posn]
hexagrams = html [ hbody [htable [rows `o` children `with` ( tag "hexagram")] ] ]
@nbogie
nbogie / whereami-readable.txt
Created Jul 1, 2011
presentation of https://gist.github.com/1056734 for attempted readability
View whereami-readable.txt
echo -n
#quote-escaping removed from the following json
"
{"version": "1.1.0","host": "maps.google.com","request_address": true,"address_language": "en_GB", "wifi_towers":
[
`iwlist scan 2> /dev/null |
tr -d '\n' |
sed -e 's/Cell [0-9]* - Address: \([0-9A-Z:]*\)[^C]*Channel:\([0-9]*\)[^S]*Signal level=\([0-9-]*\) dBm[^E]*E[^E]*ESSID:"\([^"]*\)"/\{"mac_address": "\1","signal_strength": \3,"age": 0,"channel": \2,"ssid": "\4"}/g'
-e 's/[^{]*{/{/'
-e 's/}[^{]*{/},{/g'
You can’t perform that action at this time.