Skip to content

Instantly share code, notes, and snippets.

View meswapnilwagh's full-sized avatar

Swapnil Abhimanyu Wagh meswapnilwagh

View GitHub Profile
@meswapnilwagh
meswapnilwagh / calendar.tsx
Created April 24, 2024 17:47 — forked from mjbalcueva/calendar.tsx
shadcn ui calendar custom year and month dropdown
"use client"
import * as React from "react"
import { buttonVariants } from "@/components/ui/button"
import { ScrollArea } from "@/components/ui/scroll-area"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { cn } from "@/lib/utils"
import { ChevronLeft, ChevronRight } from "lucide-react"
import { DayPicker, DropdownProps } from "react-day-picker"
const myMemoize = (func) => {
const cache = {};
return (...args) => {
const argCache = JSON.stringify(args);
if (!(argCache in cache)) {
cache[argCache] = func(...args)
}
return cache[argCache];
}
}
// Infinite add using currying
const add = (a) => (b) => {
if (b) return add(a + b)
return a
}
console.log(add(1)(2)(3)()); // 6
console.log(add(5)(20)(10)(30)()); // 65
// DS Stack uisng JS Clousers
const buildStack = () => {
let items = []
const push = (item) => items = [...items, item];
const pop = () => items = items.slice(1);
const peek = () => items[0];
const isEmpty = () => !items.length;
const size = () => items.length;
const list = () => items;
// JSON DB Query engine using JS currying
// Ref: https://www.freecodecamp.org/news/playing-around-with-closures-currying-and-cool-abstractions/
const db = {
"friends": [
{
"id": 1,
"name": "Nitin",
"age": 35,
"email": "nitin@meswapnilwagh.com"
@meswapnilwagh
meswapnilwagh / elb.aws.settings.inc
Created May 30, 2018 06:09 — forked from mpezzi/elb.aws.settings.inc
Drupal - Amazon Elastic Load Balancer HTTPS Settings
<?php
/**
* @file
* Amazon Elastic Load Balancer Settings.
*
* Force server to use https:// path if SSL is handled at load balancer.
*
* @see http://drupal.org/node/185161#comment-5452038
*/
@meswapnilwagh
meswapnilwagh / doc2pdf-linux.py
Created April 4, 2018 12:35
doc2pdf converter for linux
import sys
import os
import comtypes.client
wdFormatPDF = 17
in_file = "path_to_doc_file"
out_file = "path_to_save_pdf"
word = comtypes.client.CreateObject('Word.Application')
@meswapnilwagh
meswapnilwagh / doc2pdf-win.py
Last active April 4, 2018 12:35
doc2pdf convert for Windows.
import sys
import os
import win32com.client
wdFormatPDF = 17
in_file = "path_to_doc_file"
out_file = "path_to_save_pdf"
word = win32com.client.Dispatch('Word.Application')
@meswapnilwagh
meswapnilwagh / lambdaAMICleanup.py
Created August 10, 2017 05:13 — forked from bkozora/lambdaAMICleanup.py
AWS Lambda Function to Delete AMIs and Snapshots
# Automated AMI and Snapshot Deletion
#
# @author Robert Kozora <bobby@kozora.me>
#
# This script will search for all instances having a tag with "Backup" or "backup"
# on it. As soon as we have the instances list, we loop through each instance
# and reference the AMIs of that instance. We check that the latest daily backup
# succeeded then we store every image that's reached its DeleteOn tag's date for
# deletion. We then loop through the AMIs, deregister them and remove all the
# snapshots associated with that AMI.
@meswapnilwagh
meswapnilwagh / .bash_profile
Created December 17, 2016 13:52 — forked from dobsondev/.bash_profile
My personal .bash_profile file on my Mac. It styles my bash prompt in a way I like and also adds some useful alias.
# ~/.bash_profile
[[ -s ~/.bashrc ]] && source ~/.bashrc
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
alias subl='/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl'
alias ls='ls -GFh'
alias ll='ls -l'