Skip to content

Instantly share code, notes, and snippets.

@matharoo
matharoo / issuer.yaml
Created October 20, 2020 06:32
example self-signed issuer for cert-manager
apiVersion: cert-manager.io/v1alpha2
kind: Issuer
metadata:
name: selfsigned
spec:
selfSigned: {}
@matharoo
matharoo / mynode-ingress.yaml
Last active October 24, 2020 21:06
mynode-app ingress example
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: mynode-ingress
namespace: nodejs
spec:
rules:
- host: mynodeapp.com
http:
paths:
@matharoo
matharoo / mynode-service.yaml
Created October 19, 2020 04:08
mynode-app service.yaml using Loadbalancer example
apiVersion: v1
kind: Service
metadata:
name: mynode-app
namespace: nodejs
spec:
selector:
app: mynode-app
ports:
- port: 80
@matharoo
matharoo / mynode-deployment.yaml
Created October 19, 2020 04:07
mynode-app deployment.yaml example
apiVersion: apps/v1
kind: Deployment
metadata:
name: mynode-app
namespace: nodejs
spec:
replicas: 2
selector:
matchLabels:
app: mynode-app
@matharoo
matharoo / debug.sh
Created November 13, 2019 16:50
debugging using -x in bash
#!/bin/bash
var1='A'
var2='B'
my_function () {
local var1='C'
var2='D'
echo "Inside function: var1: $var1, var2: $var2"
}
@matharoo
matharoo / domainName.js
Created November 6, 2019 03:08
Extract the domain name from a URL ... just the domainName extractor before .[coms,nets...]
function domainName(url){
if(url.search('//')>0){
url = url.slice(url.search('//')+2);
}
if(url.search('www')>=0){
url = url.slice(url.search('www')+4);
}
return url.slice(0,url.indexOf('.'));
}
@matharoo
matharoo / sortByName.js
Last active October 23, 2019 23:58
convert 0-999 to their alphabet forms, sort them and return back number form.. not the best implementation needs some refactoring.
function sortByName(arr) {
let ones= ['zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen'];
let tens = ['','','twenty','thirty','fourty','fifty','sixty','seventy','eighty','ninety']
let alphanums = {}
arr.forEach((v,i)=>{
let numstring = String(v)
numstring =numstring.split('').reverse('').join('');
let len= numstring.length;
let str=''
let x= 0;
@matharoo
matharoo / builder-pattern.js
Created October 22, 2019 23:10
Builder pattern in JS
class Address{
constructor(street,city,country){
this.street = street;
this.city = city;
this.country = country;
}
}
class User{
@matharoo
matharoo / async-await.js
Created October 22, 2019 20:21
Using async/await in javascript, transforming promise to chain to async/await
function callApi(url){
return new Promise((resolve,reject) => {
console.log(`calling API: ${url}`)
if(url==='twitter'|| url=='facebook'){
resolve(`connected to ${url}`)
}
else{
reject(`Sorry unsupported API : ${url}`)
}
});
@matharoo
matharoo / sudoku-validator.js
Created October 21, 2019 05:34
A function that accepts a 2D array representing a Sudoku board, and returns true if it is a valid solution, or false otherwise. The cells of the sudoku board may also contain 0's, which will represent empty cells. Boards containing one or more zeroes are considered to be invalid solutions.
function validSolution(board) {
let valid = true;
const testvaliditiy = (arr) => {
let set = new Set(arr);
if (arr.includes(0) || [...set].length !== 9) {
return false;
} else {
return true;
}
}