Skip to content

Instantly share code, notes, and snippets.

View kalley's full-sized avatar

Kalley Powell kalley

  • OneSignal
  • Houston, TX
View GitHub Profile
@MarksCode
MarksCode / use-prompt.ts
Last active April 13, 2024 10:04
return `usePrompt` capabilities from react-router
/**
* Prompts a user when they exit the page
*/
import { useCallback, useContext, useEffect } from 'react';
import { UNSAFE_NavigationContext as NavigationContext } from 'react-router-dom';
function useConfirmExit(confirmExit: () => boolean, when = true) {
const { navigator } = useContext(NavigationContext);
@etienne-dldc
etienne-dldc / combineContext.js
Created March 28, 2018 18:38
A small function to combine react Contexts.
import React from 'react';
function onlyChild(children) {
return Array.isArray(children) ? children[0] : children;
}
export function combineContext(contexts) {
class Provider extends React.Component {
render() {
const init = this.props.children;
@laughinghan
laughinghan / MathSON.md
Last active December 7, 2023 21:52
MathSON - JSON for Math Formulae

MathSON

Status: Draft 1 In Progress. This document is undergoing its first revision. Initial implementation has begun alongside editing Draft 1. Your feedback is hoped and dreamed of.

Mathematical Structured Object Notation is a JSON-based representation for most of the common subset of what LaTeX and Presentation MathML can

@timgws
timgws / install-sleepwatcher-bluetooth-fix.sh
Last active November 1, 2018 17:44
Install sleepwatcher to restart bluetooth & friends
#!/bin/sh
brew install sleepwatcher
# https://gist.github.com/jagtesh/de81fa1c6b45fad0ff8e
sudo cp /usr/local/Cellar/sleepwatcher/2.2/de.bernhard-baehr.sleepwatcher-20compatibility.plist /Library/LaunchAgents/
sudo cp /usr/local/Cellar/sleepwatcher/2.2/etc/sleepwatcher/rc.* /etc/
# Add bluetooth script to /etc/rc.wakeup (the script requires root)
sudo tee -a /etc/rc.wakeup <<EOF

Folder Structure

Please note

While this gist has been shared and followed for years, I regret not giving more background. It was originally a gist for the engineering org I was in, not a "general suggestion" for any React app.

Typically I avoid folders altogether. Heck, I even avoid new files. If I can build an app with one 2000 line file I will. New files and folders are a pain.

#!/bin/bash
# Install sleepwatcher
cd /tmp
curl -O http://www.bernhard-baehr.de/sleepwatcher_2.2.tgz
tar -zxvf sleepwatcher_2.2.tgz
cd sleepwatcher_2.2
sudo mkdir -p /usr/local/sbin /usr/local/share/man/man8
sudo cp sleepwatcher /usr/local/sbin
sudo cp sleepwatcher.8 /usr/local/share/man/man8
sudo cp config/de.bernhard-baehr.sleepwatcher-20compatibility.plist /Library/LaunchAgents
# Install dependencies
#
# * checkinstall: package the .deb
# * libpcre3, libpcre3-dev: required for HTTP rewrite module
# * zlib1g zlib1g-dbg zlib1g-dev: required for HTTP gzip module
apt-get install checkinstall libpcre3 libpcre3-dev zlib1g zlib1g-dbg zlib1g-dev && \
mkdir -p ~/sources/ && \
# Compile against OpenSSL to enable NPN
@adityamenon
adityamenon / app.domainname
Last active December 28, 2021 06:31
My preferred configuration for a Laravel 4 API endpoint running over PHP-FPM, when I need to talk to it with AngularJS.
server {
root /path/to/app/public;
index index.php;
server_name test.dev;
set $cors_headers "whatever-custom-headers,you-would-like";
# redirection to index.php
location / {
try_files $uri $uri/ /index.php?$query_string;
@gre
gre / easing.js
Last active April 16, 2024 19:53
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
/*
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License, Version 2,
* as published by Sam Hocevar. See the COPYING file for more details.
*/
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
@mbostock
mbostock / .block
Last active November 14, 2023 03:46
Google Maps + D3
license: gpl-3.0