Skip to content

Instantly share code, notes, and snippets.

@EricLondon
EricLondon / nodejs_promise_example.js
Last active November 9, 2016 14:29
NodeJS Promise Example
var error = undefined;
var result = "wee!";
var chainableMethod = function () {
return new Promise(function(resolve, reject) {
if (error) {
console.log('got error');
return reject(error);
}
console.log('no error');
@EricLondon
EricLondon / sidekiq.rake
Created November 10, 2016 14:45
Sidekiq status rake task
require 'sidekiq/api'
namespace :sidekiq do
desc 'Output Sidekiq Status'
task status: :environment do
divider = '=================================================='
puts "#{divider}\nSTATS"
stats = Sidekiq::Stats.new
puts "\tProcesses:\t#{stats.processes_size}"
@EricLondon
EricLondon / scala-get-methods.scala
Created August 25, 2017 11:30
scala-get-methods.scala
""
.getClass.getMethods.map(_.getName) // methods
.sorted // sort
.filter(_ matches "(?i).*index.*") // grep /index/i
/////////
implicit def toMethods(obj: AnyRef) = new {
def methods = obj.getClass.getMethods.map(_.getName)
}
@EricLondon
EricLondon / emr-zeppelin-status.rb
Last active October 5, 2017 14:14
EMR/Zeppelin API notebook status check
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
require 'pp'
ZEP_HOST = 'localhost'
ZEP_PORT = 8890
ZEP_ADDR = "http://#{ZEP_HOST}:#{ZEP_PORT}"
@EricLondon
EricLondon / Dockerfile
Created October 17, 2017 15:32
Docker build arguments
FROM busybox
ARG MESSAGE
RUN echo $MESSAGE > message.txt
@EricLondon
EricLondon / emr-zeppelin-run.rb
Created October 31, 2017 15:20
EMR/Zeppelin set interpreter and run all notebooks
#!/usr/bin/env ruby
require 'json'
require 'net/http'
require 'open-uri'
require 'pp'
require 'uri'
ZEP_HOST = 'localhost'
ZEP_PORT = 8890
@EricLondon
EricLondon / spark-scala-snippets.scala
Last active May 2, 2018 17:40
Spark Scala Snippets
////////////////////////////////////////////////////////////////////////////////////////////////////
// Custom UDF
////////////////////////////////////////////////////////////////////////////////////////////////////
// define method
def isNumeric: (String => Boolean) = {
case null => false
case value => value forall Character.isDigit
}
val ISNUMERIC = udf(isNumeric)
@EricLondon
EricLondon / chainable.js
Created April 9, 2018 14:56
javascript chainable promise example
let method1 = function() {
console.log("method1")
return true
}
let method2 = function() {
console.log("method2")
return true
}
@EricLondon
EricLondon / MapGroupSortLimit.java
Created May 30, 2018 18:29
Java 8 group Map by value, sort desc, and limit 10
Map<String, Long> counted = list.stream()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
Map<String, Long> sorted = counted.entrySet().stream()
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
.limit(10)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
@EricLondon
EricLondon / .1_readme.txt
Last active October 16, 2018 14:27
Export Elasticsearch spark driver log messages
# usage
nvm use .
npm install
chmod +x export-spark-driver-logs.sh
./export-spark-driver-logs.sh $ES_IP:$ES_PORT driver-##############-####