Skip to content

Instantly share code, notes, and snippets.

View buren's full-sized avatar

Jacob Burenstam Linder buren

View GitHub Profile
@buren
buren / Trans.tsx
Created August 25, 2023 14:43
Super minimalistic I18n lib in TypeScript.
import React, { ReactElement, ReactNode } from "react";
import { I18nKey, i18n } from "./i18n";
interface TransProps {
i18nKey: I18nKey;
text?: string;
[x: string]: ReactNode;
}
const Trans = ({ i18nKey, text, ...interpolationData }: TransProps) => {
@buren
buren / json_csv_converter.rb
Last active May 2, 2023 12:27
Flatten JSON to a two column CSV with defined separator and convert it back from CSV to JSON again. Useful for JSON I18n files amongst other things.
#!/usr/bin/env ruby
USAGE = <<~DOC
USAGE:
ruby json_csv_converter.rb <in_file> <separator(optional)>
EXAMPLES:
Convert JSON to CSV
$ ruby json_csv_converter.rb file.json
@buren
buren / hmac_sha256.js
Created November 6, 2022 11:00
HMAC SHA256
import crypto from 'crypto'
// inputs
const key = 'notsosecret'
const method = 'POST'
const url = 'https://example.com'
const timestamp = '2022-11-03T01:08:19.138Z'
const data = '{"data":{"partnerId":"1","tokenId":47210468}}'
// generate signature
@buren
buren / firebase-function-httpbin.ts
Created November 2, 2022 21:26
httpbin built with on a firebase function stored in firestore
import { firestore } from 'firebase-admin';
import * as functions from 'firebase-functions';
const region = 'europe-west1';
const firestoreCollection = 'webhook-posts';
export const httpBin = functions
.region(region)
.https.onRequest(async ({ headers, body }, response) => {
const data = { headers, body };
await firestore().collection(firestoreCollection).doc().create(data);
@buren
buren / index.ts
Created September 5, 2022 16:19
Recursively redact keys from object.
recursiveRedact({ a: 1, b: { a: 1, b: 2 } }, new Set(['a']))
// Result
// {
// "a": "[redacted]",
// "b": {
// "a": "[redacted]",
// "b": 2
// }
// }
# USAGE
# In any local GitHub repository run
# $ github_open
github_open() {
local remotename="${@:-origin}"
local remote="$(git remote -v | awk '/^'"$remotename"'.*\(push\)$/ {print $2}')"
[[ "$remote" ]] || return
local user_repo="$(echo "$remote" | perl -pe 's/.*://;s/\.git$//')"
open "https://github.com/$user_repo"
@buren
buren / snippets.cson
Created September 11, 2018 17:59
Atom snippet - Ruby method missing template
'.source.ruby':
'def method_missing .. end':
'prefix': 'defmm'
'body':
'''
def method_missing(method_name, *arguments, &block)
if ${1}.respond_to?(method_name)
${1}.public_send(method_name, *arguments, &block)
else
super
@buren
buren / check_redirect.rb
Created August 16, 2018 12:58
Given a CSV file with expected redirects - verify that each redirect is performed correctly.
#!/usr/bin/env ruby
# USAGE:
# $ check_redirects --help
# or
# $ ruby check_redirects.rb --help
require 'bundler/inline'
gemfile do
@buren
buren / snippets.cson
Created August 2, 2018 23:41
Atom snippet - Ruby gem configuration template
'.source.ruby':
'Insert gem configuration block':
'prefix': 'gconfig'
'body':
'''
def self.configuration
@configuration ||= Configuration.new
end
def self.config
@buren
buren / snippets.cson
Created August 1, 2018 17:23
Atom snippet - Ruby optparse template
'.source.ruby':
'Insert Ruby optparser':
'prefix': 'optparse'
'body':
'''
require 'optparse'
options = {}