Skip to content

Instantly share code, notes, and snippets.

Avatar

Valde Waltari10

View GitHub Profile
View component.js
...
const [henchmenState, dispatchHenchmen] = useReducer(henchmenReducer, initialHenchmenState);
...
const handleHenchmanChange = useCallback((henchman, id) => {
// handle modifying henchmen in reducer
dispatchHenchmen({
View useState.js
...
const [henchmen, setHenchmen] = useState({});
...
const handleHenchmanChange = useCallback((henchman, id) => {
setHenchmen({
...henchmen,
[id]: henchman,
View useDispatch.js
const handleHenchmanChange = useCallback((henchman, id) => {
dispatchHenchmen({
type: actions.UPDATE,
payload: {
id,
henchman,
},
});
}, [dispatchHenchmen]);
View useDispatch.js
const addHenchman = useCallback(id => {
dispatchHenchmen({
type: actions.ADD,
payload: id,
});
}, [dispatchHenchmen]);
View brackets problem
def isLeft(bracket):
if bracket == "(":
return True
if bracket == "[":
return True
if bracket == "{":
return True
return False
View asd.js
const heroLevelArr = [
2,
4,
6,
8,
11,
14,
17,
20,
24,
@Waltari10
Waltari10 / objectDestructure.ts
Created Apr 3, 2020
How to define types when using object destructuring:
View objectDestructure.ts
function toJSON(
value: any,
{ pretty }: { pretty: boolean }
) {
const indent = pretty ? 4 : 0;
return JSON.stringify(value, null, indent);
}
View Dockerfile
# Get Nginx image from Docker hub
FROM nginx
# Copy our configuration file to a folder in our Docker image where Nginx will use it
COPY default.conf.template /etc/nginx/conf.d/default.conf.template
# Configure Nginx for Heroku
CMD /bin/bash -c "envsubst '\$PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf" && nginx -g 'daemon off;'
# Update available packages in Debian
RUN apt-get update
# Install curl cmd line tool
RUN apt-get install curl -y
View js
componentDidUpdate() {
if (this.state.members === '' || this.state.members === undefined) {
this.props.fetchHousingGovernmentMembers();
}
if (this.state.members !== this.props.members) {
this.setState({ members: this.props.members });
}
View start.js
// exec allows us to run cmd commands in code
const { exec } = require('child_process');
// process.env.PORT is defined by Heroku environment. Use 3200 as fallback if outside of Heroku.
const port = process.env.PORT || 3200;
console.log('Port: ' + port)
const cmdStr = `.\\node_modules\\.bin\\serve -l ${ port} ./build`
console.log(cmdStr)