Skip to content

Instantly share code, notes, and snippets.

View solidsnack's full-sized avatar

Jason Dusek solidsnack

  • Dallas, TX
  • 18:02 (UTC)
View GitHub Profile
@solidsnack
solidsnack / gist:4636841
Last active December 11, 2015 17:48 — forked from kowey/gist:4633875
One can use read and redirection if the files are line delimited. Preferring while/read to expansion makes for more robust scripts.
#!/bin/bash
set -o errexit -o pipefail -o nounset
cat_bundle () {
local file="$1"
echo ""
echo ""
echo "; ----------------------------------------------------------------------"
echo "; $(basename $file)"
echo "; ----------------------------------------------------------------------"
@solidsnack
solidsnack / chan.hs
Last active December 11, 2015 18:48 — forked from scan/chan.hs
Use of `maybe` combinator.
import Control.Applicative
import Control.Concurrent.Chan (Chan, newChan)
import qualified Data.Map as M
import Control.Concurrent.STM (atomically, TVar, readTVar, writeTVar)
import Control.Monad.Trans
type Id = Integer
getOrCreateChannel :: (MonadIO m) => Id -> TVar (M.Map Id (Chan a)) -> m (Chan a)
getOrCreateChannel cid t = liftIO $ do
@solidsnack
solidsnack / pg_do_over.bash
Last active December 11, 2015 20:28
Clear data/users from Postgres moderately safely.
# Connects to the server and removes all non-default DBs and users.
function clear_server {
lockdown_server
local dbs=( $( as_postgres psql -Atc \
"SELECT datname FROM pg_catalog.pg_database
WHERE NOT datname
IN ('postgres','template0','template1')" ) )
local users=( $( as_postgres psql -Atc \
"SELECT rolname FROM pg_catalog.pg_roles
WHERE rolname != 'postgres';" ) )
@solidsnack
solidsnack / gist:4737692
Created February 8, 2013 09:33
Refresh OS X wifi
PATH=/usr/sbin
45 * * * * networksetup -setairportpower en0 off && networksetup -setairportpower en0 on
@solidsnack
solidsnack / gist:4744661
Created February 9, 2013 09:10
In Bash, we can name functions some odd things...
:; function http://a.b.c/%20?x=4 { echo x ;}
:; http://a.b.c/%20?x=4
x
@solidsnack
solidsnack / scalatra.scala
Last active December 15, 2015 22:19
Suggestions from scala-user
import org.scalatra._
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.webapp.WebAppContext
object Go {
def main(args: Array[String]) {
val server = new Server(8080)
val context = new WebAppContext()
context.setContextPath("/")
context.addServlet(classOf[Slash], "/*")
@solidsnack
solidsnack / memusg
Last active December 17, 2015 12:39 — forked from netj/memusg
Clean up variable declarations.
#!/bin/bash
set -o errexit -o nounset -o pipefail
function -h {
cat <<USAGE
USAGE: memusg COMMAND [ARGS]
Measure memory usage of processes.
This script is inspired by a script of the same name written by Jaeho Shin
<[email protected]>.
@solidsnack
solidsnack / mesos.rb
Last active December 19, 2015 13:29
require 'formula'
class Mesos < Formula
homepage 'http://incubator.apache.org/mesos/'
head 'https://git-wip-us.apache.org/repos/asf/mesos.git'
depends_on 'autoconf' => :build
depends_on 'automake' => :build
depends_on 'libtool' => :build
depends_on 'zookeeper'
class MOTD {
@JsonProperty
@Length(min=8, max=128, message = "The message mustn't be too short or long.")
var message : String = "Hello World"
}
@Path("motd")
class Endpoint {
@GET @Timed @Produces(Array(MediaType.TEXT_PLAIN))
def get = Main.get
@solidsnack
solidsnack / der-zauberlehrling
Created July 23, 2013 21:55
Die Geister, die ich rief...
Hat der alte Hexenmeister The old wizard has
Sich doch einmal wegbegeben! made away with himself for once!
Und nun sollen seine Geister And now shall his spirits
Auch nach meinem Willen leben. live according to my will!
Seine Wort und Werke His words and motions
Merkt ich und den Brauch, I have marked, and the usage,
Und mit Geistesstärke and with supernatural power
Tu ich Wunder auch. I can perform wonders.
Walle! walle March, march