This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def vowels "aeiou") | |
(defn is-vowel [ch] (not (nil? (some #{ch} vowels)))) | |
(defn abs [n] (max n (- n))) | |
(defn distance | |
"Returns the distance from the number x to the closest number in xs" | |
[xs x] | |
(apply min (map (fn [y] (abs (- y x))) xs))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<title>Hello</title> | |
<p>The following search field depends on Javascript, so let's render it with Javascript: | |
<template data-autorender="true"> | |
<form> | |
<input type="search"> | |
</form> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$record = $model->fetchById(42); // return Maybe(Record) | |
$related = $record->map(function ($record) { | |
// If this function is executed, record is definitely available, no need to check. | |
return $otherModel->fetchWhere('foreign_key', $record->id); | |
}); | |
// It's still a Maybe after mapping, so you can continue mapping on the value. | |
// If the first fetchById call got you a Nothing, this is still the same | |
// Nothing, but your code doesn't need to know, it can be written |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWS_ACCESS_KEY_ID= | |
AWS_SECRET_ACCESS_KEY= | |
AWS_REGION= | |
AWS_S3_BUCKET= | |
AWS_BUCKET_WEBSITE_URL= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function middle_char(string $str): string { | |
return strlen($str) <= 2 | |
? $str | |
: middle_char(substr($str, 1, -1)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use PHPUnit\Framework\TestCase; | |
class MyTest extends TestCase { | |
/** | |
* @dataProvider invalidArgumentProvider | |
* @expectedException InvalidArgumentException | |
*/ | |
public function test_should_throw_on_invalid_arguments($arg) { | |
my_func($arg); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { pages, menuItems } from "./data.js"; | |
import { propEquals, prop, assoc, compose, map } from "./util.js"; | |
const findPageById = id => pages.find(propEquals("id", id)); | |
// Put a "url" property on the menuItems, taken from the related Page | |
console.log( | |
map( | |
compose( | |
assoc( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Ha! I totally fucked up. I noticed after publishing this, so instead of quietly updating this I will | |
* add a bit of educational text. | |
* | |
* The function below, curry_bodged, makes the mistake of saving the args in lexical scope, resulting in | |
* an ever-expanding list of arguments. Every time you call the curried function the arguments are added to | |
* the same list, and the actual applied function will probably re-use the same arguments from the first time. | |
* | |
* Example with the `addThree` function below: | |
* addThree(1, 2, 3) // 6, args = [1, 2, 3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// maybe :: ?a -> Maybe a | |
export const maybe = x => { | |
return x != null && x !== undefined ? Just(x) : Nothing; | |
}; | |
// identity :: a -> a | |
export const identity = x => x; | |
// prop :: String -> Object -> Maybe x | |
export const prop = x => o => maybe(o[x]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Plugin extends PluginBase | |
{ | |
public function boot() | |
{ | |
Event::listen('backend.page.beforeDisplay', function($controller, $action, $params) { | |
$controller->addJs('/plugins/grrr/flexiblepages/assets/javascript/repeater.js'); | |
}); | |
} | |
} |
NewerOlder