Skip to content

Instantly share code, notes, and snippets.

Avatar
🐦
🐧

Soham Kamani sohamkamani

🐦
🐧
View GitHub Profile
@sohamkamani
sohamkamani / localstorage_lru_cache.html
Created Jul 21, 2020
An example of how to implement LRU cache with eviction using the HTML5 localStorage API
View localstorage_lru_cache.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>LocalStorage With LRU Eviction</title>
</head>
<body>
<button id="btn-set">Set</button><br />
Key: <input id="input-set-key" /><br />
@sohamkamani
sohamkamani / rsa.js
Last active Oct 6, 2021
An example of RSA Encryption implemented in Node.js
View rsa.js
const crypto = require("crypto")
// The `generateKeyPairSync` method accepts two arguments:
// 1. The type ok keys we want, which in this case is "rsa"
// 2. An object with the properties of the key
const { publicKey, privateKey } = crypto.generateKeyPairSync("rsa", {
// The standard secure default length for RSA keys is 2048 bits
modulusLength: 2048,
})
@sohamkamani
sohamkamani / rsa.go
Created Apr 12, 2020
Example of RSA encryption, decryption, signing, and verification in Go
View rsa.go
package main
import (
"crypto"
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"encoding/base64"
"fmt"
)
@sohamkamani
sohamkamani / statsd_send.go
Created Jun 28, 2018
sending metrics to statsd via udp in Go
View statsd_send.go
func main() {
conn, err := net.Dial("udp", "127.0.0.1:8125")
if err != nil {
fmt.Printf("Some error %v", err)
return
}
for i := 0; i < 10; i++ {
// This is the only line of code you need to push stats to telegraf
fmt.Fprintf(conn, "deploys.test.myservice,from=go:1|c")
@sohamkamani
sohamkamani / rabbitmq_go_sample.go
Created Mar 13, 2018
An example of a simple pub-sub workflow for rabbitmq in go
View rabbitmq_go_sample.go
package queue
import (
"fmt"
"log"
"github.com/streadway/amqp"
)
var conn *amqp.Connection
View heimdall_sample2.go
res, err := client.Get("http://www.gojek.io/", nil)
if err != nil {
panic(err)
}
fmt.Println(string(res.Body()))
View heimdall_sample1.go
// After importing "github.com/gojektech/heimdall"
// Create a new hystrix configuration, and input the command name, along with other required options
hystrixConfig := heimdall.NewHystrixConfig("downstream_get_request", heimdall.HystrixCommandConfig{
ErrorPercentThreshold : 20,
MaxConcurrentRequests: 30,
Timeout: 1000,
SleepWindow: 1500
})
// Create a new hystrix-wrapped HTTP client
View .zshrc
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
export MONGO_URL="mongodb://localhost/baybank"
source ~/.iterm2_shell_integration.`basename $SHELL`
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"
View oops-in-browser.html
<html>
<head>
<title>My first Three.js app</title>
<style>
.list-item {
font-size: 1.2em;
color: black;
}
.completed {
@sohamkamani
sohamkamani / dirs-to-js.py
Created Mar 12, 2015
Lists all directories and stores them as a variable in a js file
View dirs-to-js.py
import os
import os.path
d='.'
dirs = [os.path.join(d,o) for o in os.listdir(d) if os.path.isdir(os.path.join(d,o))]
dir_sanitized = []
for dir in dirs:
dir_sanitized.append(dir.split('/')[1])
dirmap = open('dirmap.js','w')
dirmap.write("var directories=[");