Skip to content

Instantly share code, notes, and snippets.

View pingfengafei's full-sized avatar

pingfengafei pingfengafei

View GitHub Profile
@mauricedb
mauricedb / Subject under test
Last active December 7, 2023 14:46
Testing stateful React hooks
import { useState } from 'react';
export function useCounter(initial = 0) {
const [count, setCount] = useState(initial);
return [count, () => setCount(count + 1)];
}
var noop = () => {}
var compose = (f1, f2) => (...args) => f1(f2(...args))
var range = (start, end) => {
let n = start
let f = (next, complete) => {
if (n <= end) {
next(n++)
f(next, complete)
} else {
complete()
@TeWu
TeWu / lambda_factorial.js
Last active May 30, 2024 20:03
Factorial function in lambda calculus - implemented in JS
///
/// Factorial function in lambda calculus - implemented in JS
///
//// Lambda calculus
// zero = λs.λz.z
// succ = λn.λs.λz.s (n s z)
// mult = λn.λm.λs.m (n s)
// pred = λn.λf.λx.n(λg.λh.h (g f))(λu.x)(λu.u)
// minus = λn.λm.m pred n
@klein0r
klein0r / script.js
Created October 9, 2015 18:54
GPS Navigation (Codewars)
function navigate(nmbrInt, roads, from, to) {
const getRoad = (from, to, roads) => roads.filter((e) => e.from == from && e.to == to)[0];
const getIntersections = (roads) => roads.reduce((r, e) => r.concat([e.from, e.to]), []).filter((e, i, a) => a.indexOf(e) === i);
const permutator = function(inputArr, from, to) {
var r = [];
var permute = function(arr, memo) {
var cur, memo = memo || [];
for (var i = 0; i < arr.length; i++) {
cur = arr.splice(i, 1);
@PurpleBooth
PurpleBooth / README-Template.md
Last active June 10, 2024 06:12
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@staltz
staltz / introrx.md
Last active June 7, 2024 23:39
The introduction to Reactive Programming you've been missing