Skip to content

Instantly share code, notes, and snippets.

View davidsharp's full-sized avatar

David Sharp davidsharp

View GitHub Profile
@bennadel
bennadel / get-watch-count.js
Created November 28, 2014 13:26
Counting The Number Of Watchers In AngularJS - Updated For Isolate Scopes
// I return the count of watchers on the current page.
function getWatchCount() {
// Keep track of the total number of watch bindings on the page.
var total = 0;
// There are cases in which two different ng-scope markers will actually be referencing
// the same scope, such as with transclusion into an existing scope (ie, cloning a node
// and then linking it with an existing scope, not a new one). As such, we need to make
// sure that we don't double-count scopes.
@c3ry5
c3ry5 / json.fix.js
Created August 5, 2015 12:12
A fix for malformed json
JSON.fix = function(obj) {
return obj.replace(/(['"])?([a-zA-Z0-9_]+)(['"])?:/g, '"$2": ');
};
@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

"use strict";
var fragmentText = function(ctx, lines, index, maxWidth) {
var line = lines[index];
var nextLine;
var tooLong = true;
while (tooLong) {
var width = ctx.measureText(line.join(" ")).width;
@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'
@joelnet
joelnet / boolean-expressions-ski.js
Last active August 5, 2019 08:42
Boolean Logic with the SKI Combinators
// S and K are primitive function combinators.
const S = a => b => c => a (c) (b (c))
const K = a => b => a
// Non-primitive combinators can be created with S and K.
const C = S (S (K (S (K (S)) (K))) (S)) (K (K))
const I = S (K) (K)
const KI = K (I)
const M = S (I) (I)
const R = S (K (S (K (S)) (K))) (S (K (S (I))) (K))
@qubyte
qubyte / index.html
Created November 13, 2019 12:35
Conway's Game of Life. I put this together quickly as something to iterate on as a generative art project.
<!DOCTYPE html>
<html lang="en">
<head>
<script type="module" src="index.js"></script>
<title>Game of Life</title>
<meta charset="utf-8">
</head>
<body>
<h1>Game of Life</h1>
<canvas width="600" height="600"></canvas>
@clue
clue / 2018-05-17 introducing-ndjson-reactphp.md
Last active January 7, 2020 14:42
Introducing streaming newline-delimited JSON (NDJSON) with ReactPHP
@davidsharp
davidsharp / .dump.bash
Last active June 2, 2020 10:46
dot file dump functions and aliases for bash
# below is my prompt-y bit of choice: `current-dir ~ `
#export PS1="\[\e[33m\]\W \[\e[35m\]~ \[\e[m\]"
#export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007"'
# or something a little fancier: `current-dir <random fruit>`
#FRUITS=(🍎 🍐 🍊 🍋 🍌 🍉 🍇 🍓 🍒 🍑 🍍 🥝)
#export PS1="\[\e[33m\]\W \[\e[35m\]${FRUITS[$(echo $RANDOM%12 | bc)]} \[\e[m\]"
# for a new fruit on each line, rather than one per session
# export PROMPT_COMMAND='echo -ne "${FRUITS[$(echo $RANDOM%12 | bc)]} "'
# read this (if it's your .bash_profile)
@qubyte
qubyte / gyoza.md
Last active August 25, 2020 15:21

Miya's famous gyoza

Miya makes gyoza on the fly, and doesn't work to exact quantities. However, this recipe is what she used the last time we made some.

Step 1

For the first step you will need:

  • 3 cloves of garlic, finely diced or minced
  • 2 tbsp ginger, finely diced or minced