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 / 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.
*/