Skip to content

Instantly share code, notes, and snippets.

View dalegaspi's full-sized avatar
🎓
BU S2 2022

Dexter Legaspi dalegaspi

🎓
BU S2 2022
View GitHub Profile
@dalegaspi
dalegaspi / Stopwatch.scala
Last active May 7, 2018 01:45
A simple stopwatch implementation for wall-clock time measurement of a sync of async method in scala
import com.typesafe.scalalogging.StrictLogging
import monix.eval.Task
import monix.execution.Scheduler
import scala.concurrent.Future
object Stopwatch extends StrictLogging {
/**
* http://biercoff.com/easily-measuring-code-execution-time-in-scala/
@dalegaspi
dalegaspi / Gzip.scala
Last active May 4, 2018 13:13 — forked from owainlewis/Gzip.scala
Gzip Scala
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream}
import java.util.zip.{GZIPInputStream, GZIPOutputStream}
import scala.util.Try
/**
* aped from https://gist.github.com/owainlewis/1e7d1e68a6818ee4d50e (gzip compression)
* and from https://stackoverflow.com/a/39371571/918858 (ser/deser from Array[Byte])
*/
object Gzip {
@dalegaspi
dalegaspi / brew_symlink_error_sierra.md
Last active January 4, 2024 22:32
Homebrew Symlink errors in Mac OSX High Sierra
@dalegaspi
dalegaspi / JsonSlf4jReporter.scala
Last active October 25, 2017 00:20
A new scala class for recording DropWizard Metrics artifacts as JSON with SLF4J Reporter
package com.tormund
import java.util
import java.util.concurrent.TimeUnit
import com.codahale.metrics._
import com.typesafe.scalalogging.StrictLogging
import org.json4s.DefaultFormats
/**
@dalegaspi
dalegaspi / Dependencies.scala
Last active October 9, 2019 16:17
Using Postgesql with TypeSafe Slick 3.1.1
// for use with your build.sbt
object Dependencies {
// ... all your other dependencies
val typesafeSlick = "com.typesafe.slick" %% "slick" % "3.1.1"
val postgreSql = "org.postgresql" % "postgresql" % "9.4.1209"
val hikariCP = "com.typesafe.slick" %% "slick-hikaricp" % "3.1.0" // you need really need this or you get ClassNotFoundException
}
@dalegaspi
dalegaspi / unbuffer_uniq.sh
Created February 10, 2016 18:53
unbuffering uniq
tail -f reporting.log | grep --line-buffered "INFO S3RecordFetcher - 20160119/" | cut -c23-64 | stdbuf -oL uniq | ts
@dalegaspi
dalegaspi / enableJmxJerseyRest.java
Created October 5, 2015 15:00
Enable JMX programmatically for a Jersey REST application
ResourceConfig rc = new ResourceConfig().packages(...)
.register(...);
// this is to enable JMX...or any init parameters for that matter
rc.addProperties(ImmutableMap.of("jersey.config.server.monitoring.statistics.mbeans.enabled", "true"));
@dalegaspi
dalegaspi / java_rest_hp.md
Last active June 6, 2019 10:49
LPT: On Creating a High-Performance REST Service in Java
  • Use Java 8. Seriously, any other version is just backwards-thinking. Functional aspects of the new version is reason enough to use it.
  • Use Jersey REST Framework. I've tried every other framework out there (including the bloated, over-engineered Play Framework) and nothing comes close to its efficiency and features without being bloated.
  • Never use parallelStream()...at least in the current release of Java 8 as it has the most inane implementation of parallelism I have come across to date.
  • On that note, never spawn threads at all within a request. If your request is taking too long using a single thread, you're doing it wrong.
  • Use a profiler. Buy a YourKit license now.
  • Be mindful of your logging. For example, if you're using Log4J2 asynchronous loggers, don't use includeLocation=true.
  • If you need a simple in-memory, non-distributed caching, use Google Guava Caching libraries. For Pete's sake, don't roll your own using ConcurrentHashMap; life is too short for that.
  • Need pooling objects
@dalegaspi
dalegaspi / run.sh
Created September 27, 2015 00:55
Using OpenHFT's ChroniTail without using Maven
java -cp chronicle-logger-tools-1.1.1.jar:chronicle-logger-1.1.1.jar:chronicle-3.5.3.jar:lang-6.6.7.jar net.openhft.chronicle.logger.tools.ChroniTail -t -u /opt/tomcat/logs/chronicle/main
@dalegaspi
dalegaspi / udp_java.md
Created June 1, 2015 12:53
UDP Multicast on Java

Introduction

There is very little information on the internet on how to send broadcast UDP messages in Java, which is kind of surprising since UDP broadcast is the simplest way to do broadcast messages without having to write a lot of code and or put in a lot of moving pieces, so long as one is aware of the drawbacks. I found myself having to search for this information and even Oracle's own documentation on this is just mediocre at best. Fortunately, someone took the time to write down. This is just a mirror of that information on GitHub to make it easier to find for someone searching for the same information.

The Sender

  1. Import some needed classes
import sun.net.*;
import java.net.*;
  1. Declare the port we send to