Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# Install the dependencies:
#
# brew install pipx
# pipx install graphql-schema-diff
#
# Example usage:
# λ › ./schemacheck.sh src/schema/schema.graphqls
#!/usr/bin/env python3
import argparse
import os
class Config:
local: str
dev: str
tst: str
wus: str
import toolz.dicttoolz as dz
class Dictz(dict):
"""Wrapper class of dict injected with dicttoolz
## Rational ##
Using several dicttoolz funcs in a row can be cumbersome
For Example:

Properly manage Java versions in macOS

After spending hours reading half baked or old medium articles explaining how to setup java in macOS, I made an updated version that covers what I think are the best tricks.

1. uninstall all existing jdk releases (if any)

AdoptOpenJdk

# remove any versions. autocomplete should help
@franciscoafonsoo
franciscoafonsoo / unpack_data_classes.kt
Last active June 28, 2022 19:19
Convert a dataclass into another (very similar) dataclass. This can be useful for usecases like you would use unpack in Python, or to make simple changes to an existing object for backwards compatibility. Uses https://kotlinlang.org/docs/reflection.html
// Heavly based on this post. All credits to the author.
// https://www.bezkoder.com/kotlin-convert-object-data-class-to-another/
// build.gradle.kt
implementation("org.jetbrains.kotlin:kotlin-reflect:1.6.0")
// file.kt
import kotlin.reflect.full.memberProperties
data class Customer(
@franciscoafonsoo
franciscoafonsoo / strip_var_envs.py
Last active February 13, 2020 13:34
Matches all environment variables with a certain prefix. Returns a dict with the key of the variable without the prefix. Use case: filtering certain variables for using in the a CI system.
def strip_var_envs(prefix):
"""
Matches all environment variables with a certain prefix.
Returns a dict with the key of the variable without the prefix.
Example:
env vars:
- CI_API_KEY=key
- CI_URL=https://httpbin.org
- BASE_URL=https://example.com
@franciscoafonsoo
franciscoafonsoo / restore_heroku_db.sh
Last active January 16, 2020 17:39
PosgreSQL: Restore from an Heroku app to a local posgresql DB
function restore_db_heroku() {
: ${1?"Usage: $1 Heroku app; $2 Local DB"}
echo "Capturing a new backup and downloading..."
echo ""
heroku pg:backups:capture -a $1
heroku pg:backups:download -a $1
mv latest.dump "${1}_latest.dump"
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U sherby -d $2 "${1}_latest.dump"
echo ""
@franciscoafonsoo
franciscoafonsoo / django_get_all_fields.py
Created November 20, 2019 13:42
utilities to return all fields and values from Django Model objects
def get_all_fields(obj):
"""
return a {field:value} dict for a Django Model object
lambda equivelent. useful for pasting in idle
list_fields = lambda obj: {f.name: getattr(obj, f.name) for f in obj._meta.fields}
"""
return {f.name: getattr(obj, f.name) for f in obj._meta.fields}