Skip to content

Instantly share code, notes, and snippets.

@daveteu
daveteu / nodeJSbcrypt.js
Created May 18, 2020 15:46
Bcrypt with NodeJS
const bcrypt = require('bcrypt');
let passwordHash;
bcrypt.hash('passwordString', 10, function(err, hash) {
passwordHash = hash;
});
bcrypt.compare('differentpasswordString', passwordHash, function(err, res) {
if(res) {
console.log(res) //returns true
@daveteu
daveteu / midtext.js
Created August 27, 2020 05:56
Simple way to display text in the middle of 2 horizontal lines in Material-Ui
import { Grid, Divider, Typography } from '@material-ui/core'
//Could use makeStyles here but it's harder to understand
const MidText = ({text}) => {
return ( <div style={{ padding: '8px' }}>
<Grid container>
<Grid item style={{ flex: 1, display: 'flex', alignItems: 'center'}}>
<Divider style={{ flexGrow: 1 }}/>
</Grid>
@daveteu
daveteu / createPromise.js
Last active December 8, 2020 22:27
createPromise
const createPromise = () => {
let resolver;
return [ new Promise(( resolve, reject ) => {
resolver = resolve
}), resolver]
}
@daveteu
daveteu / useConfirm.js
Last active December 8, 2020 23:19
usePromise
import React, { useState } from 'react'
import { Grid, Dialog, DialogContent, DialogActions, Button } from '@material-ui/core'
const useConfirm = () => {
const [ open, setOpen ] = useState(false);
const [ resolver, setResolver ] = useState({ resolver: null })
const [ label, setLabel ] = useState('')
const DeleteWithUseConfirm = () => {
const [ getConfirmation, Confirmation ] = useConfirm()
const onDelete = async () => {
const status = await getConfirmation('Shall we have dinner together tonight?');
if (status) { //status = true
...We can now do the job of deleting
@daveteu
daveteu / tweet.js
Created June 4, 2021 06:58
Tweet Component
/*
* Credit to https://blog.maximeheckel.com/posts/static-tweets-with-mdx-nextjs/
*/
import { css } from '@emotion/react';
import { format } from 'date-fns';
import Image from 'next/image';
import { TransformedTweet } from 'types/tweet';
import { LikeIcon, ReplyIcon, RetweetIcon, TwitterLogo } from './Icons';
import {
@daveteu
daveteu / pre-push.sh
Last active July 17, 2021 14:54 — forked from vlucas/pre-push.sh
Prevent Pushes Directly to Master
#!/bin/bash
# @link https://gist.github.com/mattscilipoti/8424018
#
# Called by "git push" after it has checked the remote status,
# but before anything has been pushed.
#
# If this script exits with a non-zero status nothing will be pushed.
#
# Steps to install, from the root directory of your repo...
@daveteu
daveteu / electron_submenu_notshowing.html
Last active January 4, 2022 02:00
SubMenu Not working
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<link href="./styles.css" rel="stylesheet">
<title>Hello World!</title>
</head>
<body>
@daveteu
daveteu / keysUndefined
Last active January 6, 2022 04:47
Find undefine keys in plain object
/**
* @param {object} obj plain object with { key: value }
* @param {array} keysToCheck List of keys to check for undefined values e.g. ['a','b','c']
* @example
*
* const obj = { a: undefined, b: 1, c: 2, d: undefined }
*
* console.log(keysUndefined(obj))
* returns ['a','d' ]
**/
@daveteu
daveteu / go-ssh-reverse-tunnel.go
Created June 10, 2022 10:37 — forked from codref/go-ssh-reverse-tunnel.go
Go SSH reverse tunnel implementation (SSH -R)
/*
Go-Language implementation of an SSH Reverse Tunnel, the equivalent of below SSH command:
ssh -R 8080:127.0.0.1:8080 operatore@146.148.22.123
which opens a tunnel between the two endpoints and permit to exchange information on this direction:
server:8080 -----> client:8080