Skip to content

Instantly share code, notes, and snippets.

View krhaps's full-sized avatar
🧨
Focusing

Puneet Singh krhaps

🧨
Focusing
View GitHub Profile
@krhaps
krhaps / apicheck.go
Created October 9, 2021 15:12
kubernetes remotecommand go-client
// A working version of remotecommand
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
@krhaps
krhaps / elasticdev.sh
Last active May 14, 2021 16:50
ElasticSearch Dev Enviornment Setup
# install git, vim
# instance => e2-standard-4 (4 vCPU, 16GB Memory)
# Copy all jdks into a folder
gcloud compute copy-files ./* els:/home/touchps/softwares/jdk --zone "us-central1-a"
# add git prompt from following
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
# Increase the inotify limit
# cat /proc/sys/fs/inotify/max_user_watches
@krhaps
krhaps / geo.sh
Last active April 10, 2020 06:56
Redis DSA
# Adding coordinates <longitude, latitude>
# Longtude Degree horizontal (east)
# Latitide Degree vertical (North)
GEOADD gpo 77.5839739 12.910647 "Home"
GEOADD gpo 77.6965459 12.939111 "SLV Residency"
GEOADD gpo 77.6102169 12.935152 "Forum Mall"
GEOADD gpo 77.5964085 12.91486 "Freshco Supermarket"
GEOADD gpo 77.64062 12.892286 "Myntra Designs Pvt Ltd"
# Stored as sorted set
@krhaps
krhaps / local.sh
Last active July 27, 2019 14:00
ES Dev tool calls
GET _search
{
"query": {
"match_all": {}
}
}
GET prodbuilds/_search {
}
@krhaps
krhaps / es-node-client.js
Last active June 11, 2019 09:14
Elasticsearch sample nodejs search
const { Client } = require('@elastic/elasticsearch');
const { URL } = require('url');
let nodes = [{url: new URL("http://<server:port>")}, {url: new URL("<server:port>")},{url: new URL("<server:port>")}];
const client = new Client({
node: nodes,
maxRetries: 5,
requestTimeout: 60000,
sniffOnStart: true
@krhaps
krhaps / filebeat.yaml
Last active May 27, 2019 20:40
Filebeat Samples for docker
# this fails as json parsing happens 3 times, docker input itself, then json, then decode_json_fields
filebeat.inputs:
- type: docker
combine_partial: true
containers:
path: '/var/lib/docker/containers'
stream: 'all'
ids:
- "0db62a3d99474712c297e6f517c89b0a6f5bdf77648fbb5d03fa93d17c58d0ab"
json.message_key: log
@krhaps
krhaps / nats_async_subscribers.go
Last active April 9, 2019 12:08
NATS Async Subscriber
/**
* This is not a group, all subscriber receives the message
*/
package main
import (
nats "github.com/nats-io/go-nats"
"fmt"
"sync"
)
@krhaps
krhaps / Connect.js
Last active April 1, 2020 16:24
Sample Mongo java client using replica set
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
// Connection URL
const user = encodeURIComponent('username');
const password = '************';
const url = `mongodb://${user}:${password}@d7mongo41.company.com:27017,d7mongo41.company.com:27018,d7mongo41.company.com:27019/?authSource=dome&replicaSet=rs0`;
//const url = `mongodb://${user}:${password}@d7mongo41.company.com:27017?authSource=admin`;
@krhaps
krhaps / create_k8_job.go
Last active March 24, 2019 23:05
Create Job on kubernetes cluster with go-client
package main
import (
"fmt"
"flag"
"path/filepath"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/util/homedir"
"k8s.io/client-go/tools/clientcmd"
corev1 "k8s.io/api/core/v1"
batchv1 "k8s.io/api/batch/v1"
@krhaps
krhaps / time_loc.go
Created March 24, 2019 17:52
Location specific time parsing
loc, _ := time.LoadLocation("Asia/Kolkata")
format := "Jan _2 2006 3:04:05 PM"
fp1_time_string := "Mar 15 2019 06:30:00 AM"
fp2_time_string := "Mar 15 2019 10:30:00 AM"
fp1_time, _ := time.ParseInLocation(format, fp1_time_string, loc)
fp2_time, _ := time.ParseInLocation(format, fp2_time_string, loc)