Skip to content

Instantly share code, notes, and snippets.

View davidsharp's full-sized avatar

David Sharp davidsharp

View GitHub Profile
@artyorsh
artyorsh / README.md
Last active June 21, 2023 16:36
Metro and Babel monorepo resolver functions

React Native Metro and Babel resolver functions for monorepo projects

Have you ever faced troubles when configuring a fresh react-native app to test your framework locally? These utility functions will help you to configure metro and babel to run your monorepo-structured framework and test it's modules without a need to publish them.

Simply copy and paste the files below into your project root and follow the guides explained in both of them.

See an Example project

@davidsharp
davidsharp / console-assignment-proxy.js
Created May 16, 2019 10:11
An ill-advised console.log proxy allowing logging via `console.log = 'someValue'` (which actually gains some nice features)
console=new Proxy(console,{set:(obj,prop,value)=>obj[prop](value)})
/*
Use like:
console.log = 'hello world'
logs -> 'hello world'
Unexpected bonus side-effect:
const foobar = console.log = 'hello world'
logs -> 'hello world'
@wybiral
wybiral / noscript-tracking.go
Last active September 11, 2023 08:53
Tracking cursor position in real-time with remote monitoring (without JavaScript)
// Tracking cursor position in real-time without JavaScript
// Demo: https://twitter.com/davywtf/status/1124146339259002881
package main
import (
"fmt"
"net/http"
"strings"
)
@uXeBoy
uXeBoy / NES-controller.ino
Last active January 15, 2024 12:41
NES-controller.ino
/* Quick and dirty NES to DMG button driver (originally by Mr.Blinky)
*
* Using digital pins so it can be easily run on any Arduino
* Because DigitalRead and DigitalWrite are pretty slow, no delays are
* required when changing controller pin states and reading in data
*/
//NES button state masks
#define BS_A _BV(7)
#define BS_B _BV(6)
@DavidKuennen
DavidKuennen / minimal-analytics-snippet.js
Last active March 28, 2024 01:45
Minimal Analytics Snippet
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
@matthargett
matthargett / ts-vs-flow.md
Created November 19, 2018 21:00
TypeScript versus flowtype

First, let's note the difference in philosophy: TypeScript aims for fast analysis because you can to compile it down to JS before you can run/test it. flowtype is meant to be an async analysis that can run continuously with changes since the last analysis, or in parallel with your eslint and bundler rules. As such, flowtype's type system and analysis is not quite as concerned with speed or memory usage in service of potentially finding more bugs.

On two occasions I have tried to roll out flow in React Native applications, and on those two occasions we ended up backing out after a few weeks. Some detail: flow doesn't have a public roadmap, and what version you use is dictated by the react/react-native dependency and the annotations in react-native itself. flowtype also has some hard-coded aspects to help the analysis for React, so major updates to React itself sometimes also require updating flowtype to match. React Native upgrades then get gated based on your dependent libraries (or flow-typed) being updated

@beesandbombs
beesandbombs / wavyHexagon.pde
Created November 18, 2018 19:11
wavy hexagon
int[][] result;
float t, c;
float ease(float p) {
return 3*p*p - 2*p*p*p;
}
float ease(float p, float g) {
if (p < 0.5)
return 0.5 * pow(2*p, g);
@SimonLarsen
SimonLarsen / galmetal_patterns.md
Last active December 20, 2020 00:37
Gal Metal drum patterns

Gal Metal drum patterns

Metal

EnterSand

|🔴⚪️⚪️⚪️|🔵⚪️⚪️⚪️|🔴⚪️⚪️⚪️|🔵⚪️⚪️⚪️|

Battery

@getify
getify / 1.md
Last active October 15, 2020 01:44
BetterPromise: a strawman experiment in subclassing Promise and "fixing" a bunch of its awkward/bad parts

Some things that are "better" with this BetterPromise implementation:

  • BetterPromise # then(..) accepts a BetterPromise (or Promise) instance passed directly, instead of requiring a function to return it, so that the promise is linked into the chain.

    var p = BetterPromise.resolve(42);
    
    var q = Promise.resolve(10);
    
    p.then(console.log).then(q).then(console.log);
@clue
clue / 2018-05-17 introducing-ndjson-reactphp.md
Last active January 7, 2020 14:42
Introducing streaming newline-delimited JSON (NDJSON) with ReactPHP