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 / del_solr_write_lock.sh
Created January 5, 2015 19:59
delete write.lock files in Solr to prevent "unavailable" status due to write.lock acquire timeouts
sudo find . -type f -name "write.lock" -exec rm -f {} \;
@dalegaspi
dalegaspi / install_ejdb_osx.sh
Created April 18, 2015 15:35
Installing SoftMotion's EJDB (Embedded JSON DB) on OS X Yosemite
# use withe sudo when applicable
# install cmake via MacPorts
port install cmake
# install as per INSTALL
git clone https://github.com/Softmotions/ejdb.git
cd ejdb
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ../
@dalegaspi
dalegaspi / Readme.txt
Created May 19, 2015 20:48
Jersey 2.x Using Embedded Jetty with Swagger, CORS, and a ServletContextListener
the .java file is for initializing using embedded Jetty...the web.xml is for deploying the Jersey service as a WAR file.
@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
@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 / 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 / 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 / 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 / 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 / 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
/**