Skip to content

Instantly share code, notes, and snippets.

View jasdeepkhalsa's full-sized avatar

Jasdeep Khalsa jasdeepkhalsa

View GitHub Profile
@jasdeepkhalsa
jasdeepkhalsa / date.format.js
Created February 1, 2013 11:23
JavaScript Date Format by Steven Levithan
/*
* Date Format 1.2.3
* (c) 2007-2009 Steven Levithan <stevenlevithan.com>
* MIT license
*
* Includes enhancements by Scott Trenda <scott.trenda.net>
* and Kris Kowal <cixar.com/~kris.kowal/>
*
* Accepts a date, a mask, or a date and a mask.
* Returns a formatted version of the given date.
@jasdeepkhalsa
jasdeepkhalsa / docker-cmd.sh
Last active December 8, 2021 21:16
Docker power commands
# Stop all containers
docker stop $(docker ps -q)
# Remove all containers
docker rm $(docker ps -aq)
# Remove all images
docker rmi $(docker images -aq)
# See logs of a container
@jasdeepkhalsa
jasdeepkhalsa / stringifySafely.ts
Last active November 30, 2021 13:51
Stringify JavaScript Objects -> JSON or other parsers safely
// Adapted from the Axios HTTP library
// https://github.com/axios/axios/blob/76f09afc03fbcf392d31ce88448246bcd4f91f8c/lib/defaults.js#L29
/**
* Trim excess whitespace off the beginning and end of a string
*
* @param {String} str The String to trim
* @returns {String} The String freed of excess whitespace
*/
const trim = (str) => {
@jasdeepkhalsa
jasdeepkhalsa / video-pip-bookmarklet.js
Created April 7, 2021 20:45
Video Picture-In-Picture Bookmarklet
javascript:let video=document.getElementsByTagName('video')[0];video.removeAttribute('disablePictureInPicture');video.requestPictureInPicture()
@jasdeepkhalsa
jasdeepkhalsa / sdout.ts
Created March 15, 2021 16:30
Explicit output to SDOUT using JavaScript instead of using console.log
process.stdout.write('hello world')
@jasdeepkhalsa
jasdeepkhalsa / pipe.js
Last active March 12, 2021 15:42 — forked from ericelliott/pipe.js
Pipe
// Pipe takes the first argument and pipes it though each of the functions that you provide as the remaining arguments,
// and can be implemented as follows:
const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x);
const fn1 = s => s.toLowerCase();
const fn2 = s => s.split('').reverse().join('');
const fn3 = s => s + '!'
const newFunc = pipe(fn1, fn2, fn3);
const result = newFunc('Time'); // emit!
@jasdeepkhalsa
jasdeepkhalsa / gcp-docker-k8s-jenkins.sh
Last active March 8, 2021 22:31
GCP with Docker, K8s & Jenkins
## This script covers
# * Running Docker containers on a host.
# * Storing Docker images in the Google Container Repository (GCR).
# * Deploying GCR images on Kubernetes.
# * Pushing updates onto Kubernetes.
# * Automating deployments to Kubernetes using Jenkins.
GCP_PROJECT_ID="qwiklabs-gcp-04-17810074a304"
# Clone a repository from the Google Cloud Shell
@jasdeepkhalsa
jasdeepkhalsa / index.html
Created March 5, 2021 12:44 — forked from igrigorik/index.html
XHR streaming example
<p>Hello
<script>
var xhr = new XMLHttpRequest();
xhr.open('GET', '/stream');
xhr.seenBytes = 0;
xhr.onreadystatechange = function() {
console.log("state change.. state: "+ xhr.readyState);
@jasdeepkhalsa
jasdeepkhalsa / gcp.sh
Last active February 27, 2021 18:13
GCP gcloud provisioning
## General commands
# Get active account name
gcloud auth list
# List the project ID
gcloud config list project
# Find default zone
gcloud compute project-info describe --project <GCP Project ID>
@jasdeepkhalsa
jasdeepkhalsa / aws-lambda-edge.json
Created February 5, 2021 17:33
Role -> Trust Relationship on Principle to enable Lambda@Edge for a given Lambda
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com",
"edgelambda.amazonaws.com"
]