Skip to content

Instantly share code, notes, and snippets.

View jongacnik's full-sized avatar

Jon jongacnik

View GitHub Profile
/**
* self managing nanocomponent instance proof of concept,
* unfortunately we get hit with proxy node bugz...
*
* idea here is you reset SOFT_IMAGE_COUNT on choo RENDER
*/
var html = require('choo/html')
var Component = require('choo/component')
.db{display:block}
.dib{display:inline-block}
.di{display:inline}
.dt{display:table}
.dtr{display:table-row}
.dtc{display:table-cell}
.df{display:flex}
.dif{display:inline-flex}
.fl{float:left}
.fr{float:right}

AWS S3 Transfer

When syncing an S3 bucket within the same AWS, you still need to attach some policies. I followed these instructions, but in case they go offline. You need the following:

Policy on source bucket

{
"Id": "Policy1357935677554",
"Statement": [

In our builds we often like to have single sentence excerpts. Over the builds I've devised a rather scary looking, but effective, excerpt generating technique:

<?php

// fancy excerpt function which tries to pull 
// the first sentence. minimum character count
// is considered as well.

function trunc($phrase, $max_words) {
@jongacnik
jongacnik / php-regex-router.php
Created September 27, 2018 22:38 — forked from dave1010/php-regex-router.php
php-regex-router.php
<?php
// dangerously simple PHP regular expression URL router
// requires a mod_rewrite like "RewriteRule . /index.php [L]"
function get($url, $callback) {
$matches = array();
if (preg_match('~' . $url . '~', $_SERVER['REQUEST_URI'], $matches)) {
echo call_user_func_array($callback, $matches);
die();
}
@jongacnik
jongacnik / url-pattern.md
Created September 27, 2018 19:20
URL Pattern

URL Pattern

Sometimes I find it useful to match the current url against a set of keys, maybe to grab a model or define an active state. Things like that. An approach I've been using looks a little like:

<?php
  
function urlpattern ($path, $patterns) {
  foreach ($patterns as $pattern => $name) {
 if ($pattern === '*') continue; // skip default
@jongacnik
jongacnik / readme.md
Created September 23, 2018 21:59
A clean 50/50 layout

A layout that I tend to implement is the following:

+-------+-------+
| TITLE |       |
+-------|  IMG  |
| T     |       |
|  E    |  IMG  |
|   X   |       |
|    T  |  IMG  |
<?php
function str_contains ($str, $arr = []) {
foreach ($arr as $a) {
if (stripos($str, $a) !== false) return true;
}
return false;
}
<?php
function toSuper ($int) {
$SUPERSCRIPTS = [
'0' => '⁰',
'1' => '¹',
'2' => '²',
'3' => '³',
'4' => '⁴',
'5' => '⁵',
@jongacnik
jongacnik / plaintags.php
Last active March 29, 2019 01:37
Kirby Plaintags
<?php
kirbytext::$pre[] = function($kirbytext, $value) {
foreach (c::get('plaintags', []) as $tag) {
$value = str_replace('(' . $tag . ')', '(' . $tag . ': true)', $value);
}
return $value;
};