Skip to content

Instantly share code, notes, and snippets.

View bluefirex's full-sized avatar
👋

Benjamin Schmidt bluefirex

👋
View GitHub Profile
@bluefirex
bluefirex / benchmark.php
Created December 1, 2022 09:36
Compare runtime of PHP functions
<?php
function benchmark(Callable $fn, ...$args) {
$start = microtime(true);
for ($i = 0; $i <= 23005; $i++) {
$fn(...$args);
}
$end = microtime(true);
$diff = ($end - $start);
@bluefirex
bluefirex / benchmark.js
Last active April 27, 2022 11:25
RegEx vs. String Split vs. String Loop
/*
== Results: ==
1. Loop over string
2. Regex
3. .split()
== Output: ==
Regex
@bluefirex
bluefirex / game.js
Last active May 15, 2019 21:14
Demonetization Game (Game of 100)
// Disclaimer:
// This is not made to show off coding skills, but rather to give people an idea how you could simulate the Game of 100 or
// similar instances. If you don't know, what this is, refer to https://www.youtube.com/watch?v=kOnEEeHZp94 (Vsauce2) and/or
// https://www.youtube.com/watch?v=C5-I0bAuEUE (minutephysics)
// Helper for shuffling an array
Array.prototype.shuffle=function(){let t,h,r=this.length;if(0===r)return this;for(;--r;)t=Math.floor(Math.random()*(r+1)),h=this[r],this[r]=this[t],this[t]=h;return this};
// Helper for creating a fixed number of somethings with a range from 0 to count
let makeCollection = (count) => [...new Array(count)].map((x, i) => i)
@bluefirex
bluefirex / html.html
Created August 29, 2017 21:17
SweetModal Example
<a class="sweet-modal-trigger">Open SweetModal</a>
@bluefirex
bluefirex / PaginatedRequest.php
Last active August 29, 2017 21:06
Paginated Results in a JSON API
<?php
namespace Adepto\Asgard\API;
use Adepto\Asgard\Common\PaginatedResults;
use Purl\Url;
use Psr\Http\Message\ServerRequestInterface;
/**
* Represents a request on a paginated result set.
<template>
<ul class="sweet-pagination" v-if="pages > 1">
<li :class="[{hidden: currentPage <= 2}]">
<a href="#" v-on:click.prevent="onChange(1)" class="prev">‹‹</a>
</li>
<li :class="[{hidden: currentPage <= 1}]">
<a href="#" v-on:click.prevent="onChange('previous')" class="prev">‹</a>
</li>