Skip to content

Instantly share code, notes, and snippets.

View josefaidt's full-sized avatar
🦉

josef josefaidt

🦉
View GitHub Profile
@josefaidt
josefaidt / post-checkout
Created November 9, 2021 21:16
Git post-checkout hook to change AWS Amplify environments upon branch checkout
#!/bin/bash
# .git/hooks/post-checkout
# Utility to change AWS Amplify environments on branch checkout
# helper to get path to aws-exports.js
function get_aws_exports_path {
local AMPLIFY_PROJECT_CONFIG_PATH="amplify/.config/project-config.json"
local AMPLIFY_EXPORTS_PATH=$(jq -r '.javascript.config.SourceDir' $AMPLIFY_PROJECT_CONFIG_PATH)
if [[ "$AMPLIFY_EXPORTS_PATH" == */ ]]
// src/pages/_app.js
import { Amplify, Auth } from 'aws-amplify'
import {
AmplifyAuthenticator,
AmplifySignUp,
AmplifySignIn,
AmplifySignOut,
} from '@aws-amplify/ui-react'
import config from '../aws-exports.js'
@josefaidt
josefaidt / binary-gap.js
Created July 30, 2020 17:13
find the longest binary gap from an integer input
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
return parseInt(N >>> 0).toString(2).split('1').reduce((acc, value, index, self) => value.length > acc ? (typeof self[index + 1] === 'string' ? value.length : acc) : acc, 0)
}
@josefaidt
josefaidt / parseWorkbook.js
Created July 13, 2020 19:58
parse xlsx workbook
const xlsx = require('xlsx')
module.exports = function parseWorkbook(file) {
const result = {}
console.info(`Parsing workbook ${file}`)
const wb = xlsx.readFile(file)
if (!wb.SheetNames.length) throw new Error('Invalid workbook, no sheets available.')
const extractDataWithHeaders = (data = {}) => {
const result = []
function _create_react_component
if test (count $argv) -lt 1
read -l -P "Name of component? " component
_create_react_component $component
else
set cmp $argv[1]
mkdir -p components/$cmp
echo "
import React from 'react'
import styles from './$cmp.module.css'
#!/usr/bin/env node
const { existsSync: exists, promises: fs } = require('fs');
const { spawn } = require('child_process');
const path = require('path');
const c = require('chalk');
const dotenv = require('dotenv');
const nodemon = require('nodemon');
// set default node_env
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
@josefaidt
josefaidt / fs-router.js
Last active April 6, 2020 19:04
basic express filesystem router
import fs from 'fs';
import path from 'path';
import express from 'express';
const getFileRoutes = async ({ directory, ignore = /_/, include = /\.js$/ }) => {
const result = new Map();
const nestedGetFiles = async nestedDirectory => {
const files = fs.readdirSync(nestedDirectory, { withFileTypes: true });
for (let i = 0; i < files.length; i++) {
const f = files[i];
@josefaidt
josefaidt / now-swap-teams.js
Created March 28, 2020 15:09
Utility file to hot-swap ZEIT Now config files between multiple teams (personal and team)
//
// utility to swap ZEIT Now configs
// unable to scope deploys to dev (team) with git enabled
//
// /.now
// |- now.swap.json
// |- project.json
// |- project.personal.json
// |- project.team.json
//
@josefaidt
josefaidt / github-graphql-file-contents.graphql
Created January 10, 2020 00:26
Gets file contents from a repository folder
{
repository(name: "josefaidt.github.io", owner: "josefaidt") {
folder: object(expression: "master:app/content/pages") {
... on Tree {
entries {
oid
object {
... on Blob {
text
}
@josefaidt
josefaidt / lavandula.yml
Last active June 17, 2019 20:28
Lavandula terminal theme for Alacritty, ported to support the MacBook Pro sRGB corrections
# Lavandula
colors:
# Default colors
primary:
background: '0x040112'
foreground: '0x726f7c'
# Normal colors
normal:
black: '0x1e0543'