Skip to content

Instantly share code, notes, and snippets.

View DanThiffault's full-sized avatar

Dan Thiffault DanThiffault

View GitHub Profile
@DanThiffault
DanThiffault / spec_examples.clj
Created January 16, 2017 02:25
Clojure Spec examples
(ns spec-examples
(:require
[clojure.spec :as s]
[clojure.spec.gen :as gen]
[clojure.future :refer :all]))
;; Define a map called user-info of { :region-id :region :template-id :template }
;; and ensure that the generated regions contain the passed in region-id (same for templates)
(s/def ::region-id (s/and nat-int? #(> % 1000)))
@DanThiffault
DanThiffault / vbox_guest_upgrade.sh
Created July 19, 2016 14:27
Virtual Box Guest Additions Upgrade
# First make sure you have a consistent linux kernel & source installed
sudo apt-get install linux-image-3.13.0-92-generic linux-headers-3.13.0-92-generic
sudo reboot
# Check its what you expect
uname -a # should be 3.13.0-92-generic, if not you need to try a newer version/fix this.
# Based on https://gist.github.com/fernandoaleman/5083680
# & https://gist.github.com/zbal/7800423
@DanThiffault
DanThiffault / Readme.md
Created February 16, 2016 22:37
Rails nested transactions

See Nested Transactions for more information.

TL;DR if you're going to use nested transactions you probably should not raise ActiveRecord::Rollback

@DanThiffault
DanThiffault / bulk_insert.rb
Created February 8, 2016 22:28
Bulk Arel inserts
bookMergeBlocks = BookMergeBlock.arel_table
im = Arel::InsertManager.new Arel::Table.engine
im.into bookMergeBlocks
im.select @raw_books.select(book.id,:book_id).uniq.arel
im.columns << bookMergeBlocks[:master_book_id]
im.columns << bookMergeBlocks[:duplicate_book_id]
@DanThiffault
DanThiffault / Vagrantfile
Created January 23, 2016 21:07
Elixir Phoenix Dev Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrant file for elixir & phoenix dev
Vagrant.configure(2) do |config|
config.vm.box = "debian/jessie64"
config.vm.provider :virtualbox do |vb|
vb.name = "elixirdev"
end

Keybase proof

I hereby claim:

  • I am DanThiffault on github.
  • I am danthiffault (https://keybase.io/danthiffault) on keybase.
  • I have a public key whose fingerprint is 6387 145A 834E 08F6 2B3A 5F60 A2D4 1BB3 EA59 31D4

To claim this, I am signing this object:

@DanThiffault
DanThiffault / services.js
Last active January 25, 2017 17:34
Angular $http service with automatic retries and status code based error messages
(function (app) {
// Fluent interface to generate a map of status codes to error messages
function genErrorMap() {
var statusErrorMap = { "default": { msg: "An error has occurred", retryable: false } };
var methods = {
// Add a mapping from an array of status codes to an errorMessage and whether we should retry
// the request when recieving this error status code
add: function (statusCodes, errorMessage, retryable) {
for (var i = 0; i < statusCodes.length; i++) {
@DanThiffault
DanThiffault / ws.fsx
Last active December 12, 2022 04:52
Simple F# Web Server
open System
open System.Net
open System.Text
open System.IO
// Modified from http://sergeytihon.wordpress.com/2013/05/18/three-easy-ways-to-create-simple-web-server-with-f/
// download this file to your root directory and name as ws.fsx
// run with `fsi --load:ws.fsx`
// visit http://localhost:8080
::-webkit-inner-spin-button { display: none; }
::-webkit-datetime-edit {}
.datePicker {
position: relative;
margin-bottom: 15px;
}
.ul.calendar-header {
display: none;
@DanThiffault
DanThiffault / tad.sh
Created January 15, 2013 19:02
Tmux attach/create session from current directory
#!/bin/sh
# tmux attach directory
# inspired by https://github.com/croaky/dotfiles/commit/df3dd5129bfa941ac0bdf2885da92f822042ee5b
SESSION=$(basename $PWD)
# credit from http://stackoverflow.com/questions/3432536/create-session-if-none-exists
function hassession {
tmux has-session -t $SESSION 2>/dev/null
}