Skip to content

Instantly share code, notes, and snippets.

@astoilkov
astoilkov / readme.md
Last active March 13, 2024 10:19
Async Operations with useReducer Hook

Async Operations with useReducer Hook

9 March, 2019

We were discussing with @erusev what we can do with async operation when using useReducer() in our application. Our app is simple and we don't want to use a state management library. All our requirements are satisfied with using one root useReducer(). The problem we are facing and don't know how to solve is async operations.

In a discussion with Dan Abramov he recommends Solution 3 but points out that things are fresh with hooks and there could be better ways of handling the problem.

Problem

@stevenharman
stevenharman / 00_Heroku-Release-Phase-Review-Apps-Rails_README.md
Last active March 11, 2024 04:11
Heroku Release Phase script for managing Rails DB migrations, and playing nice with Review Apps and postdeploy scripts

Heroku Release Phase + Review Apps + Rails

This is a simplified, but fairly thorough, set of scripts and configuration to enable Heroku Release Phase for Rails apps. Further, this particular set up plays nicely with Heroku Review Apps in that the release phase script will:

  1. Fail, loudly, if the DB does not yet exist.
  2. Load the DB schema if the current schema version (as determined by bin/rails db:version) is 0.
  3. Run DB migrations otherwise.

For a "normal" app that usually means it will run the DB migrations.

@kozo002
kozo002 / jquery.brightness.js
Created October 3, 2013 07:38
Get brightness from background color with jQuery
jQuery.fn.brightness = function() {
var bg_color, rgba, y;
bg_color = this.css('background-color');
if ((bg_color != null) && bg_color.length) {
rgba = bg_color.match(/^rgb(?:a)?\(([0-9]{1,3}),\s([0-9]{1,3}),\s([0-9]{1,3})(?:,\s)?([0-9]{1,3})?\)$/);
if (rgba != null) {
if (rgba[4] === '0') {
if (this.parent().length) return this.parent().brightness();
} else {
y = 2.99 * rgba[1] + 5.87 * rgba[2] + 1.14 * rgba[3];
@grncdr
grncdr / 00-Readme.md
Last active March 3, 2023 05:57
Delete unused assets

Delete unused assets

This is an example script for deleting assets that aren't linked in your content model. It does this by walking through all assets and checking for any links back to them.

WARNING: This script does not take into account assets that are only linked inside of Text fields. If you primarily embed images directly using the markdown editor, this will very likely delete assets you depend on.

You must fill in your own CMA access token & space ID at the top before running

Usage

@amirrajan
amirrajan / main.rb
Last active September 30, 2020 19:02
DragonRuby collision and physics
def tick args
# initialization
args.state.x ||= 620
args.state.y ||= 700
args.state.dy ||= 0
args.state.dx ||= 25
args.state.gravity = -0.5
args.state.drag_coeff = 0.05
args.state.walls = [
[0, 0, 1280, 100],
@st0012
st0012 / taipei_list.md
Last active July 27, 2019 15:45
Things to visit in Taipei

Places to go

  • Taipei 101
  • Tamsui
  • National Palace Museum
  • Shi-men Ting

Nigh markets

  • Tonghua Night Market - my favorite
    • There are some great bars nearby!
@shwaydogg
shwaydogg / letsEncryptModulus.md
Last active July 17, 2016 07:09
LetsEncrypt for Modulus Standalone Cetificate only Process

SETUP (nothing new here, it's from the docs)

On another server you control:

$ git clone https://github.com/letsencrypt/letsencrypt

$ cd letsencrypt

$ ./letsencrypt-auto

@svallory
svallory / extract_clone_all_script.js
Last active December 12, 2015 04:58
Generate shell script to clone all your repositories, or a configured subset of them from your GitHub Dashboard.
// Instructions:
// 1. Navigate to you GitHub dashboard, either (https://github.com or https://github.com/organizations/{org_name}
// 2. Click on "All repositories" or "Show N more repositories" to show all your repos
// 3. Open Firebug console, and paste this script. Optionally, change the options below
// 4. Run and have fun
var options = {
origin: "all", // can be: source, fork or all
visibility: "all", // can be: public, private or all
showInNewWindow: true

Wizard Island 2012

We will be camping Friday and Saturday night at sites 87 & 88 on Lake George's Long Island, one of the southernmost islands 4.41 miles by kayak from the Village.

Date Friday September 21st - Sunday September 22nd

Cost $98/person

Limit 8 wizards

@croaky
croaky / HOW_TO.md
Created March 16, 2012 05:43 — forked from michaeldauria/gist:2048022
Migrate from Copycopter 1.0 (hosted by thoughtbot) to Copycopter 2.0 (open source, deploy your own instance)

Use the latest version of the copycopter_client gem:

gem 'copycopter_client', '2.0.0'

Export your published drafts from copycopter.com:

RAILS_ENV=production bundle exec rake copycopter:export

This will create a config/locales/copycopter.yml file.