Skip to content

Instantly share code, notes, and snippets.

@jasdeepkhalsa
jasdeepkhalsa / video-pip-bookmarklet.js
Created Apr 7, 2021
Video Picture-In-Picture Bookmarklet
View video-pip-bookmarklet.js
javascript:let video=document.getElementsByTagName('video')[0];video.removeAttribute('disablePictureInPicture');video.requestPictureInPicture()
@jasdeepkhalsa
jasdeepkhalsa / sdout.ts
Created Mar 15, 2021
Explicit output to SDOUT using JavaScript instead of using console.log
View sdout.ts
process.stdout.write('hello world')
@jasdeepkhalsa
jasdeepkhalsa / gcp-docker-k8s-jenkins.sh
Last active Mar 8, 2021
GCP with Docker, K8s & Jenkins
View gcp-docker-k8s-jenkins.sh
## 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 Mar 5, 2021 — forked from igrigorik/index.html
XHR streaming example
View index.html
<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 / docker-cmd.sh
Last active Feb 14, 2021
Docker power commands
View docker-cmd.sh
# 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 / gcp.sh
Last active Feb 27, 2021
GCP gcloud provisioning
View gcp.sh
## 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 Feb 5, 2021
Role -> Trust Relationship on Principle to enable Lambda@Edge for a given Lambda
View aws-lambda-edge.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com",
"edgelambda.amazonaws.com"
]
@jasdeepkhalsa
jasdeepkhalsa / rejection-based-retry.ts
Created Jan 18, 2021
Exponential backoff retry strategy for async
View rejection-based-retry.ts
// General purpose Rejection-based retrying
// Source: https://advancedweb.hu/how-to-implement-an-exponential-backoff-retry-strategy-in-javascript/
const wait = (ms) => new Promise((res) => setTimeout(res, ms));
const maybeFail = (successProbability, result, error) => new Promise((res, rej) => Math.random() < successProbability ? res(result) : rej());
const maybeFailingOperation = async () => {
await wait(10);
return maybeFail(0.1, "result", "error");
}
@jasdeepkhalsa
jasdeepkhalsa / promiseAny.ts
Created Jan 15, 2021
Promise Any with TypeScript Generic Return Type
View promiseAny.ts
type PromiseAny<T = any> = Promise<T>;
interface IClass {
methodA: (
paramA?: string,
) => PromiseAny | void;
}
View Dockerfile
# Disable PHAR readonly for producing PHAR archives
RUN echo 'phar.readonly=0' >> /usr/local/etc/php/conf.d/docker-php-phar-readonly.ini