Skip to content

Instantly share code, notes, and snippets.

View sagarpanchal's full-sized avatar

Sagar Panchal sagarpanchal

View GitHub Profile
@holmberd
holmberd / js-nestGroupsBy.md
Last active June 7, 2024 11:09
Dynamically create nested level groups by properties in Javascript

Dynamically create nested level groups by properties in Javascript

Code

/**
 * Creates nested groups by object properties.
 * `properties` array nest from highest(index = 0) to lowest level.
 *
 * @param {String[]} properties
 * @returns {Object}
@dherges
dherges / lru-cache.ts
Last active May 26, 2023 04:39
Simple LRU Cache in TypeScript
class LruCache<T> {
private values: Map<string, T> = new Map<string, T>();
private maxEntries: number = 20;
public get(key: string): T {
const hasKey = this.values.has(key);
let entry: T;
if (hasKey) {
// peek the entry, re-insert for LRU strategy
@Ynote
Ynote / tail-call-optimization.js
Last active October 18, 2022 13:33
[Javascript] - Tail-recursive factorial function
// This is just a short reminder of this great explanation:
// http://www.2ality.com/2015/06/tail-call-optimization.html
// not TCO
function factorial(n) {
if (n <= 0) return 1;
return n * factorial(n-1); // here, the main recursive call not in a tail position because of the `n` context.
}
@oanhnn
oanhnn / using-multiple-github-accounts-with-ssh-keys.md
Last active July 2, 2024 19:37
Using multiple github accounts with ssh keys

Problem

I have two Github accounts: oanhnn (personal) and superman (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).

Solution

Use ssh keys and define host aliases in ssh config file (each alias for an account).

How to?

  1. Generate ssh key pairs for accounts and add them to GitHub accounts.
@DinkDonk
DinkDonk / setup.md
Last active January 16, 2024 00:22
Raspberrypi (raspbian) VPN passthrough.

This will set up a passthrough between the eth0 interface and the wan0 interface, with a VPN connection in-between.
You can then connect a machine to the ethernet port of the raspberrypi, and that machines network traffic will pass through the vpn tunnel on the raspberrypi.

The device connected to the ethernet plug of the PI should be set up with:

IP: 192.168.0.2
Mask: 255.255.255.0
Gateway: 192.168.0.1

Set up interfaces