Skip to content

Instantly share code, notes, and snippets.

@vinayakg
vinayakg / LRU.java
Created March 24, 2024 14:14
LRU-CACHE
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
public class LRU {
// Modulus for HashMap Keys, i.e. Range (0, 9)
final static int LIMIT = 10;
// Evict the least recently used, once the load factor is reached.
@vinayakg
vinayakg / xlsxreadcount.js
Created March 24, 2024 13:03
count rows xlsx
const XLSX = require('xlsx');
const fs = require('fs');
const path = require('path');
const { createHash } = require('crypto');
let overallRowCount = 0;
try {
// Function to count rows in a single .xlsx file
const countRows = (filePath) => {
try {
@vinayakg
vinayakg / pgsql-encryption.sql
Created March 24, 2024 13:02
pgsql encryption
CREATE OR REPLACE FUNCTION en_cols()
RETURNS trigger AS
$$
DECLARE
continue_exception BOOLEAN;
assignable text;
BEGIN
continue_exception := TRUE;
PERFORM set_config('log_statement', 'none', true);
BEGIN
@vinayakg
vinayakg / ConsistentHashing-Simpler-V2.java
Last active September 15, 2024 14:55
Consistent Hashing
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.ThreadLocalRandom;
public class ConsistentHashing {
// Consistent Hashing with Ring having 360 buckets.
private static final int HASH_SPACE = 360; // Represents a circle from 0 to 359 degrees
private static final SortedMap<Integer, String> hashRing = new TreeMap<>();
@vinayakg
vinayakg / typebot.env
Last active March 5, 2024 13:41
typebot-env
# Make sure to change this to your own random string of 32 characters (https://docs.typebot.io/self-hosting/docker#2-add-the-required-configuration)
ENCRYPTION_SECRET=hearthathon-1234hearthathon-1234
DATABASE_URL=postgresql://postgres.gglbffzglevzeshvxmzb:[email protected]:5432/postgres
NEXTAUTH_URL=https://forms.heartfulness.org
NEXT_PUBLIC_VIEWER_URL=https://vform.heartfulness.org
[email protected]
DEFAULT_WORKSPACE_PLAN=UNLIMITED
DISABLE_SIGNUP=false
SMTP_USERNAME=AKIAZ2OBQRS7RGVPCGT7
SMTP_PASSWORD=BLOivbVa7ajLg+FVfzjEGqz+czMHZ6OOp4YecjQmo4Y7
@vinayakg
vinayakg / randomize-value-mysql.sql
Created February 25, 2024 14:44
randonmize value mysql
DELIMITER //
CREATE PROCEDURE Y9_PAYMENTS_SYNC (IN propertyTypeParam VARCHAR(255))
BEGIN
SET @randNumber = CEILING(RAND() * 100);
SET SQL_SAFE_UPDATES = 0;
IF @randNumber % 2 = 0 THEN
UPDATE `customer_app`.`client_program_configs` SET is_active = NOT is_active WHERE property_type = propertyTypeParam;
@vinayakg
vinayakg / mysql-encryption.sql
Last active February 25, 2024 14:41
mysql ecnryption
CREATE PROCEDURE customer_app.Y9_RECON()
BEGIN
DECLARE trans VARCHAR(30);
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
-- dont log to the log file
SET GLOBAL general_log = 'OFF';
SET GLOBAL log_bin = 'OFF';
SET SQL_SAFE_UPDATES = 0;
@vinayakg
vinayakg / table_generator.py
Created February 13, 2024 10:45
Data Generator python
import itertools
import psycopg2
import json
import random
import csv
import time
import sys
import datetime
import pytz
@vinayakg
vinayakg / api-tests.js
Last active February 8, 2024 12:12
k6 tests
import http from "k6/http";
import { check } from "k6";
import { Trend } from "k6/metrics";
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js";
import { textSummary } from "https://jslib.k6.io/k6-summary/0.0.1/index.js";
import papaparse from "https://jslib.k6.io/papaparse/5.1.1/index.js";
const citiesreq_dur = new Trend("zdur_citiesreq");
const allchoicesreq_dur = new Trend("zdur_allchoicesreq");
const campaignsreq_dur = new Trend("zdur_campaignsreq");
@vinayakg
vinayakg / aws-cost-allocation-monthly.sql
Last active January 3, 2024 07:28
AWS Detailed Billing DDL
-- public.hfn definition
-- Drop table
-- DROP TABLE public.hfn;
CREATE TABLE public.hfn (
"InvoiceID" int8 NULL,
"PayerAccountId" float4 NULL,
"LinkedAccountId" float4 NULL,