Skip to content

Instantly share code, notes, and snippets.

@bitsapien
bitsapien / NeovimLangConfiguration.md
Created June 7, 2023 19:49
Neovim Language Configuration

Assumptions

  1. Package Manager: Lazy
  2. LSP Package Manager: Mason
  3. Language Parser: Treesitter

Elixir

  • Search Mason registry for elixir-ls
  • Add elixir, heex, eex to the languages supported for treesitter.
@bitsapien
bitsapien / withCache.js
Last active April 5, 2021 13:55
Caching is fun ! A higher order function to add caching on your pure function.
/**
* @typedef {Object} CacheResponse
* @property {any} data - The value that you a general call would return.
* @property {Object} cache - The cache store merged with the current function call.
*/
/**
* Caching function or memoizer that uses a custom hashing key algo.
* @param {function} fn - Pure function whose value you want to cache.
@bitsapien
bitsapien / ShareSecrets.md
Last active February 6, 2021 05:20
Share Secrets

Share secrets

Share your secrets securely over the wire.

Generate public key

Ask the person who'd recieve your secret to do the following, ask them to create a public/private key pair if they do not already have one.

curl -s https://gist.githubusercontent.com/bitsapien/bbc8cb877984f4ad5141dea0163072ba/raw/gen_pub_key.sh | bash /dev/stdin <PATH-TO-PRIVATE-KEY>
@bitsapien
bitsapien / logger.js
Last active January 30, 2021 02:26
node-logger : May serve as an alternative to winstonjs
/*
* ======================================================
* node-logger: A simple logger for nodejs
* ======================================================
*
* Motivation: I noticed a logging library like winstonjs
* could add almost 200KBs to my bundle size (un-gzipped)
* for doing something as simple as this 👇🏽
*/
commit=$(curl -s http://whatthecommit.com/ | sed "34q;d"); echo ${commit:3};
@bitsapien
bitsapien / resume.json
Last active May 26, 2023 22:14
resume.json
{
"meta": {
"theme": "onepage"
},
"basics": {
"name": "Rahul Chinta",
"label": "Software Engineer",
"image": "https://en.gravatar.com/userimage/95688745/3eae14f7c9d381287aeb609fd5177be3.png",
"website": "https://blog.bitsapien.dev",
"email": "bitsapien@gmail.com",
#!/usr/bin/env node
const jwtDecode = (jwt) => console.log(Buffer.from((process.argv.slice(2)[0]).split(".")[1], "base64").toString("utf-8"));
jwt = process.argv.slice(2)[0]
jwtDecode(jwt)
@bitsapien
bitsapien / jwtDecode.js
Last active August 28, 2020 19:02
Single line JWT decoder
exports.jwtDecode = jwtToken =>
JSON.parse(Buffer.from(jwtToken.split(".")[1], "base64").toString("utf-8"));
/* Usage:
* jwtDecode('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c');
* => {
* "sub": "1234567890",
* "name": "John Doe",
* "iat": 1516239022
* }
@bitsapien
bitsapien / render.js
Last active September 1, 2020 09:33
Single line templating engine
/*
* Problem: When you want to do very basic templating with very little to no logic, for example templating a mail or an HTML.
*/
const render = (templateData, templateHTML) =>
Object.entries(templateData).reduce(
(renderedContent, dataVar) =>
renderedContent.replace(new RegExp(`{{${dataVar[0]}}}`, 'g'), dataVar[1]),
templateHTML
);
class Life < ApplicationRecord
RACES = [
"Time Lord",
"Earthling",
"Dalek"
]
# constants for easy access, the race_key method is not available in this context
RACES.each do |race|
const_set(race_key(race), race)