Skip to content

Instantly share code, notes, and snippets.

@laughedelic
laughedelic / IteratorWithFinally.scala
Created September 14, 2017 03:26
Attach a `finally` block to an iterator
implicit class IteratorOps[X](val iterator: Iterator[X]) extends AnyVal {
/** Attaches a block that will be executed only when the iterator is _completely_ consumed
* @note The original iterator should be discarded after calling this method
*/
def withFinally(fin: => Unit): Iterator[X] = new Iterator[X] {
def next(): X = iterator.next()
def hasNext: Boolean = {
val has = iterator.hasNext
if (!has) fin
@laughedelic
laughedelic / serialization.sc
Created September 7, 2017 02:27
Shows how to serialize-deserialize an object in Scala to a String
import java.io._
import java.util.Base64
import java.nio.charset.StandardCharsets.UTF_8
def serialise(value: Any): String = {
val stream: ByteArrayOutputStream = new ByteArrayOutputStream()
val oos = new ObjectOutputStream(stream)
oos.writeObject(value)
oos.close
new String(
@laughedelic
laughedelic / merge.sh
Created July 11, 2017 07:57
A script for merging MG7 output tables using Metaphlan utility
#!/bin/bash
# project specific constants
name="m16s6mangel"
# should return sample prefix for a given index
function sample_prefix() {
echo "MAGEL${1}_S${1}"
}
# arguments
@laughedelic
laughedelic / BotAuthRedirect.yaml
Created February 25, 2017 14:59
AWS API Gateway OAuth redirect to a Telegram bot's deep link
---
swagger: "2.0"
info:
version: "2017-02-25T14:22:32Z"
title: "BotAuthRedirect"
schemes:
- "https"
paths:
/:
x-amazon-apigateway-any-method:

Keybase proof

I hereby claim:

  • I am laughedelic on github.
  • I am laughedelic (https://keybase.io/laughedelic) on keybase.
  • I have a public key whose fingerprint is 138C F048 DC2E CC17 FBF1 3DD2 90A9 4E49 D72F 180F

To claim this, I am signing this object:

scala> val conf = new org.apache.commons.configuration.BaseConfiguration()
conf: org.apache.commons.configuration.BaseConfiguration = org.apache.commons.configuration.BaseConfiguration@3ada9e37
scala> conf.setProperty("storage.directory", "/media/ephemeral0/applicator/16s/bio4j")
scala> conf.setProperty("storage.backend", "berkeleyje")
scala> val graph = new com.bio4j.titan.model.ncbiTaxonomy.TitanNCBITaxonomyGraph( new com.bio4j.titan.util.DefaultTitanGraph( com.thinkaurelius.titan.core.TitanFactory.open(conf) ) )
17:46:21.350 [main] DEBUG c.t.t.d.b.BerkeleyJEStoreManager - Opened database system_properties
java.lang.Throwable: null
@laughedelic
laughedelic / .ensime
Created August 18, 2015 10:59
Problem with atom-ensime server connection (https://github.com/ensime/ensime-atom/issues/53)
(
:root-dir "/Users/laughedelic/dev/ohnosequences/statika"
:cache-dir "/Users/laughedelic/dev/ohnosequences/statika/.ensime_cache"
:name "statika"
:java-home "/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home"
:java-flags ("-Xms1024m" "-Xmx1024m" "-XX:ReservedCodeCacheSize=128m" "-XX:MaxMetaspaceSize=256m")
:reference-source-roots ("/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/src.zip")
:scala-version "2.11.7"
:compiler-args ("-feature" "-language:higherKinds" "-language:implicitConversions" "-language:postfixOps" "-deprecation" "-unchecked" "-Xlint" "-Xplugin:/Users/laughedelic/.ivy2/cache/org.brianmckenna/wartremover_2.11/jars/wartremover_2.11-0.13.jar")
@laughedelic
laughedelic / Readme.md
Last active August 29, 2015 14:23
Typing unicode symbols in Atom (temporary solution)

Temporary solution for typing unicode symbols in Atom

Usage

  1. Install autocomplete-plus and autocomplete-snippets plugins
  2. Add these snippets to your snippets.cson
  3. Try typing u and the LaTeX name of the symbol you want and you should get autocompletetion with a preview of the symbol

Notes

@laughedelic
laughedelic / tabulaInANutshell.scala
Created September 5, 2014 15:49
This is kind of a minimal example of the tags failure. Works with the commented variation.
import ohnosequences.pointless._, AnyTaggedType._
trait AnyAct {
type Itm <: AnyTaggedType
val itm: Itm
// type Out[I <: Itm] = Tagged[I]
type Out = Tagged[Itm]
}
{
"schemas" : [
{
"label" : "enzymedb",
"properties" : [
{
"label" : "id",
"type" : "java.lang.String"
},
{