Skip to content

Instantly share code, notes, and snippets.

@mmullis
mmullis / gist:1f4012b30d09bdaebd4ccfa30aa6ec64
Created July 26, 2018 16:11
Scala Oneliner to mock interview question: does list of numbers have a pair with sum equal to a target value
scala> val target = 8; val l = List(1,2,3,4,4) ; (for(x <- l; y <- l) yield { x + y }).exists(_==target)
target: Int = 8
l: List[Int] = List(1, 2, 3, 4, 4)
res24: Boolean = true
@mmullis
mmullis / fix-softlinks-for-go-oci8.sh
Last active September 29, 2017 16:18
Softlinks needed to fix missing -lclntsh to go get go-oci8
@mmullis
mmullis / sbt_run_main_script_with_correct_config.sh
Created September 7, 2017 17:04
sbt run-main using correct options by disabling fork in run
#!/bin/bash
export APP_ENV=xyztest
export SBT_OPTS=" -Dpidfile.path=/dev/null -Dconfig.file=conf/$APP_ENV.conf -Dlogger.resource=logback-${APP_ENV}.xml -Dlogback.configurationFile=conf/logback-${APP_ENV}.xml $SBT_OPTS"
sbt "; set fork in run := false ; run-main script.MyFooScript"
@mmullis
mmullis / ExceptionMessageBuilder.scala
Last active August 17, 2017 19:27
scala: build exception message with all causes
// Something simple to build a useful exception message and avoid NPE from getCause.getMessage
object ExceptionMessageBuilder {
def mkExceptionMessage(e: Throwable): String = {
e.getCause match {
case null => e.getMessage
case t: Throwable => s"${e.getMessage} cause:${mkExceptionMessage(t)}"
}
}
\n
Request Details:\n
url: %{url_effective}\n
num_redirects: %{num_redirects}\n
content_type: %{content_type}\n
response_code: %{response_code}\n
remote_ip: %{remote_ip}\n
\n
Timing Analysis:\n
time_namelookup: %{time_namelookup}\n
@mmullis
mmullis / drun_netdata.sh
Created July 3, 2017 14:59
drun_netdata.sh
docker run -d --net=host --cap-add SYS_PTRACE \
-v /proc:/host/proc:ro \
-v /sys:/host/sys:ro \
-p 19999:19999 titpetric/netdata
@mmullis
mmullis / Ruby GDB tricks
Created August 12, 2013 14:04
Debugging and Dumping the state of a running Ruby process using GDB.
# Connect to ruby process
gdb `which ruby` <pid>
# Run GC
p rb_eval_string("GC.start")
# Count each Object class
p rb_eval_string("$gdb_objs = Hash.new 0")
p rb_eval_string("ObjectSpace.each_object {|o| $gdb_objs[o.class] += 1}")
p rb_eval_string("$stderr.puts($gdb_objs.inspect)")