Skip to content

Instantly share code, notes, and snippets.

View AlexFrazer's full-sized avatar
🦊
🦊🦊🦊

Frazer AlexFrazer

🦊
🦊🦊🦊
View GitHub Profile
# Setting PATH for Python 3 installed by brew
export PATH=$(brew --prefix python3):$(brew --prefix virtualenv):$PATH
# Configuration for virtualenv
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=$(brew --prefix python3)/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=$(brew --prefix virtualenv)/bin/virtualenv
source $(brew --prefix virtualenvwrapper)/bin/virtualenvwrapper.sh
interface State {
// whatever state you want here
}
type Action = { type: "CHANGE" } | { type: "RESET" };
function reducer(state: State, action: Action) {
const initialState = { ...state };
switch (action.type) {
case "CHANGE":
@AlexFrazer
AlexFrazer / destructure-props.js
Created May 11, 2023 20:37
Restructure props
module.exports = function (fileInfo, api) {
const j = api.jscodeshift;
return j(fileInfo.source)
.find(j.FunctionDeclaration)
.forEach((path) => {
const params = path.value.params;
if (params.length === 1 && params[0].type === "Identifier" && params[0].name === "props") {
const propsParam = params[0];
const propsUsages = j(path).find(j.Identifier, { name: "props" });
@AlexFrazer
AlexFrazer / change-prop-value.js
Created May 11, 2023 15:26
Changes a prop value to a new prop value
// change-prop-value.js
const j = require('jscodeshift');
module.exports = function (fileInfo, api) {
const componentName = 'MyComponent'; // Replace with your component name
const propName = 'myProp'; // Replace with the prop name you want to change
const newValue = 'newValue'; // Replace with the new value for the prop
const root = j(fileInfo.source);
const fetchMachine = Machine({
id: 'Form Wizard',
initial: 'pending',
context: {
retries: 0
},
states: {
pending: {
initial: 'email',
states: {
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@AlexFrazer
AlexFrazer / machine.js
Created September 2, 2020 23:12
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine({
id: "fetch",
initial: "idle",
context: {
data: null,
error: null,
lastRequest: -Infinity
},
states: {
idle: {
@AlexFrazer
AlexFrazer / machine.js
Created September 2, 2020 22:50
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@AlexFrazer
AlexFrazer / machine.js
Last active September 2, 2020 21:52
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
module.exports = {
red: {
'100': '#FFBDBD',
'200': '#FF9B9B',
'300': '#F86A6A',
'400': '#EF4E4E',
'500': '#E12D39',
'600': '#CF1124',
'700': '#AB091E',
'800': '#8A041A',