Skip to content

Instantly share code, notes, and snippets.

View indrayam's full-sized avatar
💭
Onwards and upwards

Anand Sharma indrayam

💭
Onwards and upwards
View GitHub Profile
@indrayam
indrayam / file-modified
Last active December 16, 2015 03:49
Find how long ago file was modified
In OSX:
-------
echo "Token File = $TOKEN_FILE exists ..."
filetime=$(stat -f "%m" -t "%s" $TOKEN_FILE)
currtime=$(date +"%s")
secs_elapsed=$(($currtime-$filetime))
In Linux:
---------
echo "Token File = $TOKEN_FILE exists ..."
@indrayam
indrayam / awk-hacks.sh
Last active August 29, 2015 14:11
Using Awk to process Atlassian Stash Log Files
# Grab the time, the userid and the git version
cat atlassian-stash-access.log | awk -F'[|]' '($4 ~ /[:lower:]/) && ($7 ~/"" "git*/) {print $5, $4, $7;}' > phase1.txt
# Parse the git version number from the git details
cat phase1.txt | awk '{print $1, $2, $3, $5}' | sed s/\"//g > phase 2.txt

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

@indrayam
indrayam / ns2date.pl
Created May 26, 2016 20:32
Convert nanoseconds (as in InfluxDB measurements) into human readable date/timestamp
#!/usr/bin/perl -w
#
$num_of_args = $#ARGV + 1;
if ($num_of_args != 1) {
print "Usage: ns2date.pl <epochtime in nanoseconds>\n";
exit;
}
$ns = $ARGV[0];
print scalar localtime($ns / 1000000000) . "\n";
@indrayam
indrayam / create-jwt-using-unix-commands-on-mac.md
Last active September 21, 2022 08:08
Create JWT Token Header Using Unix Command line tools ONLY!

Pseudocode:

Y = Base64URLEncode(Header) + ‘.’ + Base64URLEncode(Payload)
JWT = Y + ‘.’ + Base64URLEncode(HMACSHA256(Y))

The steps called out here should work on a Mac as well. The only thing that might be different is the sed command used below. Instead of using -E, you will have to use -r to run sed with extended regular expression support

Use data from this tutorial:

scotch.io

@indrayam
indrayam / us-states.txt
Last active December 11, 2016 23:08
All US States as an Array
[Alabama, Alaska, Arizona, Arkansas, California, Colorado, Connecticut, Delaware, Florida, Georgia, Hawaii, Idaho, Illinois, Indiana, Iowa, Kansas, Kentucky, Louisiana, Maine, Maryland, Massachusetts, Michigan, Minnesota, Mississippi, Missouri, Montana, Nebraska, Nevada, New Hampshire, New Jersey, New Mexico, New York, North Carolina, North Dakota, Ohio, Oklahoma, Oregon, Pennsylvania, Rhode Island, South Carolina, South Dakota, Tennessee, Texas, Utah, Vermont, Virginia, Washington, West Virginia, Wisconsin, Wyoming]
@indrayam
indrayam / top-files-folders.sh
Last active December 11, 2016 23:07
Unix command to find the top 10 files and folders recursively inside a Unix folder
# These commands will ONLY work if you are using GNU 'du', 'find' and 'sort' commands
# Top 10 files by recursively diving inside the current folder (skip .git and .svn folders)
find . -type d \( -iregex ".*git" -o -iregex ".*svn" \) -prune -o -type f -exec du -Sh {} + | sort -rh | head -n 10
# Top 10 files by recursively diving inside the current folder (without skipping any folders)
find . -type f -exec du -Sh {} + | sort -rh | head -n 10
# Top 10 directories by recursively diving inside the current folder (skip .git and .svn folders)
du -Sh --exclude=".git" --exclude=".svn" | sort -rh | head -n 10
@indrayam
indrayam / latency.txt
Created February 1, 2017 04:45 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@indrayam
indrayam / tmux_build_from_source_ubuntu.sh
Created October 9, 2017 15:51
Install latest version of tmux in Ubuntu 16.04
# Steps to build and install tmux from source on Ubuntu.
# Takes < 25 seconds on EC2 env [even on a low-end config instance].
VERSION=2.5
sudo apt-get -y remove tmux
sudo apt-get -y install wget tar libevent-dev libncurses-dev
wget https://github.com/tmux/tmux/releases/download/${VERSION}/tmux-${VERSION}.tar.gz
tar xf tmux-${VERSION}.tar.gz
rm -f tmux-${VERSION}.tar.gz
cd tmux-${VERSION}
./configure
@indrayam
indrayam / .log
Created February 2, 2018 00:00
Minishift logs for debugging of the Error
-- minishift version: v1.12.0+daa0943
-- Starting profile 'minishift'
Found binary path at /usr/local/bin/minishift
Launching plugin server for driver virtualbox
Plugin server listening at address 127.0.0.1:56139
() Calling .GetVersion
Using API Version 1
() Calling .SetConfigRaw
() Calling .GetMachineName
(minishift) Calling .GetState