Skip to content

Instantly share code, notes, and snippets.

@rahulsom
rahulsom / demo.adoc
Created January 29, 2018 05:08
Asciidoctor source with attributes subs bug demo

Demo

This works, but is not ideal

build.gradle.kts
buildscript {
    dependencies {
@rahulsom
rahulsom / restart-audio-daemon.sh
Created December 10, 2016 19:09
Restart Audio Daemon
# All this comes from https://twitter.com/viktorklang/status/807629003385237504
function restart_audio() {
command sudo killall coreaudiod && \
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.audio.coreaudiod.plist && \
sudo launchctl load /System/Library/LaunchDaemons/com.apple.audio.coreaudiod.plist || \
return
echo 'Audio daemon restarted'
}
@rahulsom
rahulsom / Ele.groovy
Last active November 29, 2016 13:58
Mahout with Groovy - the faster way
@Grab(group = 'org.apache.mahout', module = 'mahout-core', version = '0.9')
import org.apache.mahout.cf.taste.impl.common.FastByIDMap
import org.apache.mahout.cf.taste.impl.common.FastIDSet
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel
import org.apache.mahout.cf.taste.impl.recommender.GenericItemBasedRecommender
import org.apache.mahout.cf.taste.impl.similarity.TanimotoCoefficientSimilarity
def mlDir = '/Users/rahulsomasunderam/Downloads/ml-100k'
def f = new File("$mlDir/u.data")
@rahulsom
rahulsom / Foo.groovy
Created July 19, 2012 16:31
Reloading Scripts in groovy, Erlang style
public class ReloadingScript {
/**
* The Class of the script
*/
Class clazz
/**
* Runs the script in a Erlang-ish loop
*
/*
This is my solution to https://www.youtube.com/watch?v=LYKn0yUTIU4
Languages are hard. General assumptions:
1. What qualifies as a letter is hard to explain in some languages like most indic languages.
My definition of what comprises a letter is what takes up on character in UTF encoding.
2. Same applies to chinese. In Chinese there's symbols for the every letter that are unicode symbols.
That makes chinese almost similar to the decimal number system.
Q1. What's the smallest number to form an english sequence of 7?
7: [323 (three hundred twenty-three), 23 (twenty-three), 11 (eleven), 6 (six), 3 (three), 5 (five), 4 (four)]
@rahulsom
rahulsom / nettest.sh
Created June 25, 2012 02:55
MacbookPro5,1 has a serious problem with it's wireless. Apple will not acknowledge it, but here's a fix
#!/bin/sh
#
# Tests network status and resets Airport if required
#
usage() {
cat << EOF
Usage: $0 options
-h HOST host to ping
-s <ON|OFF> say out loud: on or off default: OFF
@rahulsom
rahulsom / ssh-tunnel.sh
Last active February 28, 2016 13:33
SSH Tunneling
#!/bin/bash
#
# SSH Tunnel Manager
#
# SSH Flags:
# f - Force to background.
# N - Execute no commands. Don't open shell.
# q - Run quietly.
# T - Don't allocate pseudo TTY.
# R - Reverse Proxy.
@rahulsom
rahulsom / sendhl7.groovy
Created February 22, 2016 22:39
Send HL7 Message from file to host:port
@Grab('ca.uhn.hapi:hapi-base:2.1')
@Grab('ca.uhn.hapi:hapi-structures-v26:2.1')
import ca.uhn.hl7v2.DefaultHapiContext
import ca.uhn.hl7v2.HapiContext
import ca.uhn.hl7v2.app.ConnectionData
import ca.uhn.hl7v2.llp.LowerLayerProtocol
import ca.uhn.hl7v2.llp.MinLowerLayerProtocol
import ca.uhn.hl7v2.validation.builder.support.NoValidationBuilder
def cli = new CliBuilder()
@rahulsom
rahulsom / AnonCcd.groovy
Created November 25, 2013 23:55
CDA Anonymizer
import groovy.xml.XmlUtil
import java.security.SecureRandom
import java.text.SimpleDateFormat
void anonymize(Reader reader, Writer writer) {
def xml = new XmlParser().parse(reader)
xml.recordTarget.patientRole.with { patientRole ->
patientRole.id.each {
@rahulsom
rahulsom / output.txt
Created November 14, 2013 06:53
Hapi & LigthHl7Lib Performance Benchmarks
Hapi: 2.604747 ms per cycle
LightHl7Lib: 0.00451332 ms per cycle