Skip to content

Instantly share code, notes, and snippets.

View ezarko's full-sized avatar

Eric Zarko ezarko

View GitHub Profile
@ezarko
ezarko / read_java_properties.sh
Created February 12, 2018 20:49
Bash snippet to read a Java properties file into a bash associative array.
declare -A props
eval `grep -v '^#' $PROPS_FILE | sed -e 's/"/\\"/g;s/\${\([^}]*\)}/${props[\1]}/g;s/^\([^=]*\)=\(.*\)$/props[\1]="\2"/'`
@ezarko
ezarko / jdk8_getRequestHeadersAsMap.java
Created February 8, 2018 22:55
Given an HttpServletRequest named request, creates a Map<String, String> of the headers.
Map<String, String> headers = Collections.list(request.getHeaderNames()).stream().collect(Collectors.toMap(Function.identity(), n -> request.getHeader(n)));
@ezarko
ezarko / sqlplus.bash
Last active December 20, 2017 20:32
A convenience function which turns the complex sqlplus syntax into getopt style arguments. Also supports using sqlplus in a docker image/container.
function sqlplus {
local USER=SYS
local PASS=<default_password>
local NET
local HOST=localhost
local PORT
local SID=<default_sid>
local ROLE=SYSDBA
local EDITION
local DEFAULT_DOCKER_IMAGE=oracle/database:12.2.0.1-ee
#!/bin/perl
use strict;
use warnings;
use JSON;
$/ = undef;
print JSON->new->allow_nonref->pretty->encode(decode_json scalar <>);
@ezarko
ezarko / create_ref_repo.sh
Last active November 13, 2020 15:32
Creates a "reference repository" on a Jenkins slave to speed up build times.
#!/bin/bash
# Creates a "reference repository" on a Jenkins slave to speed up build times.
# Assumes that you will clone using HTTPS and enter username/password, then
# Jenkins will use an SSH key in the future.
#
# Works with Jenkins and GitLab. For other applications your mileage may vary.
REPO_SERVER=osn-git.us.oracle.com
REPO_PATH=ccs/caas.git
@ezarko
ezarko / findCommonParent.js
Created June 1, 2016 14:10
Given two DOM elements in the same document, find the closest common ancestor (which could be one of the elements).
function findCommonParent(a, b) {
var $a = $(a),
$b = $(b),
found;
/*
* A complicated one-liner here; with each element a & b,
* get the set of parents,
* and add to this the element
* .add() will sort the elements in document order though
@ezarko
ezarko / docker-mariadb.bash
Last active May 20, 2016 16:30
Useful bash function for interacting with a mysql database in a mariadb docker container.
# mysql <container> [...]
function mysql {
docker run -it --link $1:mysql --rm mariadb sh -c "exec mysql -h\"\$MYSQL_PORT_3306_TCP_ADDR\" -P\"\$MYSQL_PORT_3306_TCP_PORT\" -uroot -p\"\$MYSQL_ENV_MYSQL_ROOT_PASSWORD\" ${@:2}"
}
# mysqladmin <container> [...]
function mysqladmin {
docker run -it --link $1:mysql --rm mariadb sh -c "exec mysqladmin -h\"\$MYSQL_PORT_3306_TCP_ADDR\" -P\"\$MYSQL_PORT_3306_TCP_PORT\" -uroot -p\"\$MYSQL_ENV_MYSQL_ROOT_PASSWORD\" ${@:2}"
}
@ezarko
ezarko / jQuery.reduce.js
Last active March 14, 2018 01:25
A jQuery reduce function which returns a proper collection object. Note that callback is called with DOM nodes that will need to be $()'d if needed.
$.fn.reduce = function() {
return (arguments.length > 1 || this.length) ? $([].reduce.apply(this.toArray(), arguments)) : this;
};
@ezarko
ezarko / Docker and Express
Last active February 18, 2016 21:13
Simple express server application
You can add matic by adding "matic" and "jade" to the package.json, then add "RUN $(npm bin)/matic" to the Dockerfile.
I wonder if it would be as easy to add harpjs?