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 / 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;
@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 / 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 / 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 / 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 / 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 / package.json
Last active April 11, 2019 10:44
Next.js + AWS Elastic Beanstalk + AWS EC2 Container Service + Docker package.json
{
"name": "this-web-scale",
"version": "0.0.1",
"scripts": {
"dev": "node server.js",
"build": "NODE_ENV=production next build",
"start": "NODE_ENV=production node server.js",
"dockerize": "npm run build:docker && npm run tag:docker && npm run push:docker && npm run tag-latest:docker && npm run push-latest:docker",
"deploy": "eb use this-web-scale-production && eb deploy --label v$npm_package_version --verbose",
"build:docker": "docker build -t $npm_package_config_docker_image:$npm_package_version -t $npm_package_config_docker_image:latest .",
@nickdandakis
nickdandakis / config.yml
Last active November 13, 2019 06:11
AWS Elastic Beanstalk configuration with Dockerrun.aws.json deployment artifact
branch-defaults:
develop:
environment: this-web-scale-production
deploy:
artifact: Dockerrun.aws.json
environment-defaults:
this-web-scale-production:
branch: null
repository: null
global:
@nickdandakis
nickdandakis / package.json
Created October 14, 2017 18:21
Next.js + AWS Elastic Beanstalk + AWS EC2 Container Service + Docker package.json
{
"name": "this-web-scale",
"version": "x.x.x",
"scripts": {
"dev": "node server.js",
"build": "NODE_ENV=production next build",
"start": "NODE_ENV=production node server.js",
"dockerize": "npm run build:docker && npm run tag:docker && npm run push:docker && npm run tag-latest:docker && npm run push-latest:docker",
"deploy": "npm run deploy:staging",
"deploy:staging": "eb use token-staging && eb deploy --label v$npm_package_version --verbose",
@nickdandakis
nickdandakis / package.json
Created October 14, 2017 18:16
Next.js + Docker + AWS Elastic Beanstalk + AWS Elastic Container Service package.json
{
"name": "this-web-scale",
"version": "x.x.x",
"scripts": {
"dev": "node server.js",
"build": "NODE_ENV=production next build",
"start": "NODE_ENV=production node server.js",
"dockerize": "npm run build:docker && npm run tag:docker && npm run push:docker && npm run tag-latest:docker && npm run push-latest:docker",
"deploy": "npm run deploy:staging",
"deploy:staging": "eb use token-staging && eb deploy --label v$npm_package_version --verbose",