Skip to content

Instantly share code, notes, and snippets.

View dportabella's full-sized avatar

David Portabella dportabella

  • Lausanne, Switzerland
View GitHub Profile
@dportabella
dportabella / gist:5766099
Last active December 18, 2015 10:09
Transform a callback function to an iterator/list (in Scala or Java). See an example use case: http://scalaenthusiast.wordpress.com/2013/06/12/transform-a-callback-function-to-an-iteratorlist-in-scala/
import java.util.concurrent.ArrayBlockingQueue
trait OptionNextToIterator[T] extends Iterator[T] {
def getOptionNext: Option[T];
var answerReady: Boolean = false
var eof: Boolean = false
var element: T = _
def hasNext = {
@dportabella
dportabella / TestJKS.java
Last active January 26, 2024 19:34
Test your JKS file easily with java -Djavax.net.ssl.trustStore=your_trust_store.jks TestJKS <url> [<user> <password>]
/*
Test your JKS file easily.
You have created a java JKS trust store file to access a webservice with a certificate, and you want to test if it works?
Some colleagues often test this by deploying the jks to the application server (tomcat, weblogic...), restarting the server and manually running tests,
and repeating this procedure until the jks is properly created.
you can speed up this test by using this simple java program:
> javac TestJKS.java
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>david.rundeck</string>
<key>ProgramArguments</key>
<array>
<string>/Users/david/bin/rundeck/server/sbin/rundeck_launchd</string>
</array>
@dportabella
dportabella / dstat
Last active August 29, 2015 13:56
command line tool to list all files, with properties and checksum
#! /bin/bash
# use this script as follows: find . -mount -exec dstat {} \;
# this produces a list as follows:
# Regular File -rw-r--r-- david staff 2013-11-09 01:33:24 2013-11-09 01:33:24 14787 c3a7afd9e3cf89543352ee58e26cfb10 Invoice_41010102336895558_6601081486112013.pdf pdf ./accounting/files/Invoice_41010102336895557_6601081486112013.pdf
# Regular File -rw-r--r-- david staff 2013-09-01 00:41:05 2013-09-01 00:41:05 13636 55b47d2a41d5d6a072439ef2dabacac4 Invoice_41010102336895558_6601108809092013.pdf pdf ./accounting/files/Invoice_41010102336895557_6601108809092013.pdf
# ...
# see http://linux.die.net/man/1/stat for more stat options
if [ -z "$1" ] ; then
@dportabella
dportabella / gist:9388448
Last active August 29, 2015 13:57
ruby, converting an array of hashes to a hash based on hash key
def hasharray2hash(array, hash_key)
if (!array.kind_of?(Array) || !hash_key.kind_of?(String))
raise 'invalid parameters'
end
array.reduce({}){|cumulate,entry|
if !entry.kind_of?(Hash)
raise 'expecting a hash: ' + entry.to_s
end
key = entry[hash_key]
@dportabella
dportabella / biemond-orawls-vagrant-javaexec-log.txt
Created April 10, 2014 11:41
install weblogic with wlst using biemond-orawls puppet module. this is the log of all java executions, by using this patched vagrant https://github.com/dportabella/biemond-orawls-vagrant/tree/javaexec_log
+++++++++++++++++++++++++++++
+++ EXECUTING JAVA. CMD: java -version +++ start provisioning +++
+++ EXECUTING JAVA. time: 20140410-093331
+++ EXECUTING JAVA. java: /usr/java/jdk1.7.0_51/jre/bin/java
+++ EXECUTING JAVA. cp:
+++ EXECUTING JAVA. user: root
+++ EXECUTING JAVA. running. log: /tmp/log_puppet_weblogic/log-20140410-093331.txt
+++ EXECUTING JAVA. cat /tmp/log_puppet_weblogic/log-20140410-093331.txt. START.
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
@dportabella
dportabella / setup_puppet_developer_env_and_run_spec_tests.sh
Last active August 29, 2015 13:59
Set-up an environment to run puppet as a developer and run the spec tests
# here there is a guide about contributing to puppet:
# https://github.com/puppetlabs/puppet/blob/master/docs/quickstart.md
# It says:
# Quick Start to Developing on Puppet
# Before diving into the code, you should first take the time to make sure you have an environment where you can run puppet as a developer.
# In a nutshell you need: the puppet codebase, ruby versions, and dependencies.
# Once you've got all of that in place you can make sure that you have a working development system by running the puppet spec tests.
#
# I didn't manage to install all this in my OSX without breaking other dependencies, so I created a vagrant box with Ubuntu.
# I share here this set-up, so that it can be reproduced easily by anyone.
@dportabella
dportabella / ExampleScalaAck.scala
Created August 22, 2014 22:46
this example Scala scripts executes a regex to all files recursively. it uses apache tika UniversalEncodingDetector to filter only text files. it uses a regex to find all lines containing the word "super", except if this word is part of the larger word "superstition" or "supernatural".
import java.io.File
import org.apache.tika.detect._
import org.apache.tika.metadata._
import org.apache.tika.mime._
import org.apache.tika.io._
import org.apache.tika.parser.txt._
import resource._
def recursiveListFiles(f: File): List[File] = {
val these = f.listFiles.toList
@dportabella
dportabella / PomDependenciesToSbt
Last active May 7, 2022 16:25
Script to convert Maven dependencies (and exclusions) from a pom.xml to sbt dependencies. Or run it online on http://goo.gl/wnHCjE
#!/usr/bin/env amm
// This script converts Maven dependencies from a pom.xml to sbt dependencies.
// It is based on the answers of George Pligor and Mike Slinn on http://stackoverflow.com/questions/15430346/
// - install https://github.com/lihaoyi/Ammonite
// - make this script executable: chmod +x PomDependenciesToSbt
// - run it with from your shell (e.g bash):
// $ ./PomDependenciesToSbt /path/to/pom.xml
import scala.xml._
@dportabella
dportabella / build.sbt
Last active May 31, 2016 02:07
sbt project for the spark distribution examples
val sparkVersion = "1.6.1"
val hbaseVersion = "0.98.7-hadoop2"
name := "spark-examples"
version := sparkVersion
javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint")
initialize := {