Skip to content

Instantly share code, notes, and snippets.

View ashishtiwari1993's full-sized avatar
🏠
Working from home

Ashish Tiwari ashishtiwari1993

🏠
Working from home
View GitHub Profile
@ashishtiwari1993
ashishtiwari1993 / groupByOrderByLoadash.md
Created September 25, 2020 16:35
GroupBy orderBy with loadash

Use chain to apply groupBy() & orderBy() together with Loadash.

let data = [
  {"name":"foo","id":1},
  {"name":"bar","id":2},
  {"name":"foo","id":2},
  {"name":"foo","id":3},
  {"name":"bar","id":1},
 {"name":"bar","id":4},
@ashishtiwari1993
ashishtiwari1993 / promises-example.js
Created August 29, 2020 11:45
Javascript promises short example
function one(){
var promise = new Promise(function(resolve, reject){
setTimeout(function(){
console.log(1)
resolve()
}, 998)
})
return promise
}
@ashishtiwari1993
ashishtiwari1993 / spfLookup.go
Last active August 2, 2020 18:58
SPF Lookup in Go
package main
import (
"github.com/miekg/dns"
"strings"
"fmt"
)
func main() {
@ashishtiwari1993
ashishtiwari1993 / loop.go
Created February 28, 2020 13:58
This code will make 100% CPU utilization and `forever()` function not going to share any single CPU time with `anotherGoroutine()`
package main
import (
"fmt"
)
func main() {
go anotherGoroutine()
forever()
}
func forever() {
for {
@ashishtiwari1993
ashishtiwari1993 / fatal_map_writes.go
Last active February 4, 2020 11:18
Reproduce Golang "fatal error: concurrent map writes" & Solution. To reproduce comment Mutex related all operation like line no. 12, 30, 32, 44, 46. Mutex is use to prevent race condition which generates this error.
package main
import (
"fmt"
"sync"
// "time"
"strconv"
)
var activeInstances = make(map[int]string)
@ashishtiwari1993
ashishtiwari1993 / service_up_exporter.md
Last active October 12, 2020 16:36
Prometheus exporter to fetch if any specific service running or stopped.

Service up exporter for prometheus

(by @_ashish_tiwari)


It performs ps -ef | grep service_name | wc -l command and gives response in 1 or 0.

Get Start

  1. Install prometheus client by pip install prometheus_client.
@ashishtiwari1993
ashishtiwari1993 / aes.js
Created March 19, 2019 06:48
AES encryption and decryption with Node JS.
const crypto = require('crypto');
key = "secretKey";
string = "your string";
let encryptedString = encrypt(key,string);
let decryptedString = decrypt(key,encryptedString);
console.log(encryptedString);
console.log(decryptedString);
@ashishtiwari1993
ashishtiwari1993 / es_exception_challenges.md
Last active March 26, 2021 01:22
Below are some challenges & exceptions faced while setting up Elasticsearch. I just shared my experience and learning. Please correct me, If you guys feel somewhere i got wrong OR You can contribute if you have any experiences . Will keep update this gist.

(by @_ashish_tiwari)


Elasticsearch specification:

Version : 6.2
Heap size : 30 GB
core : 24
Memory : 128 GB
Client : PHP - 6.0