Skip to content

Instantly share code, notes, and snippets.

@NeilRobbins
NeilRobbins / Alt.Fizzbuzz.hs
Last active December 15, 2015 02:49
Fizzbuzz in Haskell - just because
import System.Environment
main = do (countTo:_) <- getArgs
let numbers = fizzbuzz [0..(read countTo)]
mapM_ putStr $ map (\n -> n ++ ", ") $ init numbers
putStrLn $ last numbers
divides d n = rem n d == 0
fb x = if (divides 15 x) then "Fizzbuzz" else if (divides 3 x) then "Fizz" else if (divides 5 x) then "Buzz" else show x
@NeilRobbins
NeilRobbins / Hunt in files for things.sh
Last active December 16, 2015 20:49
Change the regex to match requirements Example 1 (line 1) Search in packages.xml files for those that reference a given package. Example 2 (line 3) Search in csproj files for references
find . -name packages.config -exec grep -H -n '^.*System.Windows.*' {} \;
find . -name *.csproj -exec grep -H -n '^.*<Reference Include="System.Windows.Controls.Toolkit.Internals, Version=4.0.5.0, Culture=neutral, PublicKeyToken=2c5c654d367bf4a7, processorArchitecture=MSIL">' {} \;
(ns tron.neil.bots
(:require [tron.core :as tron]))
(def directions {:right [1 0]
:down [0 1]
:left [-1 0]
:up [0 -1]})
(def pos [3 4])
@NeilRobbins
NeilRobbins / tron.bot.clj
Last active December 17, 2015 13:39 — forked from cgrand/tron.bot.clj
;Circle
(ns tron.neil.bots
(:require [tron.core :as tron]))
(def directions {:right [1 0]
:down [0 1]
:left [-1 0]
:up [0 -1]})
(require '[clojure.zip :as zip])
(def v [[[1 2 [3 4]] [:a [[ :b :c] :d]]] ["f" "g"] [[["h"] "i"] "j"]])
(def z (zip/vector-zip v))
z
( -> z zip/node)
( -> z
(defprotocol LNext
(foo [this] [this a] "this is a foo 1")
(bar [this a] "this is a bar"))
(extend-protocol LNext
String
(foo
([this] (str this " with extra goodness!"))
([this a] (str this " with double extra goodness!!" a)))
(defn foo
[arg]
(cond
(string? arg)
(println "a string")
(and (number? arg)
(pos? arg))
(println "pos arg yo!")
@NeilRobbins
NeilRobbins / LinesToQuotedCSV
Last active December 19, 2015 05:19
Take a file and make a csv from each line, trimming each line for excess whitespace, and placing its contents into double quotes. Use the uniq utility to remove any duplicate lines.
awk '{gsub (/^[ \t]+|[ \t]+$/,""); print "\"" $0 "\"," > "OUTPUT.csv" }' INPUT.txt
@NeilRobbins
NeilRobbins / Drop_unique_constraints_across_schemas.sql
Last active December 27, 2015 12:39
Drop all unique constraints from a named table, across all schemas with instances of that schema. Be aware that using the information_schema.table_constraints for schema names is not reliable and that sys.objects is preferred.
DECLARE @constraints_to_remove TABLE (
schemaName nvarchar(128) NOT NULL,
tableName sysname NOT NULL,
constraintName sysname NOT NULL);
INSERT @constraints_to_remove (
schemaName,
tableName,
constraintName)
SELECT
@NeilRobbins
NeilRobbins / dumpgitlog
Created November 12, 2013 14:03
Dump the full git log to a text file with pretty-printed graph, and short date format
git log --pretty=format:"%h%x09%an%x09%ad%x09%s" --graph --date=short > gitlog.txt