Skip to content

Instantly share code, notes, and snippets.

View thinkjrs's full-sized avatar
🎯
Focusing

Jason R. Stevens, CFA thinkjrs

🎯
Focusing
View GitHub Profile
@thinkjrs
thinkjrs / python-date-range.md
Last active February 19, 2023 01:32
Date range in Python

Date Range in Python

This covers how to get a date range in Python using only standard library modules.

The code

"""
MIT LICENSED
(c) 2023 Jason R. Stevens, CFA
"""
@thinkjrs
thinkjrs / README.md
Created November 30, 2022 02:14 — forked from tomi/README.md
Saving and reading private key to env variables using base64

Encoding the private key as base64

  • Copy the private key to clipboard
  • Run command pbpaste | base64 | pbcopy on mac or xclip -selection clipboard -o | base64 -w 0 | xclip -selection clipboard on 'nix systems
  • The private key is now base64 encoded in the clipboard. Paste it to env variable e.g. to heroku or to .env file

Decoding the private key from base64 in node.js

const private_key = new Buffer(process.env.PRIVATE_KEY, 'base64').toString('ascii');
@thinkjrs
thinkjrs / git-index-permissions.md
Created November 12, 2022 22:22
Change the permissions of a file in a Git index.

From Github's documentation, the below demonstrates how-to explicitly change the permission mode of a file so that it doesn’t get reset every time there is a clone/fork.

git update-index --chmod=+x <filename>

For example, to give entrypoint.sh executable permissions:

@thinkjrs
thinkjrs / alt-ssh-copy-id.md
Created October 15, 2022 20:25 — forked from nickbayley/alt-ssh-copy-id.md
Simple Alternative to ssh-copy-id

Simple Alternative to ssh-copy-id

Replace user with the name of the user you want to ssh as.

Replace the ip with the ip of the machine / host / vps you want to connect to.

cat ~/.ssh/id_rsa.pub | ssh user@ip "cat >> ~/.ssh/authorized_keys"
@thinkjrs
thinkjrs / cloudinaryPayloadTypes.d.ts
Created October 8, 2022 14:02
Cloudinary TypeScript Payload Typing
type CloudinaryPayload = {
id: string;
batchId: string;
asset_id: string;
public_id: string;
version: number;
version_id: string;
signature: string;
width: number;
height: number;
@thinkjrs
thinkjrs / cookie-consent-implementation.md
Created August 30, 2022 18:01
A short how-to on how we implement react-cookie-consent at Tincre.
@thinkjrs
thinkjrs / flask_migrate_single_to_multidb.md
Created June 13, 2022 19:37
Flask-Migrate: Add multiple database setup to existing single database setup

Today we ran into an issue adding a multi-database setup to prior single-db setup. Here's how we fixed it and reference links.

What to do

From the maintainer of Flask-Migrate, Miguel Grinberg:

I was able to convert a single-db repository to multi-db with the following procedure:

  • backup everything just in case!
  • rename your migrations folder to something else (i.e. migrations-old)
@thinkjrs
thinkjrs / simple_testing_in_go.md
Created May 30, 2022 04:02
Writing tests in Go

"You write a test by creating a file with a name ending in _test.go that contains functions named TestXXX with signature func (t *testing.T). The test framework runs each such function; if the function calls a failure function such as t.Error or t.Fail, the test is considered to have failed."

📓 Reference: https://go.dev/doc/code.

Testing reverse.go

To test a file named reverse.go simply create a file named reverse_test.go in the package directory with the following content:

@thinkjrs
thinkjrs / remove_module_deps_go.md
Created May 29, 2022 14:22
Remove downloaded modules dependencies in Go

"To remove all downloaded modules, you can pass the -modcache flag to go clean:"

go clean -modcache

📓 Reference: https://go.dev/doc/code

@thinkjrs
thinkjrs / aws-s3-public-image-upload
Created April 10, 2022 01:33
Script to upload a local file to an s3 bucket as public returning the https route
#! /usr/bin/sh
# A simple script to upload the file given via the single input parameter
# via the full path to the file.
# This uses Python to grab the filename, since bash and other shell
# scripting languages are comparably unreadable.
bucket_name=<that-sexy-bucket-name-of-yours>
bucket=s3://$bucket_name/
input=$1
filename=$(python3 -c "print('$1'.split('/')[-1])")