Skip to content

Instantly share code, notes, and snippets.


Brandon Belvin PizzaBrandon

View GitHub Profile
ceejbot /
Last active July 14, 2022 21:45
npm's proposal for supporting ES modules in node

ESM modules in node: npm edition

The proposal you’re about to read is not just a proposal. We have a working implementation of almost everything we discussed here. We encourage you to checkout and build our branch: our fork, with the relevant branch selected. Building and using the implementation will give you a better understanding of what using it as a developer is like.

Our implementation ended up differing from the proposal on some minor points. As our last action item before making a PR, we’re writing documentation on what we did. While I loathe pointing to tests in lieu of documentation, they will be helpful until we complete writing docs: the unit tests.

This repo also contains a bundled version of npm that has a new command, asset. You can read the documentation for and goals of that comma

View simple-clustering.js
const cluster = require('cluster');
const childProcess = require('child_process');
const cpus = require('os').cpus().length;
const processes = cpus >= 2 ? cpus : 2;
console.log("Starting server processes");
for(var i = 0; i < processes; i++){
crittermike / App.js
Last active May 9, 2022 08:18
Using Google API (gapi) with React
View App.js
/* global gapi */
import React, { Component } from 'react';
class App extends Component {
loadYoutubeApi() {
const script = document.createElement("script");
ohanhi /
Last active February 3, 2021 18:14
The Joy of Composition - Why stateless rendering is pure bliss

This is a proposal for a lightning talk at the Reactive 2015 conference.

NOTE: If you like this, star the Gist - the amount of stars decides whether it makes the cut!

The Joy of Composition

Why stateless rendering is pure bliss

React just got stateless components, meaning that they are in essence pure functions for rendering. Pure functions make it dead simple - even fun - to refactor your views

View react-app-file-structure
├── actions
├── stores
├── views
│   ├── Anonymous
│   │   ├── __tests__
│   │   ├── views
│   │   │   ├── Home
│   │   │   │   ├── __tests__
│   │   │   │   └── Handler.js
wvengen /
Last active January 23, 2023 10:00
Extend non-HiDPI external display above HiDPI internal display
# extend non-HiDPI external display on DP* above HiDPI internal display eDP*
# see also
# you may run into
EXT=`xrandr --current | sed 's/^\(.*\) connected.*$/\1/p;d' | grep -v ^eDP | head -n 1`
INT=`xrandr --current | sed 's/^\(.*\) connected.*$/\1/p;d' | grep -v ^DP | head -n 1`
ext_w=`xrandr | sed 's/^'"${EXT}"' [^0-9]* \([0-9]\+\)x.*$/\1/p;d'`
anoved / star.scad
Created March 18, 2014 15:48
OpenSCAD pointed star module
View star.scad
// points = number of points (minimum 3)
// outer = radius to outer points
// inner = radius to inner points
module Star(points, outer, inner) {
// polar to cartesian: radius/angle to x/y
function x(r, a) = r * cos(a);
function y(r, a) = r * sin(a);
// angular width of each pie slice of the star
md55 / jquery.waituntilexists.js
Last active May 19, 2021 20:27 — forked from PizzaBrandon/jquery.waituntilexists.js
bugfix: if handler do waituntilexists() again with same selector then new IntervalId will replace old one in intervals array before removeListener() call. So new Interval will be cleared instead of old, and old Interval will never be cleared.
View jquery.waituntilexists.js
;(function ($, window) {
var intervals = {};
var removeListener = function(selector) {
if (intervals[selector]) {
intervals[selector] = null;
louy / .htaccess
Created July 25, 2013 22:31
Apache .htaccess geographical redirect based on CloudFlare's geo-ip headers
View .htaccess
# add as many as you need...
SetEnvIf CF-IPCountry SY RedirectSubdomain=syria
SetEnvIf CF-IPCountry AE RedirectSubdomain=uae
SetEnvIf CF-IPCountry EG RedirectSubdomain=egypt
# Only redirect if Host is not a subdomain
SetEnvIfNoCase Host ^.+\.example\.com$ !RedirectSubdomain
# Only redirect if cookie "noredirect" doesn't exist
SetEnvIfNoCase ^Cookie$ noredirect=true !RedirectSubdomain