Skip to content

Instantly share code, notes, and snippets.

Avatar

Furkan Tunalı JacopKane

View GitHub Profile
@masaeedu
masaeedu / nanoparsec.js
Last active Aug 6, 2018
Monadic parser combinators in JS
View nanoparsec.js
require("@babel/polyfill");
const {
adt,
_,
fail,
Maybe,
Fn,
Arr,
implement,
Chain,
View Validator.js
export const Validator = (value, props, ...customValidators) => (validators => validators.reduce((errors, validate) => [...errors, ...validate(value, props)], []))([
// Here the list of validators
(value, props) => typeof value !== 'string'
|| props.type !== 'email'
|| /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(value.toLowerCase()) ? [] : [{error: Errors.EMAIL}],
(value, props) => typeof value !== 'string'
|| typeof props.maxLength === 'undefined'
|| parseInt(props.maxLength) >= value.length ? [] : [{error: Errors.MAXLENGTH, length: parseInt(props.maxLength)}],
/**
* Other validators here
View challenge.md

Challenge

Write a function of type String -> Integer. The input may or may not be a valid JSON string. If it is valid, the resulting JavaScript value is expected to be an object, but may not be. If it is an object, it is expected to have a foo property whose value is expected to be an object, but may not be. This value is expected to have a bar property which is expected to be an object with a baz property whose value is expected to be an array of strings. Each of these strings is expected to be a hex representation of an integer (e.g. 0xFF). If every element of the array meets this expectation, the

@yangshun
yangshun / using-eslint-with-prettier.md
Last active Sep 15, 2021
Comparison between tools that allow you to use ESLint and Prettier together.
View using-eslint-with-prettier.md
prettier-eslint eslint-plugin-prettier eslint-config-prettier
What it is A JavaScript module exporting a single function. An ESLint plugin. An ESLint configuration.
What it does Runs the code (string) through prettier then eslint --fix. The output is also a string. Plugins usually contain implementations for additional rules that ESLint will check for. This plugin uses Prettier under the hood and will raise ESLint errors when your code differs from Prettier's expected output. This config turns off formatting-related rules that might conflict with Prettier, allowing you to use Prettier with other ESLint configs like eslint-config-airbnb.
How to use it Either calling the function in your code or via [prettier-eslint-cli](https://github.co
@hharnisc
hharnisc / index.js
Last active Nov 28, 2018
Webpack Dev Middleware (w/ Hot Module Replacement) served by `Micro`
View index.js
const fs = require('fs');
const webpack = require('webpack');
const { send } = require('micro');
const config = require('./webpack.config');
const webpackMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const compiler = webpack(config);
const middleware = (next) => {
const mw = webpackMiddleware(compiler, {
@Avaq
Avaq / ramda-sanctuary.md
Last active Mar 1, 2019
Comprehensive Ramda to Sanctuary list
View ramda-sanctuary.md
Ramda Sanctuary
add(a, b) add(b, a)
addIndex(f) ``
adjust(f, i, xs) ``
all(f, xs) ``
allPass(fs, x) allPass(fs, x)
always(x) K(x)
and(a, b) and(a, b)
any(f, x) ``
@jsonmaur
jsonmaur / bzexcluderules_editable.xml
Last active Aug 8, 2021
Backblaze Custom Exclude
View bzexcluderules_editable.xml
<excludefname_rule plat="mac" osVers="*" ruleIsOptional="t" skipFirstCharThenStartsWith="users/" contains_1="/.git/" contains_2="*" doesNotContain="*" endsWith="*" hasFileExtension="*" />
<excludefname_rule plat="mac" osVers="*" ruleIsOptional="t" skipFirstCharThenStartsWith="users/" contains_1="/node_modules/" contains_2="*" doesNotContain="*" endsWith="*" hasFileExtension="*" />
View do-stage-1.md

Motivation

  • expression-oriented programming one of the great advances of FP
  • expressions plug together like legos, making more malleable programming experience in-the-small

Examples

Write in an expression-oriented style, scoping variables as locally as possible:

@peterdemartini
peterdemartini / command.sh
Last active Aug 31, 2021
Exclude node_modules in timemachine
View command.sh
find `pwd` -type d -maxdepth 3 -name 'node_modules' | xargs -n 1 tmutil addexclusion
View lens7.js
const immLens = key => lens((x) => x.get(key), (val, x) => x.set(key, val))