Skip to content

Instantly share code, notes, and snippets.

View sohamkamani's full-sized avatar
🐦
🐧

Soham Kamani sohamkamani

🐦
🐧
View GitHub Profile
@sohamkamani
sohamkamani / rsa.go
Created April 12, 2020 17:31
Example of RSA encryption, decryption, signing, and verification in Go
package main
import (
"crypto"
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"encoding/base64"
"fmt"
)
@sohamkamani
sohamkamani / rsa.js
Last active April 7, 2024 21:41
An example of RSA Encryption implemented in Node.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 / rabbitmq_go_sample.go
Created March 13, 2018 12:59
An example of a simple pub-sub workflow for rabbitmq in go
package queue
import (
"fmt"
"log"
"github.com/streadway/amqp"
)
var conn *amqp.Connection
@sohamkamani
sohamkamani / create_tables.sql
Last active October 12, 2023 19:01
Script to create tables for my tutorial on https://www.sohamkamani.com/sql-guide/
CREATE TABLE books (
bookid serial PRIMARY KEY,
title text,
author text,
published date,
stock int
);
INSERT INTO
books (bookid, title, author, published, stock)
@sohamkamani
sohamkamani / gist:52c0e24fa776c2b36aa9e088a0f6120b
Created September 20, 2023 11:11
Java formatting stylegiude
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="13">
<profile kind="CodeFormatterProfile" name="GoogleStyle" version="13">
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
@sohamkamani
sohamkamani / localstorage_lru_cache.html
Created July 21, 2020 16:27
An example of how to implement LRU cache with eviction using the HTML5 localStorage API
<!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 / statsd_send.go
Created June 28, 2018 06:22
sending metrics to statsd via udp in 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")
res, err := client.Get("http://www.gojek.io/", nil)
if err != nil {
panic(err)
}
fmt.Println(string(res.Body()))
// 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
# 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"