Skip to content

Instantly share code, notes, and snippets.

View timc1's full-sized avatar

Tim timc1

View GitHub Profile
@timc1
timc1 / useTheme2.tsx
Created April 18, 2020 20:10
🌑☀️core app system/light/dark mode theming + varying themes for nested components
import * as React from "react";
type ThemeConfig = "system" | "light" | "dark";
type ThemeName = "light" | "dark";
// Custom themes are keyed by a unique id.
type KeyedThemes = {
[k: string]: {
config: ThemeConfig;
themeName: ThemeName;
};
@timc1
timc1 / use-auth.js
Created June 10, 2019 00:20
React Context + Hooks + Firebase Authentication
import React from 'react'
import firebaseConfig from '../path/to/firebase-config'
import firebase from 'firebase/app'
import 'firebase/auth'
import FullPageLoading from '../path/to/full-page-loading'
AuthProvider.actions = {
setUser: 'SET_USER',
toggleLoading: 'TOGGLE_LOADING',
}
@timc1
timc1 / use-dropzone.tsx
Last active May 8, 2024 21:46
A React hook that returns whether a file is being dragged into the document from the operating system and not from within the browser.
import React from 'react'
type DropzoneContextValue = {
isDragging: boolean
}
const DropzoneContext = React.createContext<DropzoneContextValue | undefined>(
undefined
)
import React from "react";
function isMobile() {
if (typeof document !== `undefined`) {
return "ontouchstart" in document.documentElement === true;
}
return false;
}
const mobile = isMobile();
@timc1
timc1 / freeze-window.js
Created April 24, 2019 02:15
Prevent overflow scrolling — nice to use when displaying a modal
const capturePosition = () => {
const cachedPosition = window.pageYOffset
return {
freeze: () => {
document.body.style =
`position: fixed;
top: ${cachedPosition * -1}px;
width: 100%;`
},
unfreeze: () => {
@timc1
timc1 / renew-certbot.txt
Last active January 19, 2024 19:11
Renew certbot certificate on an nginx server
// Turn off server
sudo service nginx stop
// Renew certbot
certbot-auto renew —debug
// If failed, run this, then rerun renew command
sudo /opt/eff.org/certbot/venv/local/bin/pip install cryptography interface
// If failed
@timc1
timc1 / recursive-remove-attributes.js
Created January 26, 2019 21:55
removes all attributes from a dom node and its children
// recursively remove all attributes from a node and all its children
const recursiveRemove = node => {
removeAttributes(node)
while (node.childNodes.length > 0) {
for (let child of node.childNodes) {
node = child
if (node.nodeName !== 'IMG') {
recursiveRemove(child)
}
}
@timc1
timc1 / .vimrc
Last active February 15, 2019 17:27
set nocompatible
set encoding=utf-8 nobomb
filetype off
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" Vundle manages Vundle 😀
Plugin 'VundleVim/Vundle.vim'