Skip to content

Instantly share code, notes, and snippets.

View gowda's full-sized avatar

Basavanagowda Kanur gowda

View GitHub Profile
@gowda
gowda / do-split.sh
Created August 6, 2019 16:33
Split a large CSV file into smaller chunks & preserve header in each of the chunks, then upload each of the chunks to S3 bucket
#!/bin/bash
function __setup() {
input="$1";
# https://stackoverflow.com/a/32584935/1993020
OUTPUT_PREFIX=$(echo $input | rev | cut -f 2- -d'.' | rev);
header=$(head -1 $input);
@gowda
gowda / javascript-format-date-locale-issue.js
Last active February 13, 2019 18:53
Locale issue in stock nodejs distribution
// on node console: (on Feb 14th 2019)
> let date = new Date();
> date.toLocaleDateString("en-IN", {day: "2-digit", month: "2-digit", year: "numeric"});
'02/14/2019'
// Expected result: '14/02/2019'
// Github issue (https://github.com/nodejs/node/issues/8500) details the behaviour & provides solutions
// Easiest solution: https://github.com/nodejs/node/issues/8500#issuecomment-246437933
//
@gowda
gowda / typescript-inheritance-issue.ts
Created February 13, 2019 18:28
Typescript inheritance with complex constructor
/*
Retain original behaviour of new Date(), new Date("YYYY-MM-DD"), new Date(date /* Date */),
while allowing instantiation using new AppointmentDate("DD.MM.YYYY")
*/
class AppointmentDay extends Date {
constructor(date?: string | Date) {
if (!date) {
super();
} else if (date instanceof Date) {
super(date);
@gowda
gowda / bash-startup-time-with-lazy-loading-environment-managers.sh
Created October 3, 2018 11:57
Bash interactive login shell startup time with lazy loading for rvm, nvm, pyenv & jenv
$ time echo 'exit' | bash -li
$ exit
logout
real 0m0.370s
user 0m0.180s
sys 0m0.268s
@gowda
gowda / bash-startup-time-with-environment-managers.sh
Created October 3, 2018 11:55
Bash interactive login shell startup time when configuring rvm, nvm, pyenv & jenv
$ time echo 'exit' | bash -li
$ exit
logout
real 0m3.076s
user 0m1.287s
sys 0m1.107s
@gowda
gowda / bash-lazy-rvm-loader-for-ruby-tools.sh
Created October 3, 2018 11:50
Bash lazy loader function to configure rvm when any ruby bundle program is invoked
MACOS_RUBY_DIR="/System/Library/Frameworks/Ruby.framework/Versions/Current"
binaries=$(ls ${MACOS_RUBY_DIR}/usr/bin)
for binary in $binaries; do
source /dev/stdin <<EOF
function ${binary}() {
for t in ${binaries}; do
 unset -f "\$t";
done
local SCRIPT="\$HOME/.rvm/scripts/rvm"
@gowda
gowda / bash-lazy-rvm-loader-for-ruby.sh
Created October 3, 2018 11:48
Bash lazy loader function to configure rvm when ruby is invoked
function ruby() {
unset -f "ruby";
local SCRIPT="$HOME/.rvm/scripts/rvm"
 [[ -s ${SCRIPT} ]] && source ${SCRIPT};
ruby "$@";
}
@gowda
gowda / bash-lazy-loaded-rvm-invocation.sh
Created October 3, 2018 11:45
Invoking rvm after configuring lazy loading for rvm
$ time rvm - version # first invocation of rvm
rvm 1.29.4 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
real 0m0.677s
user 0m0.333s
sys 0m0.280s
$ time rvm - version # not first invocation of rvm
rvm 1.29.4 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
@gowda
gowda / bash-lazy-rvm-loader-for-rvm.sh
Created October 3, 2018 11:43
Bash lazy loader function to configure rvm when rvm itself is invoked
function rvm() {
unset -f "rvm";
local SCRIPT="$HOME/.rvm/scripts/rvm"
  [[ -s ${SCRIPT} ]] && source ${SCRIPT};
rvm "$@";
}
@gowda
gowda / bash-startup-time-without-rvm.sh
Created October 3, 2018 11:40
Bash interactive login shell startup time when not configuring rvm
$ time echo 'exit' | bash -li
$ exit
logout
real 0m0.039s
user 0m0.009s
sys 0m0.020s