Skip to content

Instantly share code, notes, and snippets.

@jehoshua02
jehoshua02 / JsonSchema.php
Created May 22, 2023 22:49
Quick recursive function to replace $refs in json schema.
<?php
namespace App\Libs;
class JsonSchema {
public static function flatten_spec($file) {
$path = dirname($file);
$json = static::load_json($file);
$contents = json_encode(static::replace_refs($path, $json));
file_put_contents($path . '/openapi.json', $contents);
♜♞♝♛♚♝♞♜
♟♟♟♟♟♟♟♟
□■□■□■□■
■□■□■□■□
□■□■□■□■
■□■□■□■□
♙♙♙♙♙♙♙♙
♖♘♗♕♔♗♘♖
@jehoshua02
jehoshua02 / randomItem.elm
Last active September 30, 2016 14:10
Here's how I would have liked to get a random number in elm
randomItem : List a -> Maybe a
randomItem xs =
case xs of
[] ->
Nothing
_ ->
let
randomInt =
Random.int 0 ((List.length xs) - 1)

PR Template Bookmark

javascript:(function pullRequestTemplate() {
  var e = document.activeElement;
  if (e) {
    e.value += [
      '#### What does this PR do?',
      '#### Where should the reviewer start?',
 '#### How should this be manually tested?',
@jehoshua02
jehoshua02 / JsonFileDataProviderIterator.php
Last active July 14, 2023 03:46
JsonFileDataProviderIterator class for use with PHPUnit @dataProvider annotation.
<?php
class JsonDataProviderIterator implements Iterator
{
protected $position = 0;
protected $array;
public function __construct($test, $namespace)
{
$path = preg_replace('/.php$/', '.data', $test) . '/' . $namespace;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
console.log('hello');
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
{
".modal" : ".modal",
".modal.modal-open" : ".modal--open",
".modal > .inner" : ".modal__inner",
".modal > .inner > .head" : ".modal__head",
".modal > .inner > .head > .title" : ".modal__title",
".modal > .inner > .head > .modal-toggle": ".modal__head > .modal-toggle",
".modal > .inner > .body" : ".modal__body",
".modal > .inner > .foot" : ".modal__foot"
}
@jehoshua02
jehoshua02 / className.js
Created May 4, 2015 23:04
React.addons.classSet() replacement ...
module.exports = function (classSet) {
return Object.keys(classSet).filter(function (className) {
return !!classSet[className];
}).join(' ');
};
@jehoshua02
jehoshua02 / debounce.js
Created May 1, 2015 21:31
Primitive debounce function.
var debounce = (function () {
var timeouts = {};
return function (id, callback) {
if (timeouts[id]) {
clearTimeout(timeouts[id]);
}
timeouts[id] = setTimeout(callback, 300);
}
})();