Skip to content

Instantly share code, notes, and snippets.

@mping
mping / .zshrc
Created April 5, 2018 12:55
zsh
alias pserv='python -m SimpleHTTPServer $*'
alias wget='wget --trust-server-names --no-check-certificate'
alias ls='LC_COLLATE=C ls -lFha -G' #--group-directories-first --color '
alias grep='grep --color=always'
alias less='less -R'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
@mping
mping / FutureWUT.java
Last active March 27, 2018 15:35
CompletableFuture gotcha
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class FutureWUT {
static void sleep(long millis) {
try {
Thread.sleep(millis);
@mping
mping / core.clj
Created January 29, 2018 10:58
quasar producer
(ns clj-quasar.core
(:require
[co.paralleluniverse.pulsar
[core :refer :all]
[actors :refer :all]]))
(defsfn adder []
(receive [from v]
(do
(+ v 1))))

Quick Tips for Fast Code on the JVM

I was talking to a coworker recently about general techniques that almost always form the core of any effort to write very fast, down-to-the-metal hot path code on the JVM, and they pointed out that there really isn't a particularly good place to go for this information. It occurred to me that, really, I had more or less picked up all of it by word of mouth and experience, and there just aren't any good reference sources on the topic. So… here's my word of mouth.

This is by no means a comprehensive gist. It's also important to understand that the techniques that I outline in here are not 100% absolute either. Performance on the JVM is an incredibly complicated subject, and while there are rules that almost always hold true, the "almost" remains very salient. Also, for many or even most applications, there will be other techniques that I'm not mentioning which will have a greater impact. JMH, Java Flight Recorder, and a good profiler are your very best friend! Mea

@mping
mping / multiline.sh
Last active October 9, 2017 13:07
Multiline processing with bash
#!/bin/bash
## run nc with
# while true ; do echo -e "HTTP/1.1 200 OK\n\n $(date)" | nc -l 1500; done
#curl -XPOST -H "Partner-Id:230" --data "@-" http://localhost:1500
while read email; do
curl -X POST -d "$email" http://localhost:1500;
done << EOF
@mping
mping / Main.scala
Created July 3, 2017 09:46 — forked from sujoyu/Main.scala
Scala parser combinator sample like HTML tag.
import scala.util.parsing.combinator._
import scala.language.postfixOps
object Main {
def main(args:Array[String]) = {
val sc = new java.util.Scanner(System.in)
val input = collection.mutable.ListBuffer[String]()
while(sc.hasNextLine) {
input += sc.nextLine
@mping
mping / build.boot
Created May 27, 2017 11:57 — forked from bartojs/build.boot
gmail rest api java/clojure example with oauth2 and labels
;; 1) first goto https://console.developers.google.com/start/api?id=gmail
;; -- to turn on gmail api for your account
;; 2) then create a oauth consent with app name
;; 3) then add oauth clientid and download to ./clientsecret.json
;; 4) boot run
;; -- when running first time a browser will open to accept authorizaton
(set-env! :dependencies '[[com.google.apis/google-api-services-gmail "v1-rev34-1.21.0"]
[com.google.api-client/google-api-client "1.20.0"]
[com.google.oauth-client/google-oauth-client-jetty "1.20.0"]])
@mping
mping / hosts.sh
Created April 17, 2017 14:03
hosts.sh
#!/bin/bash
echo "172.217.7.228 www.miguelping.com" >> /etc/hosts
@mping
mping / cgd.js
Last active February 9, 2017 12:47
Nightmarejs to fetch ebank data
var electron = require("electron")
var Nightmare = require("nightmare")
require('nightmare-inline-download')(Nightmare)
//$ node xxx.js USER PW
// ^ in some shells, that space prevents the cmd to be saved in shell history
@mping
mping / .tmux.conf
Created January 11, 2017 17:27
tmux
set -g default-terminal "screen-256color"
# use C-q for tmux
unbind-key C-b
set -g prefix 'C-q'
# ctrl+arrow up/down in emacs for history
set-window-option -g xterm-keys on
# Allows for faster key repetition