Skip to content

Instantly share code, notes, and snippets.

@tom-galvin
tom-galvin / c209e.hs
Created April 4, 2015 20:57
DailyProgrammer Challenge #209e Solution (The Button can be pressed but once...)
import Control.Monad
import Data.Char
import Data.List
import Data.Ord
import System.IO
type Time = Double
type User = (String, Time)
readUser :: String -> User
@tom-galvin
tom-galvin / c-gradient.rb
Created March 31, 2015 10:27
DailyProgrammer Challenge #208i Solution (ASCII Gradient Generator)
module C208i
class Gradient
def initialize(gradient)
if gradient.length > 0
@chars = gradient.chars
else
raise Exception.new("Gradient string must not be empty.")
end
end
@tom-galvin
tom-galvin / c-machine.rb
Last active August 29, 2015 14:17
DailyProgrammer Challenge #208h Solution (The Universal Machine)
#!/usr/bin/env ruby
module Machine
class Tape
def initialize(alphabet, initial='')
@alphabet = ('_' + alphabet).chars.uniq.join ''
@head = 0
@tape = Hash.new
initial.each_char do |c|
self.write c
@tom-galvin
tom-galvin / c-machine.hs
Last active August 29, 2015 14:17
DailyProgrammer Challenge #208h Solution (The Universal Machine)
-- My eyes! The goggles do nothing!
import Data.Char
import Data.List
import Data.Maybe
import qualified Data.Map.Strict as Dm
type Symbol = Char
type Alphabet = [Symbol]
type State = String
@tom-galvin
tom-galvin / xsetwacom_my_preferences
Last active August 29, 2015 14:17
Improved xsetwacom preferences helper
#!/bin/bash
if [ $# -eq 0 -o "$1" == "--help" ]; then
echo "Usage: $(basename $0) device screen [-q]"
echo "device The device to set the screen for."
echo " Possible devices:"
xsetwacom --list devices | sed -n 's/\(.*\)id:.*/ * \1/p'
echo "screen The screen to set the given device's region to."
echo " Possible screens:"
echo " * screen (the entire display)"
@tom-galvin
tom-galvin / c206h-compact.hs
Last active August 29, 2015 14:17
DailyProgrammer Challenge #206h Compact Solution (Recurrence Relations, part 2)
import Data.Maybe
import Data.List
import Data.Char
data Successor = Literal Double
| Previous Int
| Binary (Double -> Double -> Double) Successor Successor
| Unary (Double -> Double) Successor
type Term = (Int, Double)
@tom-galvin
tom-galvin / c206h.hs
Last active August 29, 2015 14:17
DailyProgrammer Challenge #206h Solution (Recurrence Relations, part 2)
import Data.Maybe
import Data.List
import Data.Char
-- AST structure for successors
data Successor = Literal Double
| Previous Int
| Binary (Double -> Double -> Double) Successor Successor
| Unary (Double -> Double) Successor
@tom-galvin
tom-galvin / fs-util.fs
Created March 16, 2015 19:01
Miscellaneous F# Utilities
// Don't know why these functions aren't part of the language but there you are.
module Util
module String =
let splitArray (delimiters: string list) (s: string) =
s.Split((Array.ofList delimiters), System.StringSplitOptions.None)
let splitArrayMax (delimiters: string list) max (s: string) =
s.Split((Array.ofList delimiters), max, System.StringSplitOptions.None)
@tom-galvin
tom-galvin / c-recur.fs
Last active August 29, 2015 14:17
DailyProgrammer Challenge #206e Solution (Recurrence Relations, part 1)
open Util // fs-util available at https://gist.github.com/Quackmatic/2309d4f7b93631c99f22
/// Relation tree structure.
type Relation =
| Add of left: Relation * right: Relation
| Subtract of left: Relation * right: Relation
| Multiply of left: Relation * right: Relation
| Divide of left: Relation * right: Relation
| Constant of value: float
| Relative of offset: int
@tom-galvin
tom-galvin / c204e.fs
Created March 2, 2015 20:48
DailyProgrammer Challenge #204e Solution (Remembering your lines)
open System
open System.Text.RegularExpressions
type Passage = { speakers: string list; lines: string list }
type Scene = { numeral: string; setting: string; speakers: string list; passages: Passage list }
type Act = { numeral: string; scenes: Scene list }
type Token =
| OpenAct of numeral: string