Skip to content

Instantly share code, notes, and snippets.

View vslala's full-sized avatar

Varun Shrivastava vslala

View GitHub Profile
@vslala
vslala / main.tf
Created June 18, 2023 14:54
Terraform deploy lambda with API Gateway
variable "aws_profile" {
description = "AWS Profile For Deployment"
}
variable "aws_region" {
description = "AWS Region For Deployment"
}
variable "project" {
type = string
@vslala
vslala / EventBusDemo.tsx
Last active May 8, 2023 10:43
Example of Using Event Bus for communication between components
interface PostalChannel {
channel: string,
topic: string
}
export const useEventBus = (channel: PostalChannel, callback: (data: any) => void) => {
const [state, setState] = useState({});
useEffect(() => {
const subscription = postal.subscribe({
@vslala
vslala / EventBus.ts
Created May 8, 2023 10:29
Custom Event Bus Using React/Typescript
export interface Subscriber {
name: string
callback: (data: any) => void
}
class EventBus {
private static instance: EventBus | undefined
private subscribers: Map<string, Array<Subscriber>>
constructor() {
@vslala
vslala / tilde-switch.sh
Created December 1, 2022 10:51
This is to replace tilde key (~) with (§) in new mac keyboard
cat << 'EOF' > ~/.tilde-switch && chmod +x ~/.tilde-switch
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x700000064},{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035}]}'
EOF
sh .tilde-switch
# To revert back, run the following:
# hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x700000035},{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000064}]}'
@vslala
vslala / persistence.xml
Created September 1, 2022 10:27
Persistence XML for bootstrapping persistence hibernate
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
@vslala
vslala / BottomUpMergeSort.java
Created June 23, 2021 18:42
Iterative Merge Sort A.K.A Bottom Up Merge Sort
import java.util.Arrays;
public class BottomUpMergeSort implements Sort {
@Override
public int[] sort(int[] input) {
var arr = Arrays.copyOf(input, input.length);
var aux = new int[input.length];
for (var width = 1; width < arr.length; width = 2 * width) {
int i;
for (i = 0; i < arr.length; i = i + 2 * width) {
@vslala
vslala / bitbucket-webhooks-api.py
Created June 13, 2021 08:06
Add/Delete Webhooks in Bitbucket Server Using REST API 1.0
import os
import requests
import json
from app.report import Report
BITBUCKET_BASE_URL = os.environ['BITBUCKET_URL'] # bitbucket base url
ACCESS_TOKEN = os.environ['ACCESS_TOKEN'] # get this token from bitbucket account
JENKINS_BASE_URL = os.environ['JENKINS_URL'] # host url for Jenkins
headers = {

Trie Data Structure

It is a symbol table specialized to string keys.

The goal is to device a data structure that is Faster than hashing and More flexible than BSTs.

Challenge - Efficient Performance for String keys

R-Way Trie

@vslala
vslala / modified_kaprekar_number.cpp
Created October 28, 2020 05:50
Modified Kaprekar Number - Hacker rank problem
#include<iostream>
using namespace std;
int low;
int hi;
void test_cases() {
cin >> low; cin.ignore();
cin >> hi; cin.ignore();
@vslala
vslala / SortingAlgorithmComparision.java
Created May 28, 2020 19:00
Multi-threaded Code for generating time-complexity of elementary sorting algorithms
import com.bma.algorithms.sort.elementary.Util;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;