Skip to content

Instantly share code, notes, and snippets.

View pedroborges's full-sized avatar
🏠
Working from home

Pedro Borges pedroborges

🏠
Working from home
  • Brazil
View GitHub Profile
var qc=Object.defineProperty;var Hc=(t,e,n)=>e in t?qc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var zc=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Ms=(t,e,n)=>(Hc(t,typeof e!="symbol"?e+"":e,n),n);var zv=zc((Wv,Yu)=>{(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const i of o)if(i.type==="childList")for(const s of i.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&r(s)}).observe(document,{childList:!0,subtree:!0});function n(o){const i={};return o.integrity&&(i.integrity=o.integrity),o.referrerpolicy&&(i.referrerPolicy=o.referrerpolicy),o.crossorigin==="use-credentials"?i.credentials="include":o.crossorigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(o){if(o.ep)return;o.ep=!0;const i=n(o);fetch(o.href,i)}})();var Qn=typeof globalThis<"u"?globalThis:typeof window<"u"?
@pedroborges
pedroborges / fake-promise.js
Created July 15, 2020 20:04
Ways to fake API request delay during development
const wait = (delay, data) => ({ then(resolve) { setTimeout(resolve, delay, data) } })
const fakeApi = async () => await wait(500, [1, 2, 3, 4])
@pedroborges
pedroborges / index.php
Created July 8, 2019 12:31
How to add Kirby 3 file template to Kirby 2 images
<?php
require __DIR__ . '/kirby/bootstrap.php';
// echo (new Kirby)->render();
$items = page('blog')->children();
foreach ($items as $item) {
if ($i = $item->cover()->toFile()) {

Kirby 3 CLI

Add the function below to your ~/.bashrc or ~/.zshrc file.

Usage:

  • kirby <branch>
  • kirby
@pedroborges
pedroborges / LocalValetDriver.php
Last active January 31, 2021 00:30
Valet Driver for Kirby 3 with public directory
<?php
class LocalValetDriver extends ValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
<?php
function characterCodeAt(string $string, int $index) {
return ord(substr($string, $index, 1));
}
function fuzzySearch(string $needle, string $haystack) {
$needleLength = strlen($needle);
$haystackLength = strlen($haystack);
@pedroborges
pedroborges / faq.php
Created December 4, 2017 13:10
Fuzzy Search may also be used on @getkirby page fields? You can even chain it with other field methods. https://github.com/pedroborges/kirby-fuzzy-search
<?php
// site/controllers/faq.php
return function($site, $pages, $page) {
$questions = $page->questions();
if ($query = get('q')) {
$questions = $questions->fuzzySearch($query)->toStructure();
}
@pedroborges
pedroborges / blog.php
Last active December 1, 2017 23:03
Besides finding non-exact matches in your content, Fuzzy Search for @getkirby offers some neat features like the ability to search through a custom page method. https://github.com/pedroborges/kirby-fuzzy-search
<?php
// site/controllers/blog.php
return function($site, $pages, $page) {
$query = esc(get('q'));
$articles = $page->children()->visible()->flip();
if ($query) {
$articles = $articles->fuzzySearch($query, 'title|text|authorName');
}
<nav class="list-reset flex flex-col lg:flex-row items-center">
<ul class="list-reset flex flex-col lg:flex-row mx-6">
<li class="active border border-white rounded text-blue py-2 px-3 text-center align-content-center">
<a href="/" class="text-slate text-right">Home</a>
</li>
<li class="border border-white rounded text-blue py-2 px-3 text-center align-content-center">
<a href="/newsletter" class="text-slate">Newsletter</a>
</li>
<li class="border border-white rounded text-blue py-2 px-3 text-center align-content-center">
<a href="/talks" class="text-slate text-right">Talks</a>
@pedroborges
pedroborges / composer.json
Created October 9, 2017 16:49
Kirby Sermon Uploader
{
"require": {
"aws/aws-sdk-php": "^3.12",
"james-heinrich/getid3": "^1.9"
}
}