Skip to content

Instantly share code, notes, and snippets.

@carymrobbins
carymrobbins / JSRoutes.hs
Created December 21, 2014 08:46
Generate JavaScript routes for Yesod.
{-
To use this module, import it in Foundation and make your App an instance of JSRoutable -
instance JSRoutable App where
jsRoutes = jsRoutesBuilder resourcesApp
You will want to add the following line to your routes file -
/jsRoutes JSRoutesR GET
import Control.Monad.Reader
import System.IO
import System.Process
data NodeJS = NodeJS
{ nodeIn :: Handle
, nodeOut :: Handle
, nodeErr :: Handle
, nodePid :: ProcessHandle
}
@carymrobbins
carymrobbins / GenerateFormFromLastPost.hs
Last active August 29, 2015 14:12
Yesod - Generate a form from post data stored in the session
-- Most of these pragmas probably aren't needed, just ripped from Yesod.Form.Functions
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE CPP #-}
import ClassyPrelude.Yesod
import Control.Monad.Trans.RWS (evalRWST)
@carymrobbins
carymrobbins / BadQQCPP.hs
Last active August 29, 2015 14:12
Example of CPP and QuasiQuotes causing GHC to report the wrong line numbers for type errors (see https://ghc.haskell.org/trac/ghc/ticket/4150)
{-# LANGUAGE QuasiQuotes #-}
module BadQQCPP where
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import Language.Haskell.TH.Quote
quoter :: QuasiQuoter
quoter = QuasiQuoter { quoteExp = lift }
@carymrobbins
carymrobbins / postgres-9.4.sh
Last active July 19, 2016 11:49
Installing PostgreSQL 9.4 on Ubuntu 12.04
sudo apt-get update
sudo apt-get purge postgresql-9.1 postgresql-9.2 postgresql-9.3
# If you don't need postgis, you can probably get away with postgresql-contrib instead.
sudo apt-get install postgresql-client-common postgresql-9.4 postgresql-9.4-postgis-2.1
@carymrobbins
carymrobbins / setup-postgresql-vagrant.md
Last active May 4, 2023 10:22
Configure PostgreSQL in a Vagrant guest to allow connections from the host.

Configure Postgres

  • Update pg_hba.conf (most likely in /etc/postgresql/9.4/main) with -
    • host all all 0.0.0.0/0 trust
  • Update postgresql.conf to use listen_addresses = '*'
  • Be sure to sudo service postgresql restart

Configure Vagrant

@carymrobbins
carymrobbins / intellij-config.md
Last active October 16, 2015 23:43
Reasonable default configurations for IntelliJ

Preferences

  • Editor > General > Other
    • Strip trailing spaces on Save: Modified Lines
    • Ensure line feed at file end on Save
  • Editor > General > Smart Keys
    • Backspace smart indent (disable)
  • Editor > General > Appearance
    • Show line numbers
  • Show whitespaces > Trailing
@carymrobbins
carymrobbins / sbt-debug
Last active July 25, 2017 18:11
IntelliJ SBT Debug script for remote debugging, particularly through Vagrant.
#!/bin/bash
set -ex
# Sets the port that IntelliJ attaches to
true ${LISTEN_PORT:=5005}
# Sets whether or not the process waits for the debugger to attach
true ${SUSPEND:=y}
JVM_DEBUG=-Xdebug
@carymrobbins
carymrobbins / ProxyTypes.scala
Last active August 29, 2015 14:14
Use multiple values of the same base type as implicits with different contexts by separating them at the type level.
object Main {
def main(args: Array[String]) = {
implicit val pg = PostgreSQLConnection(ConnectionImpl("pg"))
implicit val mysql = MySQLConnection(ConnectionImpl("mysql"))
println(queryPostgreSQL("foo")) // prints "selected foo from pg"
println(queryMySQL("bar")) // prints "selected bar from mysql"
}
def queryPostgreSQL(x: String)(implicit pg: PostgreSQLConnection): String = pg { implicit c =>
doQuery(x)

Keybase proof

I hereby claim:

  • I am carymrobbins on github.
  • I am carymrobbins (https://keybase.io/carymrobbins) on keybase.
  • I have a public key whose fingerprint is D33C 6335 6304 1A4D DF20 F353 39BA A0C5 3411 3BD8

To claim this, I am signing this object: