Skip to content

Instantly share code, notes, and snippets.

View arabold's full-sized avatar
🦀
Making things. Breaking things.

Andre Rabold arabold

🦀
Making things. Breaking things.
View GitHub Profile
@arabold
arabold / fix-glue-table-schema.py
Created August 24, 2023 20:35
Fix Glue Table Schema
View fix-glue-table-schema.py
import boto3
boto3.setup_default_session(region_name="eu-central-1")
def make_partitions_inherit_datatypes_of_table(database_name, table_name):
glue_client = boto3.client("glue")
# Get the data types of the base table
table_response = glue_client.get_table(
DatabaseName=database_name,
@arabold
arabold / PythonOfflineFix.js
Created October 6, 2022 15:15
Run Serverless Offline and Serverless Python Requirements together
View PythonOfflineFix.js
#!/usr/bin/env node
"use strict";
const path = require("path");
const fs = require("fs");
/**
* Custom Serverless plugin to fix an issue with Serverless Offline not resolving the requirements
* path of the Serverless Python Requirements plugin.
@arabold
arabold / serverless.yml
Created August 17, 2022 15:36
Serverless Cognito Setup
View serverless.yml
service: auth
frameworkVersion: "3"
provider:
name: aws
runtime: nodejs16.x
stage: ${opt:stage, 'dev'}
region: ${opt:region, 'us-east-1'}
timeout: 300
@arabold
arabold / useDataStoreQuery.tsx
Last active February 23, 2023 18:07
Simplify querying the Amplify DataStore using React hooks
View useDataStoreQuery.tsx
import {
DataStore,
PersistentModel,
PersistentModelConstructor,
ProducerModelPredicate,
SortPredicate,
ProducerPaginationInput
} from '@aws-amplify/datastore'
import { useCallback, useEffect, useState } from 'react'
View How To Clean React Native Project.md

Add the following scripts to package.json:

    "clean": "npm run clean:git && npm run clean:npm && npm run clean:tmp && npm run clean:android && npm run clean:ios",
    "clean:android": "cd android && rimraf .gradle build && (./gradlew clean --continue || true) && cd ..",
    "clean:git": "git clean -fdX",
    "clean:ios": "cd ios && xcodebuild clean -quiet && rimraf Pods && pod cache clean && pod deintegrate && cd ..",
    "clean:npm": "rimraf node_modules && npm cache clean --force",
    "clean:tmp": "watchman watch-del-all && rimraf '$TMPDIR/react-native-packager-cache-*' && rm -fr '$TMPDIR/metro-cache' && rm -fr '$TMPDIR/haste-map-*'"
View Semaphore.ts
export type SemaphoreFunction = (done: () => void) => void;
/**
* Based on https://www.derpturkey.com/simple-semaphore-in-nodejs/
*/
export default class Semaphore {
readonly max: number;
private _fns: Array<SemaphoreFunction>;
private _active: number;
View createSimpleLogger.ts
export function createSimpleLogger(asJson: boolean): LogHandlerFunc {
return function log(logEntry) {
console.log(asJson ? JSON.stringify(logEntry) : logEntry);
};
}
View createSimpleLogger.ts
export function createSimpleLogger(): LogHandlerFunc {
return function log(logEntry) {
console.log(logEntry);
};
}
View logger-globalmetadata.ts
/** Metadata shared between all instances of the Logger */
private static _globalMetaData?: Payload;
static setGlobalMeta(meta: Payload): void {
Logger._globalMetaData = { ...meta };
}
View createBrowserLogger.ts
/** Log to Browser Console; Use colorful logs for Chome, Safari, etc. */
export function createBrowserLogger(): LogHandlerFunc {
return function log({ level, message, payload, meta }: LogEntry) {
const logFunc = ConsoleLogFuncs[level];
if (payload && typeof console.groupCollapsed === "function") {
console.groupCollapsed(`%c[${meta?.tag}] %c${message}`, "color:magenta;", "color:black;font-weight:normal");
logFunc(payload);
console.groupEnd();
} else if (payload) {
logFunc(`%c[${meta?.tag}] %c${message}`, "color:magenta;", "color:black;", payload);