Skip to content

Instantly share code, notes, and snippets.

@wfaler
wfaler / generic-jdbc.scala
Created November 15, 2015 13:34
Generic deriving of a type-class that sets column values with JDBC, can derive for any arbitrary case-class (if you add a few more basic types)
import shapeless._
import java.sql.PreparedStatement
trait ToRow[A]{
def toRow(a: A, statement: PreparedStatement): (Int) => Unit
}
implicit val stringToRow: ToRow[String] = new ToRow[String]{
def toRow(s: String, statement: PreparedStatement) = statement.setString(_,s)
}
@wfaler
wfaler / nested-reader.hs
Created September 23, 2015 14:04
Reader nested with IO and other [somemonad]T's
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Maybe
import Control.Monad.IO.Class
import Control.Monad.Trans
--import Control.Monad.State
m :: IO ()
m = do
runReaderT r2 5
@wfaler
wfaler / bind-consul.sh
Created September 9, 2015 19:01
use consul as DNS for local services, fronted by Bind for the rest
sudo apt-get install bind9 bind9utils bind9-doc
wget https://dl.bintray.com/mitchellh/consul/0.5.2_linux_amd64.zip
/etc/bind/named.conf.options:
options {
directory "/var/cache/bind";
recursion yes;
allow-query { localhost; };
forwarders {
@wfaler
wfaler / init.el
Last active August 29, 2015 14:27
OSX init.el
(require 'package)
(setq package-list '(markdown-mode
yaml-mode
js2-mode
jsx-mode
find-file-in-project
auto-complete
nix-mode
dockerfile-mode
scala-mode2
@wfaler
wfaler / gist:6f53d4b6f21dbe97f8f9
Created August 15, 2015 09:34
raspberry-pi printer server
sudo apt-get install cups
sudo apt-get install hplip-gui
sudo usermod -a -G lpadmin pi
sudo emacs /etc/cups/cupsd.conf
# change:
#Listen section to:
Listen 632
#Add to all top level Location sections until Policy turns up in the file:
Allow @local
@wfaler
wfaler / vpnrouter.sh
Last active August 29, 2015 14:27
raspberry pi as VPN router
# Assumes eth0 is WAN and eth1 is the port you want to act as a router for other devices.
sudo apt-get install openvpn
sudo apt-get install dnsmasq
/etc/network/interfaces - add:
#USB NIC serving as internal gateway
iface eth1 inet static
address 192.168.10.1
netmask 255.255.255.0
@wfaler
wfaler / Router.js
Created August 3, 2015 23:04
A Javascript router in 83 LOCS (including white space).
var Router = function(routeDef){
this.routes = [];
routeDef.call(this);
};
Router.prototype.splitPath = function(path){
var splits = path.split('/');
return _.filter(splits, function(part){
return part !== '';
(require 'package)
(setq package-list '(markdown-mode
yaml-mode
js2-mode
jsx-mode
find-file-in-project
auto-complete
ghc
nix-mode
dockerfile-mode
@wfaler
wfaler / haskell-shell.nix
Last active August 29, 2015 14:23
Haskell shell.nix instructions
cabal2nix --sha256=0 cabal-file.cabal > shell.nix
#add the following to the top line
haskellPackages ? (import <nixpkgs> {}).haskellPackages,
# remove sha line, add src location
src = ./src;
# add required build-tools to mkDerivation section, happy, alex & ghc-mod used for emacs
buildTools = [ haskellPackages.cabal-install haskellPackages.happy haskellPackages.alex haskellPackages.hlint]; # haskellPackages.ghc-mod - ghc-mod broken right now
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var webrtc = new SimpleWebRTC({
// the id/element dom element that will hold "our" video
localVideoEl: 'localVideo',