Skip to content

Instantly share code, notes, and snippets.

@NeilRobbins
NeilRobbins / params.sh
Created January 8, 2014 14:04
Some simple argument handling for use in shell scripts. HT to an answer on StackOverflow.
#! /bin/sh -
#argument defaults
x="foo"
y="bar"
# argument handling
while test $# -gt 0
do
case "$1" in
@NeilRobbins
NeilRobbins / TableCounts.sh
Last active January 2, 2016 12:09
List count of each vertica table in a schema (though regex could be used to match on properties other than the schema name).
vsql -e -w "PasswordHere" -c "\dt" | awk 'BEGIN { FS = "|" } $1 ~ /SchemaNameHere\>/ { for (i=1;i<=NF;i++) gsub (/(^ *)|(\W*$)/,"",$i); print "SELECT '\''" $1 "." $2 "'\'', COUNT(*) FROM " $1 "." $2 ";" }' | vsql -t -w "PasswordHere" | awk '/SchemaNameHere\>/ {print $1 "|" $3}'
@NeilRobbins
NeilRobbins / AntiForgerySessionDataProvider.cs
Created December 13, 2013 15:18
CSRF session linked protection with ASP.NET MVC
using System;
using System.Web;
using System.Web.Helpers;
namespace CSRF.Infrastructure
{
public class AntiForgerySessionDataProvider : IAntiForgeryAdditionalDataProvider
{
private readonly Func<string, string> _sessionKeyValuePair = sessionId => string.Format("Session: {0}", sessionId);
public string GetAdditionalData(HttpContextBase context)
@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
@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 / 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
(defn foo
[arg]
(cond
(string? arg)
(println "a string")
(and (number? arg)
(pos? arg))
(println "pos arg yo!")
(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)))
(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
@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]})