This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Aggregate keys of all objects in an array | |
jsonArrayData | jq '[.[] | keys] | flatten | unique' | |
# Map array to reduced objects and sort by a field | |
# Assumes array of {id, name, items:[]} | |
jsonArrayData | jq '[.[] | {id, name, itemCount:.items | length}] | sort_by(.itemCount)' | |
# Filter an array by matching property | |
jsonArrayData | jq '. [] | select(.id == "SomeId")' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
export interface SimpleContextType { | |
userName: string | undefined; | |
setUserName: (userName: string | undefined) => void; | |
} | |
export const SimpleContext = React.createContext<SimpleContextType>({ userName: undefined, setUserName: () => undefined }); | |
export const SimpleContextProvider = ({ children }: { children: React.ReactNode }): React.ReactElement => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state | |
function Counter() { | |
const [count, setCount] = useState(0); | |
const prevCountRef = useRef(); | |
useEffect(() => { | |
prevCountRef.current = count; | |
}); | |
const prevCount = prevCountRef.current; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To be placed in ~/.config/git/git-prompt.sh | |
# Will be picked up by git bash /etc/profile.d/git-prompt.sh as a custom configuration | |
PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]' # set window title | |
PS1="$PS1"'\n' # new line | |
PS1="$PS1"'\[\033[34m\]' # change to blue | |
PS1="$PS1"'[`date +%F_%T`] ' # date | |
PS1="$PS1"'\[\033[32m\]' # change to green | |
PS1="$PS1"'\u' # user | |
PS1="$PS1"'\[\033[95m\]' # change to purple | |
PS1="$PS1"'@\h ' # @host<space> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: https://www.benmvp.com/blog/filtering-undefined-elements-from-array-typescript/ | |
/* | |
* Let's say I have a list of MyObjects and I want to filter down to all of the contained MySubProperties. | |
* | |
* I need to filter out the objects with undefined property values since they cannot have a subproperty, and | |
* I need TypeScript to understand that the result type of that filter is MyProperty[] rather than | |
* (MyProperty | undefined)[] - that way, ts won't flag the access of p.subProperty for possibly undefined values. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From https://medium.com/@optalgo/use-dropbox-as-a-git-repo-96c0e6412549 | |
#Create and setup the Dropbox base repo | |
mkdir -p ~/Dropbox/Git | |
cd ~/Dropbox/Git | |
# Do the following for every project you want to add | |
git init --bare myProject.git | |
# Add Dropbox as a remote branch named "origin" | |
cd ~/myProject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To run a cmd command from git bash, prefix with "cmd //c" | |
cmd //c echo %PATH% | |
# I have experienced scenarios where I have custom batch files that are in my cmd | |
# path and I want to call them from Git Bash. | |
# To do this, alias the command names in ~/.bashrc to add the cmd prefix: | |
# .bashrc | |
alias search='cmd //c search' | |
alias explore='cmd //c explore' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const convertToTitleCase = (str) => { | |
return str | |
// Split on spaces | |
.split(' ') | |
// Capitalize the first letter of each word | |
.map((word) => | |
word.length > 0 | |
? word[0].toUpperCase() + word.substr(1).toLowerCase() | |
: word | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myList = [ | |
{ title: "First one", link: "https://en.wikipedia.org" }, | |
{ title: "Second One", link: "https://en.wikipedia.org" }, | |
{ title: "Actual First One", link: "https://en.wikipedia.org" }, | |
]; | |
// Sort the list by {each}.title, alphabetically | |
const sortedList = myList.sort((a, b) => (a.title > b.title ? 1 : -1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Use this to set up basic configuration for application logging. | |
Call this at the top in one file, then any following functions (even | |
in other files) can send log statements via the typical logging | |
functions (logging.info, logging.error, etc) | |
''' | |
# Set up logging | |
logging.basicConfig( | |
level=logging.DEBUG, |
NewerOlder