Skip to content

Instantly share code, notes, and snippets.

View nickdandakis's full-sized avatar
🙏
These hands make digital projects finish.

Nick Dandakis nickdandakis

🙏
These hands make digital projects finish.
View GitHub Profile
@nickdandakis
nickdandakis / WindowsWindowControls.jsx
Created March 16, 2018 23:10
Microsoft Windows window controls
import React, { Component } from 'react';
import _ from 'lodash';
import classnames from 'classnames';
import { remote } from 'electron';
class WindowsWindowControls extends Component {
state = {
fullscreen: false,
blur: false,
};
@nickdandakis
nickdandakis / MacOSWindowControls.jsx
Created March 16, 2018 23:10
Apple MacOS window controls
import React, { Component } from 'react';
import classnames from 'classnames';
const ALT = 18;
class MacOSWindowControls extends Component {
state = {
altKeyDown: false,
blurred: false,
fullscreen: false,
@nickdandakis
nickdandakis / ReCAPTCHA.jsx
Created June 2, 2019 21:09
A React component for Google's ReCAPTCHA
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class ReCAPTCHA extends Component {
static propTypes = {
sitekey: PropTypes.string.isRequired,
onVerify: PropTypes.func,
};
static defaultProps = {
@nickdandakis
nickdandakis / debounce.js
Last active September 15, 2020 20:41
Common utility functions and hooks when working in a React codebase
export default function debounce (fn, delay) {
let timeoutID = null;
return function (...args) {
clearTimeout(timeoutID);
timeoutID = setTimeout(() => {
fn.call(this, ...args);
}, delay);
};
};
@nickdandakis
nickdandakis / ModalPortal.jsx
Created September 17, 2020 20:18
A basic React Modal Portal
// Import dynamically without SSR, as this is expected to be rendered clientside only
// e.g. const ModalPortal = dynamic(() => import('~/shared/components/ModalPortal'), { ssr: false });
//
// Expects an empty div with id of `modal-portal-root` somewhere in the DOM
import React, { useRef, useEffect } from 'react';
import { createPortal } from 'react-dom';
function ModalPortal({ children }) {
const $modalPortalRoot = useRef();
@nickdandakis
nickdandakis / ksuid-browser-only.js
Last active July 25, 2023 19:06
zero dependency ksuid implementation
// KSUIDs should be 20 bytes: 4 for the timestamp and 16 for the payload
const TIMESTAMP_BYTES = 4;
const PAYLOAD_BYTES = 16;
const TOTAL_BYTES = TIMESTAMP_BYTES + PAYLOAD_BYTES;
function getCurrentTimestamp() {
// KSUID timestamps have a custom epoch that starts in 14e8
const CUSTOM_EPOCH_DIFF = 1_400_000_000;
const timestamp = Math.floor(Date.now() / 1000) - CUSTOM_EPOCH_DIFF;