Skip to content

Instantly share code, notes, and snippets.

View princefishthrower's full-sized avatar
💭
codevideo.io 🎥

Chris Frewin princefishthrower

💭
codevideo.io 🎥
View GitHub Profile
@princefishthrower
princefishthrower / warn-bandwidth.ts
Created February 27, 2024 09:51
Netlify serverless function that sends a warning email / SMS if the bandwidth is close to the specified limits.
// This Netlify serverless function will send a warning email / SMS if the bandwidth is close to the specified limits.
// Many environment variables need to be set in order for this function to work:
// - MJ_API_KEY (Mailjet API key)
// - MJ_API_SECRET (Mailjet API secret)
// - SINCH_SERVICE_PLAN_ID (Sinch service plan ID)
// - SINCH_API_TOKEN (Sinch API token)
// - SINCH_NUMBER (Sinch phone number)
// - SINCH_TO_NUMBER (Sinch phone number to send the SMS to)
// - NETLIFY_ACCESS_TOKEN (Netlify access token) - generate one at https://app.netlify.com/sites/{your-site-name}/settings/general#access-control
// - NETLIFY_API_BANDWIDTH_URL (Netlify API bandwidth URL) - should have this pattern: https://api.netlify.com/access-control/bb-api/api/v1/accounts{your-account-id}/bandwidth
@princefishthrower
princefishthrower / export-source-from-docker-tag.sh
Last active December 4, 2023 19:13
Export the source code from any Docker tag!
#!/bin/bash
#
# Extracts the source code of any Docker tag!
# Inspired by Sambhav Jain's post on DEV: https://dev.to/sambhav2612/reverse-engineering-a-docker-image-i8c
# Simply pass:
# 1. The desired Docker image tag you want to get the source code for
# 2. The target folder to put the source code in
#
# Example usage:
# ./export-source-from-docker-tag.sh gcr.io/google-samples/gb-frontend:v4 docker-source
@princefishthrower
princefishthrower / OTPInput.tsx
Last active May 13, 2023 21:54
Simple OTP TextInput for React Native
import {useIsFocused} from '@react-navigation/native';
import * as React from 'react';
import {useRef} from 'react';
import {TextInput, View} from 'react-native';
import {isIOS} from '../../helpers/utils';
import {useTimeout} from '../../hooks/useTimeout';
export interface IOTPInputProps {
otpCodeChanged: (otpCode: string) => void;
}
@princefishthrower
princefishthrower / asshat.py
Created January 9, 2023 16:25
A 50 line script illustrating the ease of botnets to exploit spam on sites like substack.
# Best run with "scrapy runspider asshats.py --nolog" in your terminal
import time
import scrapy
from selenium import webdriver
# Variables needed - or, throw this garbage in a loop to produce ultimate ass-hattery
url = "https://somesubstackurl.substack.com/"
email = "someemail@gmail.com"
class MyAsshatSpider(scrapy.Spider):
@princefishthrower
princefishthrower / KeyboardShift.tsx
Last active October 6, 2022 21:01
A Keyboard Avoiding View for React Native in 2021
import React, { PropsWithChildren, useEffect, useState } from 'react';
import { Platform, Animated, Dimensions, Keyboard, KeyboardAvoidingView, StyleSheet, TextInput } from 'react-native';
import {useHeaderHeight} from '@react-navigation/elements';
import { useKeyboard } from '@react-native-community/hooks';
export default function KeyboardShift (props: PropsWithChildren<{}>) {
const { children } = props;
const [shift, setShift] = useState(new Animated.Value(0))
const keyboard = useKeyboard()
@princefishthrower
princefishthrower / KeyboardShiftUseEffectFixReactNatve66.tsx
Created October 28, 2021 19:43
Updated useEffect for KeyboardShift on React Native 0.66 and higher
const [didShowListener, setDidShowListener] = useState<EmitterSubscription | null>()
const [didHideListener, setDidHideListener] = useState<EmitterSubscription | null>()
useEffect(() => {
setDidShowListener(Keyboard.addListener('keyboardDidShow', handleKeyboardDidShow));
setDidHideListener(Keyboard.addListener('keyboardDidHide', handleKeyboardDidHide));
return () => {
if (didShowListener){
didShowListener.remove();
}
if (didHideListener) {
@princefishthrower
princefishthrower / KeyboardShiftUsage.tsx
Last active October 3, 2021 10:23
A basic boilerplate of how to use the KeyboardShift component.
import KeyboardShift from './KeyboardShift'
export default function YourCoolKeyboardScreen () {
// Other logic, variables, etc.
return (
<KeyboardShift>
{/* Screen components */}
</KeyboardShift>
@princefishthrower
princefishthrower / buildColorPrompt.sh
Created September 30, 2021 21:13
Transform your bash shell prompt into a letter-level alternating color kaleidoscope!
function buildColorPrompt() {
# I always like showing what directory I am in (special character "\w" in PS1) - store the equivalent in this 'directory' variable
directory=$(pwd)
# Modify these to whatever you'd like!
PROMPT_TEXT="awesome-shell-prompt-colors@awesome-machine [$directory] "
# Colors seperated by comma - acceptable values are:
# black, white, red, green, yellow, blue, magenta, cyan, light gray, light red, light green, light yellow, light blue, light magenta, light cyan
@princefishthrower
princefishthrower / buildColorPrompt.zsh
Created September 30, 2021 21:12
Transform your zsh shell prompt into a letter-level alternating color kaleidoscope!
function buildColorPrompt() {
# I always like showing what directory I am in
directory=$(pwd)
# Modify these to whatever you'd like!
PROMPT_TEXT="youruser@yourmachine [$directory]"
# Comma seperated colors - as many or as few as you'd like
PROMPT_COLORS="15"
@princefishthrower
princefishthrower / pipe.js
Last active June 1, 2021 09:36
pipe.js - execute as many functions as needed in series
// pipe.js - execute as many functions as needed in series
// from https://egghead.io/lessons/react-create-a-pipe-function-to-enable-function-composition
// usage:
// const addTwo = (a, b) => console.log(a + b);
// const addThree = (a, b, c) => console.log(a + b + c);
// pipe(addTwo(1, 2), addThree(3, 4, 5));
// 3
// 12
const combine = (f, g) => (...args) => g(f(...args));
export const pipe = (...fns) => fns.reduce(combine);