Instantly share code, notes, and snippets.

View FutureTranslation.scala
package object effect {
import cats.effect.IO
import scala.concurrent.Future
import language.implicitConversions
import language.higherKinds
import scala.util.{Success, Failure}
import scala.concurrent.Promise
import cats.effect.Effect
View circe-subtyping.scala
// ========== approach 1 ==========
sealed abstract class FooBase {
def subType: String = this.getClass.getSimpleName
}
case class Foo(a: Int, b: String) extends FooBase
case class Bar(c: Float, d: Int) extends FooBase
val fooName = getClassName(Foo.getClass)
val barName = getClassName(Bar.getClass)
View tf-keras-model.py
import numpy as np
import tensorflow as tf
from tensorflow import keras
from keras.models import Sequential
import h5py
from keras.utils.io_utils import HDF5Matrix
data_dir = '...'
train_fn = data_dir + '/dataset_train.h5'
test_fn = data_dir + '/dataset_test.h5'
View ArtemisClient.scala
package com.practicingtechie
import org.apache.activemq.artemis.api.core.TransportConfiguration
import org.apache.activemq.artemis.api.core.SimpleString
import org.apache.activemq.artemis.api.core.client.{ActiveMQClient, ClientMessage, MessageHandler}
import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants._
import scala.collection.JavaConversions._
// produce & consume messages using Apache Artemis v2.2.0 core API
object ArtemisClient {
View d3v4-labeled-force-layout.html
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.link {
stroke: #aaa;
}
.node {
pointer-events: all;
View Extending LVM based filesystem
# initialize physical device to be used as a physical volume with LVM
# (below we assume the newly added block device was "/dev/sdb")
pvcreate /dev/sdb
# add physical volume to volume group
vgextend ubuntu-vg /dev/sdb
# extend logical volume and file system
lvextend -r /dev/ubuntu-vg/root /dev/sdb
View issue_certificate.sh
#!/bin/bash
#
# requires CA.pl from OpenSSL: https://github.com/openssl/openssl/blob/master/apps/CA.pl.in
#
# generating CA.pl from OpenSSL source:
# /usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \
# "-oMakefile" apps/CA.pl.in > "apps/CA.pl"
# sudo cp apps/CA.pl /usr/local/bin
#
View build.sbt
organization := "fi.markoa"
name := "sbt-demo"
version := "0.0.1"
scalaVersion := "2.11.7"
libraryDependencies += "org.foo" % "bar" % "10"
View ResourceCataloguer.java
package fi.markoa.proto.libload;
import java.io.File;
import java.io.IOException;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
View vw-stress-daemon.py
#!/usr/bin/env python
import sys
import socket
sock = socket.socket()
sock.connect(("127.0.0.1", 26542))
ss = sock.makefile()
for i in range(1, 5000000):