Skip to content

Instantly share code, notes, and snippets.

View ernesto-alvarado's full-sized avatar

ernesto alvarado ernesto-alvarado

View GitHub Profile
@rednaxelafx
rednaxelafx / PrintThreadIds.java
Created February 25, 2011 10:31
find out the correspondence between the tid/nid of Java threads as shown from jstack/JMX, on HotSpot/Linux
package fx.jvm.hotspot.tools;
import java.util.List;
import sun.jvm.hotspot.tools.Tool;
public class PrintThreadIds extends Tool {
public static void main(String[] args) {
PrintThreadIds tool = new PrintThreadIds();
tool.start(args);
@also
also / utf-16.js
Created April 10, 2011 22:17
Decode JavaScript UTF-16 arrays
// http://www.ietf.org/rfc/rfc2781.txt
function decodeUtf16(w) {
var i = 0;
var len = w.length;
var w1, w2;
var charCodes = [];
while (i < len) {
var w1 = w[i++];
if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
charCodes.push(w1);
@jonhurlock
jonhurlock / pleaseEscape.py
Created June 20, 2012 15:07
Example Python Code showing cURLing data and POSTing data to Elastic Search, but fails with escaped speech marks
############# My Clusters Health
curl -XGET 'http://127.0.0.1:9200/_cluster/health?pretty=true'
{
"cluster_name" : "TweetHadoop",
"status" : "yellow",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 15,
@vorburger
vorburger / gist:3429822
Created August 22, 2012 22:03
How to find an available (free) TCP port in Java
/**
* Returns a free port number on localhost.
*
* Heavily inspired from org.eclipse.jdt.launching.SocketUtil (to avoid a dependency to JDT just because of this).
* Slightly improved with close() missing in JDT. And throws exception instead of returning -1.
*
* @return a free port number on localhost
* @throws IllegalStateException if unable to find a free port
*/
private static int findFreePort() {
@Yaffle
Yaffle / TextEncoderTextDecoder.js
Last active February 21, 2024 18:27
TextEncoder/TextDecoder polyfills for utf-8
// TextEncoder/TextDecoder polyfills for utf-8 - an implementation of TextEncoder/TextDecoder APIs
// Written in 2013 by Viktor Mukhachev <vic99999@yandex.ru>
// To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
// You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
// Some important notes about the polyfill below:
// Native TextEncoder/TextDecoder implementation is overwritten
// String.prototype.codePointAt polyfill not included, as well as String.fromCodePoint
// TextEncoder.prototype.encode returns a regular array instead of Uint8Array
// No options (fatal of the TextDecoder constructor and stream of the TextDecoder.prototype.decode method) are supported.
@airawat
airawat / 00-NLineInputFormat
Last active August 22, 2018 15:18
NLineInputFormat - About NLineInputFormat, uses, and a sample program
**********************
Gist
**********************
A common interview question for a Hadoop developer position is whether we can control the number of
mappers for a job. We can - there are a few ways of controlling the number of mappers, as needed.
Using NLineInputFormat is one way.
About NLineInputFormat
----------------------
@sideshowcoder
sideshowcoder / run_eunit.sh
Created February 23, 2014 12:48
Run Erlang EUnit from the shell
# replace ERLANG_MODULE with the module you try to test, i.e. calc
erlc -DTEST ERLANG_MODULE.erl && erl -noshell -pa . -eval "eunit:test(ERLANG_MODULE, [verbose])" -s init stop
@aslakknutsen
aslakknutsen / start_testing_java8_today.asciidoc
Last active May 10, 2024 20:15
Example of how to use both JDK 7 and JDK 8 in one build.

JDK 8 Released

Most of us won’t be able to use/deploy JDK 8 in production for a looong time. But that shouldn’t stop us from using it, right?

It should be possible to sneak in JDK 8 in the back way, the same way we snuck in Groovy and other libraries we wanted to use.

The Test Suite to the rescue

The Maven compiler plugin run in two separate lifecycles, compile and testCompile. Those can be configured separately.

@yourbuddyconner
yourbuddyconner / server.py
Created June 29, 2014 08:53
Python server to listen to a TCP socket and dump traffic to a file, then serve that file via HTTP
# A simple script that creates two TCP sockets, one that listens
# for and handles HTTP traffic on port 9000 and one that
# listens for and handles vanilla TCP traffic on port 9001
# Web Server portion is set up to support Cross Origin Requests, FYI
import sys # for exit()
import BaseHTTPServer # for WebHandler
import SocketServer # for everything
import json # for json parsing
@mrserverless
mrserverless / Configuration.java
Last active March 14, 2019 12:08
Dropwizard serving Static Assets on Root URL "/" and APIs on "/api/"
public class ApplicationConfiguration extends Configuration implements AssetsBundleConfiguration {
@Valid
@NotNull
@JsonProperty
private AssetsConfiguration assets;
@Override
public AssetsConfiguration getAssets() {
return assets;
}