Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
💻 🤓 💻

Chris Frewin princefishthrower

💭
💻 🤓 💻
View GitHub Profile
@princefishthrower
princefishthrower / export-source-from-docker-tag.sh
Last active Jun 5, 2022
Export the source code from any Docker tag!
View export-source-from-docker-tag.sh
#!/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 / KeyboardShiftUseEffectFixReactNatve66.tsx
Created Oct 28, 2021
Updated useEffect for KeyboardShift on React Native 0.66 and higher
View KeyboardShiftUseEffectFixReactNatve66.tsx
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 / buildColorPrompt.sh
Created Sep 30, 2021
Transform your bash shell prompt into a letter-level alternating color kaleidoscope!
View buildColorPrompt.sh
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 Sep 30, 2021
Transform your zsh shell prompt into a letter-level alternating color kaleidoscope!
View buildColorPrompt.zsh
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 / KeyboardShiftUsage.tsx
Last active Oct 3, 2021
A basic boilerplate of how to use the KeyboardShift component.
View KeyboardShiftUsage.tsx
import KeyboardShift from './KeyboardShift'
export default function YourCoolKeyboardScreen () {
// Other logic, variables, etc.
return (
<KeyboardShift>
{/* Screen components */}
</KeyboardShift>
@princefishthrower
princefishthrower / KeyboardShift.tsx
Last active Oct 28, 2021
A Keyboard Avoiding View for React Native in 2021
View KeyboardShift.tsx
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 / usePleaseStay.ts
Created Apr 26, 2021
A React hook that will animate the document title and / or favicon!
View usePleaseStay.ts
import { useEffect, useRef, useState } from 'react';
import { getFavicon } from '../../helpers/getFavicon';
import { AnimationType } from '../../enums/AnimationType';
import { UsePleaseStayOptions } from '../../types/UsePleaseStayOptions';
import { useInterval } from '../useInterval';
export const usePleaseStay = ({
titles,
animationType = AnimationType.LOOP,
interval = 1000,
@princefishthrower
princefishthrower / ExampleUsage.cs
Created Mar 26, 2021
Dynamic Where Expressions With EF Core
View ExampleUsage.cs
public List<AppParkingOrderModel> GetHourlyIntersectedBookingsByFacility(string facilityName)
{
var searchCriteria = new List<Expression<Func<AppParkingOrderModel, bool>>>();
var now = DateTime.Now;
var yearFromNow = now.AddYears(1).Year;
var startDateTime = new DateTime(now.Year, 1, 1, 0, 0, 0);
var endDateTime = new DateTime(yearFromNow, 1, 1, 0, 0, 0);
var hours = (endDateTime - startDateTime).TotalHours;
View pipelines-8.yml
pipelines:
branches:
staging:
- step:
name: Copy Staging Environment (.env.staging.json) to .env.json
script:
- cp /src/env/.env.staging.json /src/env/.env.json
- curl -X POST -H 'Content-type: application/json' --data '{"text":"Staging environment copied into environment!"}' YOUR_WEBHOOK_URL_HERE
master:
- step:
View pipelines-7.yml
pipelines:
branches:
staging:
- step:
name: Copy Staging Environment (.env.staging.json) to .env.json
script:
- cp /src/env/.env.staging.json /src/env/.env.json
<<<rest of install, build, SCP, SSH scripts and commands>>>
master:
- step: