Skip to content

Instantly share code, notes, and snippets.

View ezarko's full-sized avatar

Eric Zarko ezarko

View GitHub Profile
@ezarko
ezarko / gist:d660d9653fae7a746094
Last active March 14, 2022 16:24
Use vimdiff for git diff
# vim
echo "au! BufRead,BufNewFile /tmp/* setlocal buftype=nofile" >> ~/.vimrc
echo "au! BufRead,BufNewFile /proc/* setlocal buftype=nofile" >> ~/.vimrc
echo "syntax on" >> ~/.vimrc
echo "set laststatus=2" >> ~/.vimrc
echo "set statusline=%f\ %h%w%m%r\ %=%(%l,%c%V\ %=\ %P%)" >> ~/.vimrc
# git
git config --global pager.diff ""
git config --global diff.external "/bin/bash -c 'vimdiff -o \"\$1\" \"\$4\"'"
@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 / 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 / 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 / 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}"
}