Skip to content

Instantly share code, notes, and snippets.

@kyleshevlin
kyleshevlin / memoizedHandlers.js
Created Jan 22, 2021
Using React.useMemo to create a `handlers` object
View memoizedHandlers.js
// One of my new favorite React Hook patternms is to create handler
// functions for a custom hook using `React.useMemo` instead of
// `React.useCallback`, like so:
function useBool(initialState = false) {
const [state, setState] = React.useState(initialState)
// Instead of individual React.useCallbacks gathered into an object
// Let's memoize the whole object. Then, we can destructure the
// methods we need in our consuming component.
@masyukun
masyukun / recipeTools.js
Last active Jan 3, 2021
JavaScript functions to work with exported Cronometer recipes
View recipeTools.js
/**
* Recipe Tools v0.1
*
* This version exists as a GitHub Gist at https://gist.github.com/masyukun/64a3490a464acaa3b9af6819f10dfbf4
*
* @license
* Copyright (c) 2020 Matthew Royal
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
View FetchedDogPictures.re
// This is a proper alternative to
// https://github.com/BuckleScript/bucklescript/blob/b9508105b1a35537bdea9a1fabd10f6c65f776b4/jscomp/bsb/templates/react-hooks/src/FetchedDogPictures/FetchedDogPictures.re#L14
// The one in that file uses Promise, but that's *wrong*.
// We only used promise as a demo of its API. We'll remove it soon.
// As you can see below, the pure XMLHttpRequest code is just as clean,
// less mysterious for all, more performant, extensible, and actually correct.
// Ignore these externals for now. They're just for illustration
// purposes. I just copy pasted the Js code from
View bashrc.sh
// by @noffle
autoinstall () {
local MODULES=$(cat $1 | grep "require('.*')" | sed "s/.*require('\(.*\)')/\1/" | grep -v '^\.' | tr '\n' ' ')
shift
shift
npm install $MODULES $@
}
@adrianhall
adrianhall / AppSyncAPI.yaml
Last active Nov 17, 2020
A CloudFormation template for DynamoDB + Cognito User Pool + AppSync API for the Notes tutorial
View AppSyncAPI.yaml
---
Description: AWS AppSync Notes API
Parameters:
APIName:
Type: String
Description: Name of the API - used to generate unique names for resources
MinLength: 3
MaxLength: 20
AllowedPattern: '^[a-zA-Z][a-zA-Z0-9_]*$'
@dylanmckay
dylanmckay / facebook-contact-info-summary.rb
Last active May 6, 2021
A Ruby script for collecting phone record statistics from a Facebook user data dump
View facebook-contact-info-summary.rb
#! /usr/bin/env ruby
# NOTE: Requires Ruby 2.1 or greater.
# This script can be used to parse and dump the information from
# the 'html/contact_info.htm' file in a Facebook user data ZIP download.
#
# It prints all cell phone call + SMS message + MMS records, plus a summary of each.
#
# It also dumps all of the records into CSV files inside a 'CSV' folder, that is created
@bahmutov
bahmutov / tmux.md
Last active Mar 31, 2017
tmux basics
View tmux.md

install

Install on Mac using brew install tmux and start with tmux

main commands

See help (list of commands) with Control-b ? key combination. Leave help view by pressing q key. From now on use Control-b (aka C-b) to start all tmux commands (C-b is called command prefix and can be changed, see tmux.config options).

@getify
getify / 1.js
Last active Oct 15, 2017
generators as object iterator
View 1.js
// ugly way
var obj = {
a: 1,
b: 2,
c: 3,
[Symbol.iterator]() {
var keys = Object.keys(this);
var idx = 0;
return {
@haveaguess
haveaguess / HSBC.js
Created Oct 8, 2016 — forked from benjie/HSBC.js
HSBC Personal Statement to CSV
View HSBC.js
/******************************
HSBC Personal Statement to CSV
v0.5
Copyright: Benjie Gillam (2012)
License: WTFPL v2.0 ( http://en.wikipedia.org/wiki/WTFPL )
Instructions:
Add the following bookmarklet to your browser:
@tomysmile
tomysmile / node-setup-pm2-nginx.md
Last active Mar 6, 2021
Setup NodeJS Production with PM2, Nginx in Ubuntu 16.04
View node-setup-pm2-nginx.md

How To Set Up a Node.js Application for Production on Ubuntu 16.04

with PM2 & Nginx

Create User

as a root, run below commands on server:

# adduser tomy