Skip to content

Instantly share code, notes, and snippets.

View davidmc971's full-sized avatar
:octocat:

David Alexander Pfeiffer davidmc971

:octocat:
View GitHub Profile
@davidmc971
davidmc971 / crypto.js
Last active September 11, 2021 17:59
Compact utility for securely storing user passwords that are hashed using sha512 and a salt
/**
* @file A compact utility for securely storing user passwords
* that are hashed using sha512 and a salt.
* @author David Alexander Pfeiffer <david.pfeiffer971@gmail.com>
*/
import crypto from "crypto";
/**
* Hash password with sha512, generates and appends a new random salt.
* @function
@davidmc971
davidmc971 / config.yml
Created January 30, 2022 14:45
My Trafik 2 Setup using Let's Encrypt Wildcard Certificates with Cloudflare
# config.yml in traefik directory
# Dynamic Configuration for Dashboard
http:
routers:
dashboard:
# Your domain here
rule: Host(`traefik-dashboard.example.com`)
service: api@internal
middlewares:
- auth
@davidmc971
davidmc971 / App.js
Last active July 6, 2022 10:27
React: Store auth token in cookie (localStorage) and make it available through context
// file: App.js
// example usage
import { AuthContext } from './context/AuthContext';
import { useLocalStorage } from './hooks/useLocalStorage';
import SomeComponent from './components/SomeComponent';
export const App = () => {
const [storedValue, setValue] = useLocalStorage("authToken", null);
@davidmc971
davidmc971 / useMediaQuery.js
Created November 23, 2022 17:59
Custom media query hook in React
import { useEffect, useRef, useState } from "react";
const useMediaQuery = (minWidth, maxWidth) => {
const mediaQuery = "screen".concat(
minWidth !== undefined ? ` and (min-width: ${minWidth})` : "",
maxWidth !== undefined ? ` and (max-width: ${maxWidth})` : ""
);
const [matches, setMatches] = useState(window.matchMedia(mediaQuery).matches);