Skip to content

Instantly share code, notes, and snippets.

@nkhil
nkhil / SUBREDDIT_LIST.md
Created July 8, 2025 11:11 — forked from timvisee/SUBREDDIT_LIST.md
Get a list of subreddits you're subscribed to on reddit. https://timvisee.com/blog/list-export-your-subreddits/

As posted on: https://timvisee.com/blog/list-export-your-subreddits/

Get a list of your subreddits

To obtain a list of your subreddits, do the following:

  • First make sure you're logged in on reddit, on a desktop browser.
  • Then visit reddit.com/subreddits.
  • Then put the following snippet in your browsers address bar, and press Enter.
    Make sure javascript: is included at the beginning, your browser might remove it while copy-pasting for security reasons:
@nkhil
nkhil / script.md
Created April 20, 2023 11:13
Parse a csv file in node without additional dependencies

Parse a CSV file in node without dependencies

We're going to parse a file, use a conditional to add a new column, then save the new file with an additional column all without using any external dependencies not included in the standard lib

const fs = require('fs');

const inputCsvFile = 'input.csv';
const outputCsvFile = 'output.csv';

Custom Karabiner rule to toggle W/A/S/D as arrow keys

The following rule re-maps the capslock key so it toggles on W/A/S/D becoming arrow keys.

{
  "global": {
    "check_for_updates_on_startup": true,
    "show_in_menu_bar": true,
    "show_profile_name_in_menu_bar": false,
@nkhil
nkhil / symmetric-decryption-nodejs.md
Created June 6, 2022 20:27
Symmetric decryption using nodejs
import never from 'never'
type ParsedLogs = Array<[string, string]>
type GroupedLogs = {
[K: string]: Array<string>
}
export default function main(logs: string) {
const parsedLogs = parseAndNormaliseLogs(logs)
function parseLogs(logs) {
const logsArray = logs.split('\n').map(eachLog => eachLog.split(','))
const normalisedArray = normaliseArray(logsArray)
const logsWithSeconds = normalisedArray.map(([timestamp, phoneNumber]) =>
[calculateTotalSeconds(timestamp), phoneNumber])
const grouped = groupByPhoneNumber(logsWithSeconds)
const phoneNumberWithLargestTotal = getPhoneNumberWithLargestTotalSeconds(grouped)
grouped[phoneNumberWithLargestTotal] = 0
return calculateTotalBill(logsWithSeconds, phoneNumberWithLargestTotal)
}
const crypto = require('crypto')
const fs = require('fs')
const encryptedData = fs.readFileSync('encrypted_data.txt', { encoding: 'utf-8' })
const privateKey = fs.readFileSync('private.pem', { encoding: 'utf-8' })
const decryptedData = crypto.privateDecrypt(
{
key: privateKey,
// In order to decrypt the data, we need to specify the
const fs = require('fs')
const crypto = require('crypto')
const dataToEncrypt = fs.readFileSync('data_to_encrypt.txt', { encoding: 'utf-8' })
const publicKey = Buffer.from(fs.readFileSync('public.pem', { encoding: 'utf-8' }))
const encryptedData = crypto.publicEncrypt(
{
key: publicKey,
const crypto = require('crypto')
const fs = require('fs')
const { publicKey, privateKey } = crypto.generateKeyPairSync("rsa", {
// The standard secure default length for RSA keys is 2048 bits
modulusLength: 2048,
})
// *********************************************************************
//
const crypto = require('crypto')
const NUMBER_OF_BYTES = 32
const randomBytes = crypto.randomBytes(NUMBER_OF_BYTES)