Skip to content

Instantly share code, notes, and snippets.

View solidsnack's full-sized avatar

Jason Dusek solidsnack

  • Dallas, TX
  • 08:21 (UTC)
View GitHub Profile
@solidsnack
solidsnack / syslogged
Created July 26, 2013 18:08
Wrapper for logging any command's STDOUT and STDERR to syslog.
#!/bin/bash
set -o errexit -o nounset -o pipefail
function -h {
cat <<EOF
USAGE: syslogged <program> <args>
Wraps a command invocation with logging, sending STDOUT and STDERR to
syslog, setting the syslog tag to:
<program>[<pid>]
@solidsnack
solidsnack / cio.scala
Last active December 20, 2015 07:49
Demo of concurrent, side-effecting operations in Scala with a configurable thread pool.
import scala.concurrent._
import scala.concurrent.duration._
import java.util.concurrent.Executors.newFixedThreadPool
val logger = java.util.logging.Logger.getLogger("par")
def f(n: Int): Int = {
Thread.sleep(20000)
logger.info(f"$n%04d")
n*2
}
@solidsnack
solidsnack / ips.bash
Created August 1, 2013 04:39
Find IPs, on OS X and Linux
function ips {
/sbin/ifconfig | tr '\t' ' ' | # OS X gives us tabs, remove them
sed -n '/^ *inet / { s/// ; p ;}' | # Only IPv4, thanks
cut -d' ' -f1 | # Throw away everything but the addr
sed s/addr:// | # Strip addr: prefix on Linux
fgrep -v 127.0.0.1 # We already know about this one
}
@solidsnack
solidsnack / tarmap.scala
Created August 8, 2013 23:41
Tar as the JSON of UNIX
import org.kamranzafar.jtar._
import java.io.{ByteArrayInputStream, ByteArrayOutputStream}
import scala.collection.mutable.ArrayBuffer
import com.google.common.base.Charsets
object Tar {
def toTar(entries: Map[String,String]): Array[Byte] = {
val bytesOut = new ByteArrayOutputStream()
val archive = new TarOutputStream(bytesOut)
val mTime: Long = System.currentTimeMillis() / 1000

Haskell example:

powerset :: (Eq t) => [t] -> [[t]]
powerset [   ] = []
powerset [ h ] = [ [h] ]
powerset (h:t) = map (h:) sub ++ sub
 where sub = powerset t
@solidsnack
solidsnack / isset.bash
Created November 20, 2013 08:42
Demo of ${_+} predicate in Bash.
bash -c '[[ ${1+isset} ]] ; echo "#? $?" ; echo "#1 $1"' bash
#? 1
#1
bash -c '[[ ${1+isset} ]] ; echo "#? $?" ; echo "#1 $1"' bash x
#? 0
#1 x
#!/bin/bash
set -o errexit -o nounset -o pipefail
function -h {
cat <<USAGE
USAGE: ln_libjvm.bash
Symlink a likely libjvm.so into /usr/bin.
USAGE
}; function --help { -h ;}
while :; do sleep 1; done <IN >OUT
sed s/^/::/ >IN <OUT
cat IN
echo x > OUT
@solidsnack
solidsnack / scan_path.bash
Created December 1, 2013 23:04
Not useful today...but seems like it will come in handy.
function check_path_for_usr_local_bin {
printf %s "$PATH" | while read -d: -r line
do printf '%s\n' "$line"
done | fgrep -qx /usr/local/bin
}
@solidsnack
solidsnack / mesos-attrs-causes-slave-upgrade
Created December 17, 2013 19:34
Can be fixed with: /usr/local/sbin/mesos-slave --recover=cleanup
I1217 19:23:11.844920 2201 state.cpp:33] Recovering state from '/tmp/mesos/meta'
Incompatible slave info detected.
------------------------------------------------------------
Old slave info:
hostname: "ip-10-46-210-228.ec2.internal"
webui_hostname: "ip-10-46-210-228.ec2.internal"
resources {
name: "cpus"
type: SCALAR
scalar {