Skip to content

Instantly share code, notes, and snippets.

View bryanberger's full-sized avatar
👨‍💻
always makin'

Bryan Berger bryanberger

👨‍💻
always makin'
View GitHub Profile
@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

@112RG
112RG / microservice.md
Created October 21, 2018 04:09
Discord bot. Microservice a love hate

Please read this gist by DasWolke it goes into a much better explanation of why you should use microservice Discord bots.

This is about my experience in making a microservice discord bot.

To start let's look at the core design I was looking for in creating my bot

(https://i.imgur.com/bWxXyc3.png)

I was looking to have multiple gateways that serve different shards groups this design could allow for a beta or premium version of the bot to be hosted on the same service more easily. I also wanted plug and play workers that don't store any information and could be restarted or crash without having any downtime and be scaled just by changing the replica value in docker swarm.

@JoelBesada
JoelBesada / sketch-loader.js
Created January 8, 2018 15:10
Webpack Sketch Loader
const JSZip = require('jszip')
const { parseBuffer } = require('bplist-parser')
const { isObject, each, find } = require('lodash')
const parseArchivedValue = value => {
return parseBuffer(new Buffer(value, 'base64'))
}
const parseArchivedString = obj => {
const { $objects } = parseArchivedValue(
@emoruzzi
emoruzzi / README.md
Last active March 29, 2022 20:10 — forked from Neilos/README.md
Bi-directional hierarchical sankey diagram

This is a demonstration of a bi-directional hierarchical sankey diagram produced in javascript, html and css using d3. (Refresh page to generate new random data)

Sankey diagrams represent flows between nodes by varying the thickness of the connecting links.

This diagram was based off of Mike Bostock's sankey diagram, but additionally incorporates bi-directionality into the flow and caters for hierarchical relationships between nodes to allow drill down into the data.

All javascript code to generate the diagram markup is contained in the app.js file, but the underlying calculations are performed using a custom plugin: bihisankey.js.

This version addresses the issue with double clicking. Demo: http://bl.ocks.org/emoruzzi/6f8140c4d903e64ae35dce0c971e488f

@wingrunr21
wingrunr21 / environment.js
Created October 2, 2017 19:43
Simple webpacker server side rendering
const webpack = require('webpack')
const { environment } = require('@rails/webpacker')
// Don't use commons chunk for server_side_render chunk
const entries = environment.toWebpackConfig().entry
const commonsChunkEligible = Object.keys(entries).filter(name => name !== 'server_side_render')
environment.plugins.set('CommonsChunkVendor', new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: (module, count) => {
@spacehuhn
spacehuhn / arduino_flash_esp8266.md
Last active January 16, 2024 18:14
Flash ESP8266 over an Arduino

How to flash your ESP8266 without a USB-Serial adapter but with an Arduino.

First be sure everything is connected correcly:

Arduino ESP82666
TX RX
RX TX
GND GND
GND GPIO-15
@anaisbetts
anaisbetts / stat-cache.js
Last active April 11, 2019 05:07
Make your Electron apps load faster, with this One Weird Trick
// Include this at the very top of both your main and window processes, so that
// it loads as soon as possible.
//
// Why does this work? The node.js module system calls fs.realpathSync a _lot_
// to load stuff, which in turn, has to call fs.lstatSync a _lot_. While you
// generally can't cache stat() results because they change behind your back
// (i.e. another program opens a file, then you stat it, the stats change),
// caching it for a very short period of time is :ok: :gem:. These effects are
// especially apparent on Windows, where stat() is far more expensive - stat()
// calls often take more time in the perf graph than actually evaluating the
@jherax
jherax / filterArray.js
Last active February 23, 2024 12:59
Filters an array of objects with multiple match-criteria.
/**
* Filters an array of objects using custom predicates.
*
* @param {Array} array: the array to filter
* @param {Object} filters: an object with the filter criteria
* @return {Array}
*/
function filterArray(array, filters) {
const filterKeys = Object.keys(filters);
return array.filter(item => {
@gbaman
gbaman / HowToOTGFast.md
Last active May 1, 2024 08:26
Simple guide for setting up OTG modes on the Raspberry Pi Zero, the fast way!

Setting up Pi Zero OTG - The quick way (No USB keyboard, mouse, HDMI monitor needed)

More details - http://blog.gbaman.info/?p=791

For this method, alongside your Pi Zero, MicroUSB cable and MicroSD card, only an additional computer is required, which can be running Windows (with Bonjour, iTunes or Quicktime installed), Mac OS or Linux (with Avahi Daemon installed, for example Ubuntu has it built in).
1. Flash Raspbian Jessie full or Raspbian Jessie Lite onto the SD card.
2. Once Raspbian is flashed, open up the boot partition (in Windows Explorer, Finder etc) and add to the bottom of the config.txt file dtoverlay=dwc2 on a new line, then save the file.
3. If using a recent release of Jessie (Dec 2016 onwards), then create a new file simply called ssh in the SD card as well. By default SSH i