It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.
// I'm suggesting we add a new "adopt X from <Y />" syntax to the JSX language | |
// it would de-sugar to render prop children, but look and read better than | |
// what we currently have. For example: | |
// 1. | |
// this sugar | |
function MyComponent(props) { | |
adopt foo from <Bar />; | |
return <div>{foo}</div>; | |
} |
Moved to https://github.com/ebidel/puppeteer-examples |
const Compose = ({ children = () => null, ...chain }) => { | |
const composedFn = Object.entries(chain).reduce( | |
(acc, [renderProp, renderFn]) => props => | |
renderFn(value => acc({ ...props, [renderProp]: value })), | |
children | |
); | |
return composedFn(); | |
}; |
function _confidence(ups, downs) { | |
var n = ups + downs; | |
if(n === 0) { | |
return 0; | |
} | |
var z = 1.281551565545; | |
var p = parseFloat(ups) / n; | |
var left = p + 1 / (2 * n) * z * z; |
import java.util.*; | |
import java.util.stream.*; | |
class Trie { | |
public char nodeChar; | |
public boolean isLeaf; | |
public List<String> safeNames; | |
public HashMap<Character, Trie> subtrie; | |
Trie(char nodeChar, boolean isLeaf) { |
State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?
There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.
Here I present a composable pattern for pure state machiness with effects,
//Basic autocomplete using a Trie | |
//The trie is really not efficient | |
//The words should be supplied in a dict.txt file. | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
typedef struct n { | |
struct n *subtrie[26]; |
// @author - {N.Md Faizaan} | |
// @email - {aulisius7[at]gmail[dot]com} | |
// @title - Converts decimal float to binary 32 format float | |
// @ref - https://en.wikipedia.org/wiki/Single-precision_floating-point_format | |
// @license - MIT | |
/** | |
* float2bin - Convert decimal number to binary32 format | |
* @param {input} - The number to be converted either in Number or String type | |
* @return {bin32float} - The binary32 representation |