Skip to content

Instantly share code, notes, and snippets.

♜♞♝♛♚♝♞♜
♟♟♟♟♟♟♟♟
□■□■□■□■
■□■□■□■□
□■□■□■□■
■□■□■□■□
♙♙♙♙♙♙♙♙
♖♘♗♕♔♗♘♖
@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;
@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 / .htaccess
Created February 22, 2014 20:55
Simple single point entry index.php configured in .htaccess file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [NC,L]
@jehoshua02
jehoshua02 / _notes.md
Created March 3, 2012 06:59
CodeIgniter page/layout/content views

Why I like this approach ...

I like this approach because it relieves the controllers from much of view rendering responsibility while still leaving the controller the power to alter the view rendering process a great deal.

Lingering concerns ...

However, my gut tells me that this approach still hides a non-trivial flaw. I wonder how this approach will cope with swapping out layouts or pages, and actually generating parts of the total view that require increased intricate logic and heavier data requirements.

The goal ...

@jehoshua02
jehoshua02 / .bash_alias_composer
Created October 4, 2012 05:32
Bash aliases for Composer
alias composer='php composer.phar'
alias composerinit='curl -s http://getcomposer.org/installer | php; composer init; echo composer.phar >> .gitignore'
alias composerdump='composer dumpautoload --optimize'
@jehoshua02
jehoshua02 / sass_kss_gulp.md
Created June 24, 2014 22:42
Compile Sass and generate KSS docs with Gulp.

Setting up Gulp to compile Sass and build KSS docs

Install dependencies:

npm install --save-dev gulp gulp-sass gulp-kss gulp-concat gulp-clean

This will add devDependencies to your package.json that looks like this:

@jehoshua02
jehoshua02 / kint_log.php
Last active November 1, 2017 10:25
Just an idea for logging kint to file instead of screen.
<?php
require_once __DIR__ . '/vendor/autoload.php';
define('KINT_LOG', '/vagrant/logs/kint.log.html');
/**
* Logs Kint::dump() to file
*/
function l()
@jehoshua02
jehoshua02 / PYTHON
Created October 4, 2011 09:11
mutagen: mp3 tags in not showing in windows explorer
from shutil import copyfile
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, TIT2, TCON, TALB
def resetFile():
"""Copies original.mp3 to somefile.mp3 and returns an mutagen MP3 file handle"""
filename = 'somefile.mp3'
copyfile('original.mp3', filename)
file = MP3(filename)
return file
@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)