Skip to content

Instantly share code, notes, and snippets.

View JacopKane's full-sized avatar

Furkan Tunalı JacopKane

View GitHub Profile
@DrBoolean
DrBoolean / lens7.js
Created January 21, 2016 17:29
Lens7
const immLens = key => lens((x) => x.get(key), (val, x) => x.set(key, val))
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
@masaeedu
masaeedu / nanoparsec.js
Last active August 6, 2018 13:55
Monadic parser combinators in JS
require("@babel/polyfill");
const {
adt,
_,
fail,
Maybe,
Fn,
Arr,
implement,
Chain,
@hharnisc
hharnisc / index.js
Last active November 28, 2018 06:27
Webpack Dev Middleware (w/ Hot Module Replacement) served by `Micro`
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 March 1, 2019 00:26
Comprehensive Ramda to Sanctuary list
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) ``
@colinharman
colinharman / Alfred+ScreenSharing+AppleScript+MountainLion.scpt
Created August 6, 2012 02:33
Alfred + Screen Sharing + AppleScript + Mountain Lion = Winning
tell application "Screen Sharing"
activate
tell application "Screen Sharing"
activate
tell application "System Events"
keystroke "osx-mini.local" -- "osx.mini.local" would need to be replaced by "YourComputerName or IP Address"
keystroke return
end tell
@jamesmusgrave
jamesmusgrave / _smart-underline.scss
Last active September 24, 2019 17:57
Smart Underline Sass Mixin
@mixin smart-underline($background: #fff, $text: #000, $selection: #ffc, $position: 86%){
a {
color: inherit;
text-decoration: none;
background: -webkit-linear-gradient($background, $background), -webkit-linear-gradient($background, $background), -webkit-linear-gradient($text, $text);
background-size: .05em 1px, .05em 1px, 1px 1px;
background-repeat: no-repeat, no-repeat, repeat-x;
text-shadow: 0.03em 0 $background, -0.03em 0 $background, 0 0.03em $background, 0 -0.03em $background, 0.06em 0 $background, -0.06em 0 $background, 0.09em 0 $background, -0.09em 0 $background, 0.12em 0 $background, -0.12em 0 $background, 0.15em 0 $background, -0.15em 0 $background;
background-position-y: $position,$position, $position;
background-position-x: 0%, 100%, 0%;

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

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:

@schmunk42
schmunk42 / autogenerate-packages.php
Created October 8, 2012 16:27
Test-script to auto-generate packages.json from github API
<?php
// get all repos from yiiext
$response = file_get_contents("https://api.github.com/orgs/yiiext/repos");
$repos = json_decode($response);
#var_dump($repos);
// get versions/tags
$satis = array();
foreach($repos AS $num => $repo) {