Skip to content

Instantly share code, notes, and snippets.

@naush
naush / delete-merged-branches.sh
Last active September 29, 2023 16:36
One liner for deleting merged git branches
git branch --merged | grep -v main | xargs -n 1 git branch -D
const Buttons = () => {
const { dispatch, } = React.useContext(DarumaContext);
return (
<>
<UndoIcon
onClick={() => dispatch({ type: Actions.UNDO })}
/>
<BrushIcon
onClick={() => dispatch({ type: Actions.PAINT })}
const Daruma = () => {
const { state, } = React.useContext(DarumaContext);
switch (state) {
case WishState.PENDING:
return <DarumaPending />;
case WishState.STARTED:
return <DarumaStarted />;
default:
return <DarumaFulfilled />;
type DarumaContextType = {
state: WishState,
dispatch: React.Dispatch<any>,
};
const DarumaContext = React.createContext({} as DarumaContextType);
const reducer = (state: WishState, action: any) => {
switch (action.type) {
case Actions.PAINT:
type ButtonsProps = {
dispatch: React.Dispatch<any>,
};
const Buttons = ({ dispatch, }: ButtonsProps) => {
return (
<>
<UndoIcon
onClick={() => dispatch({ type: Actions.UNDO })}
/>
enum Actions {
PAINT,
UNDO,
}
const reducer = (state: WishState, action: any) => {
switch (action.type) {
case Actions.PAINT:
return forward(state);
case Actions.UNDO:
const App = () => {
const [state, setState] = React.useState(WishState.PENDING);
return (
<>
<Daruma
state={state}
/>
<Buttons
paint={() => setState(forward(state))}
type ButtonsProps = {
paint: () => void,
undo: () => void,
};
const Buttons = ({
paint,
undo,
}: ButtonsProps) => {
return (
type DarumaProps = {
state: WishState,
};
const Daruma = ({
state,
}: DarumaProps) => {
switch (state) {
case WishState.PENDING:
return <DarumaPending />;
enum WishState {
PENDING = 1,
STARTED = 2,
FULFILLED = 3,
};
const forward = (state: WishState) => {
switch (state) {
case WishState.PENDING:
return WishState.STARTED;