Skip to content

Instantly share code, notes, and snippets.

View swikars1's full-sized avatar
💫
getting act together

Swikar Sharma swikars1

💫
getting act together
View GitHub Profile
@swikars1
swikars1 / gist:c0cc70cdc2a92ef3c448471eecc5c436
Created July 7, 2025 05:04
Local to Server Deployment using Rsync for Docker
#!/bin/bash
# EOL Website Deployment Script
# Compatible with macOS and Linux
# Usage: ./deploy.sh [environment]
# Environment: staging (default) | production
set -e # Exit on any error
# Check if we're on macOS
@swikars1
swikars1 / gist:305ac421a91e3655c8ea235f7ee433d3
Created July 7, 2025 04:55
Pre Commit for Cache Busting for js and css
#!/bin/bash
# Function to bump version number in a string (e.g., 2.3 → 2.4)
bump_version() {
local version=$1
local major=$(echo $version | cut -d. -f1)
local minor=$(echo $version | cut -d. -f2)
minor=$((minor + 1))
echo "$major.$minor"
}
@swikars1
swikars1 / docker-compose.yml
Created January 8, 2025 10:45
mysql 8 docker compose
version: "3.8"
services:
mysql:
platform: linux/x86_64 # Add this line to ensure compatibility
image: mysql:8.0
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: mysqldb
@swikars1
swikars1 / firewall.sh
Created July 9, 2024 07:05
Common firewall config for Linux - bash file
#!/bin/bash
# Delete the current firewall setup:
iptables -F
# Define default rules for all chains:
iptables -P INPUT DROP
iptables -P FORWARD DROP
# Allow incoming/outgoing localhost frames for tests (e.g. Webserver, Mailserver):
@swikars1
swikars1 / tryCatch.ts
Last active January 29, 2024 23:23
Typescript tryCatch helper function using Rust like Result<T, E> types.
function tryCatch<T>(fn: () => T, andFinally?: () => void): Result<T, string> {
try {
return Ok(fn());
} catch (err) {
return Err(`Fn threw an error ${err}`);
} finally {
andFinally?.();
}
}
@swikars1
swikars1 / rustTypeHelpers.ts
Created January 29, 2024 23:00
Implementation of Rust like Result<T,E> and Option<T> in Typescript
interface SomeType<T> {
type: "some";
value: T;
/*** Returns the value of the Option if it exists, otherwise throws an error.*/
unwrap(): T;
/*** Returns the value of the Option if it exists, otherwise returns the provided default value.*/
unwrapOr(defaultValue: T): T;
/*** Returns the value of the Option if it exists, otherwise calls the provided function and returns its result.*/
unwrapOrElse(fn: () => T): T;
/*** Returns true if the Option contains a value, false otherwise.*/
@swikars1
swikars1 / App.js
Last active August 23, 2023 13:58
solution for conditional props react
import Component from "./Component";
import "./styles.css";
import { useState } from "react";
import { Check, Random } from "./random";
/**
* @Question
*Implement a theme switcher.that can switch between themes in entire application.
*/