Skip to content

Instantly share code, notes, and snippets.

View ncrmro's full-sized avatar
🦁

Nicholas Romero ncrmro

🦁
View GitHub Profile
@ncrmro
ncrmro / github-actions-k8-account.sh
Last active August 4, 2023 23:56
Generate Kubernetes KUBECONFIG with user that can only access a single namespace.
# https://computingforgeeks.com/restrict-kubernetes-service-account-users-to-a-namespace-with-rbac/?expand_article=1
# If you want to expose a diffrent port rather than 6443 we can port forward using UFW
# ufw route allow to 0.0.0.0 port 6443 from 0.0.0.0 port 42544
# sudo iptables -A PREROUTING -t nat -i enp1s0 -p tcp --dport 44394 -j REDIRECT --to-port 6443
export NAMESPACE=nextjs-sqlite
export K8S_USER="github-actions"
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Namespace
import React from "react";
import { UserAddressInput } from "~/graphql-types";
import TextField from "~/components/TextField";
interface AddressState extends UserAddressInput {
isPrimary: boolean;
}
export const useAddressState = () =>
React.useReducer(fieldReducer, {

SQL Trigger to Create Function

CREATE OR REPLACE FUNCTION app_private.tg__user_stripe_customer_sync() RETURNS trigger AS
$$
DECLARE
    stripe_customer app_private.stripe_customers;
BEGIN
    SELECT *
    INTO stripe_customer
@ncrmro
ncrmro / postgraphile-cred-secrets.sh
Created December 31, 2021 14:04
Generate the required secrets and init script for using postgraphile in kubernetes.
NAMESPACE=jtx-staging
DATABASE_NAME=jtx
DATABASE_ROOT_PASSWORD=$(openssl rand -hex 32)
DATABASE_OWNER=${DATABASE_NAME}_owner
DATABASE_OWNER_PASSWORD=$(openssl rand -hex 32)
DATABASE_AUTHENTICATOR=${DATABASE_NAME}_authenticator
DATABASE_AUTHENTICATOR_PASSWORD=$(openssl rand -hex 32)

Keybase proof

I hereby claim:

  • I am ncrmro on github.
  • I am ncrmro (https://keybase.io/ncrmro) on keybase.
  • I have a public key ASCTq5JbMHeIz1ym_uEodPpipL1QD57IcH0cbVs6oKdT1Qo

To claim this, I am signing this object:

@ncrmro
ncrmro / regex
Last active December 2, 2020 21:51
// URL with country, language, path and query (could remove the country and language easly enough
((?<protocol>https?)?(:\/\/)?(?<host>[^\/]*\.[^\/]*))?(\/(?<country>\w{2})?\/(?<language>\w{2}))?(?<path>\/[^?]*)?(?<query>\?.*)?
ssh_authorized_keys:
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILz8pN4JIWGXt2zZlj4qIrxgXtF6Nc2O06MAazcSj3hm ncrmro-workstation-22-07-2020
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA4cFS7p6Dkh1Aj60scG7qrTAJufD65b5YYGLabgpnEX ncrmro-laptop
@ncrmro
ncrmro / gist:57af8b1e361660af618a3fb968eac0ba
Created June 26, 2020 23:20
Unlock Encrypted Root Disk using dropper with auto find IP on MAC address
artul() {
MAC_ADDRESS=94:c6:91:ae:53:fc
NETWORK=192.168.1
echo Attempting to find IP address of host to unlock with MAC address $MAC_ADDRESS on $NETWORK.0
IP_ADDRESS=`for ((i=1; i<=255; i++));do arp $NETWORK.$i; done | grep $MAC_ADDRESS | awk '{print $2}' | sed -e 's/(//' -e 's/)//'`
echo Found IP address: $IP_ADDRESS
ssh root@$IP_ADDRESS -p 22 -i ~/.ssh/id_rsa
}
@ncrmro
ncrmro / deploy.sh
Created June 15, 2020 17:49
A script to build and copy binary to remote host (pi in this case) only if src is changed and then run said binary.
#!/bin/sh
set -e
## Current folder name
PROJECT_NAME=${PWD##*/}
DEPLOY_HOST=pi
DEPLOY_USER=pi
CHECKSUM_FILE=target/checksum
from django.contrib.postgres.search import TrigramSimilarity
from parts.models import Part
def trigram_similarity_search(similarity=0.3, search_string=""):
parts = Part.objects
parts = parts.annotate(similarity=TrigramSimilarity('name', search_string))
parts = parts.filter(similarity__gt=similarity).order_by('-similarity')