Skip to content

Instantly share code, notes, and snippets.

@kwhinnery
kwhinnery / main.js
Last active October 21, 2022 16:05
const path = require('path');
const { app, BrowserWindow } = require('electron');
function createWindow() {
const win = new BrowserWindow({
width: 1280,
height: 720,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
namespace :solargraph do
task generate: :environment do
# Add the folder you choose in your config/application.rb
# example:
# config.autoload_paths << Rails.root.join('app/solargraph')
gen_directory = Rails.root.join("config", "yard")
# run the script as a rails runner:
# jundle exec rails r ./bin/generate_solar_models.rb
@bvaughn
bvaughn / index.md
Last active May 4, 2024 11:25
How to use profiling in production mode for react-dom

React recently introduced an experimental profiler API. This page gives instructions on how to use this API in a production release of your app.

Table of Contents

Profiling in production

React DOM automatically supports profiling in development mode for v16.5+, but since profiling adds some small additional overhead it is opt-in for production mode. This gist explains how to opt-in.

@kentcdodds
kentcdodds / create-required-context.js
Created May 15, 2018 22:31
create react context that has a validated consumer.
// create a React context Provider/Consumer pair that
// validates the consumer is rendered within a provider
function createRequiredContext(name) {
const Context = React.createContext()
function Consumer(props) {
return (
<Context.Consumer {...props}>
{val => {
if (!val) {
@leebyron
leebyron / PriorityQueue.js
Last active January 28, 2019 05:08
PriorityQueue.js uses a binary heap to ensure the highest priority item is always available to dequeue, and sorts on enqueue. A dynamically resizing Array can be used to model the binary heap, for a simpler and more efficient implementation.
/**
* For compare function return:
* - Less than zero: item1 has higher priority than item2.
* - Zero: same.
* - Greater than zero: item1 has lower priority than item2.
*/
export type CompareFunction<T> = (item1: T, item2: T) => number;
export class PriorityQueue<T> {
_items: Array<T>;
@danielalvarenga
danielalvarenga / puma.rb
Last active October 16, 2021 20:08
Puma config for rails 5 api
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
# More: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#threads
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
@ryanwilsonperkin
ryanwilsonperkin / convox_env_check.sh
Created December 20, 2017 16:22
Check all applications in a convox rack for environment variables (name or value) containing a search_query
rack=$1
search_query=$2
if [ -z "$rack" ] || [ -z "$search_query" ]; then
echo "usage: $0 rack search_query"
exit 1
fi
apps=$(convox apps --rack $rack | grep -v STATUS | cut -f1 -d' ')
// @flow
import {Component, type Node} from 'react'
import authenticatedApolloClient from '../shared/authenticatedApolloClient';
/**
* Example usage:
*
* const ScreenWithLoader = (props) => <ApolloWrapper
* queryOptions={{
@bojand
bojand / index.md
Last active March 1, 2024 19:32
gRPC and Load Balancing

Just documenting docs, articles, and discussion related to gRPC and load balancing.

https://github.com/grpc/grpc/blob/master/doc/load-balancing.md

Seems gRPC prefers thin client-side load balancing where a client gets a list of connected clients and a load balancing policy from a "load balancer" and then performs client-side load balancing based on the information. However, this could be useful for traditional load banaling approaches in clound deployments.

https://groups.google.com/forum/#!topic/grpc-io/8s7UHY_Q1po

gRPC "works" in AWS. That is, you can run gRPC services on EC2 nodes and have them connect to other nodes, and everything is fine. If you are using AWS for easy access to hardware then all is fine. What doesn't work is ELB (aka CLB), and ALBs. Neither of these support HTTP/2 (h2c) in a way that gRPC needs.

@anthonyclarka2
anthonyclarka2 / borg-backup-enhanced.sh
Created August 14, 2017 17:06
Borg backup script with exit code checking and status push to Zabbix
#!/bin/sh
# Enhanced backup script
# Sends messages to Zabbix based on exit code of borg executable
#
# anthonyclark AT G MAIL
# Shellcheck will still kvetch at you if notices are enabled
#
# This script will not work AS-IS but is only provided as such
# NO WARRANTIES
# This work is licensed under a Creative Commons Attribution 4.0 International License.