Skip to content

Instantly share code, notes, and snippets.

View like_to_regex.php
<?php
function likeToRegex($like)
{
// replace all % characters that are not escaped with .*
$regex = preg_replace('/(?<!\\\)%/', '.*', $like);
// replace all escaped % characters with %
$regex = str_replace('\%', '%', $regex);
// replace all unescaped _ characters with .{1}
$regex = preg_replace('/(?<!\\\)_/', '.{1}', $regex);
View laravel-errors.js
$.ajax({
method: POST,
url: my.app.dev/users/1,
data: { name: "Matt"}
})
.done(function () {
// whatever you normally do here
})
.fail(function (res) {
if (res.status !== 422) {
@matt-allan
matt-allan / lumen-validator.md
Last active Jan 20, 2016
Implicit Validation For Lumen
View lumen-validator.md

Currently the validator will not run validation rules for empty values:

$rules = ['age' => 'integer'];

$input = json_decode('{"age": null}', true);

Validator::make($input, $rules)->passes(); // true
View stream-multipart-example.php
<?php
$stream = new GuzzleHttp\Psr7\MultipartStream([['name' => 'some-file', 'contents' => 'the contents']]);
$client = new GuzzleHttp\Client();
$r = $client->request('POST', 'http://httpbin.org/post', ['body' => $stream]);
$r->getBody()->getContents();
=> """
{\n
"args": {}, \n
"data": "", \n
"files": {}, \n
@matt-allan
matt-allan / getting-started-streams.php
Created Nov 6, 2015
gettings started with reading streams in PHP
View getting-started-streams.php
<?php
// Open the stream
$numbers = fopen(__DIR__ . '/numbers.txt', 'r');
// Wrap our parser in an infinite loop, so it won't stop until we say so
while (true) {
// Read a line
$buffer = fgets($numbers);
// The docs say it will return false when there arent any bytes left,
// so we break out of our loop and let the sript die when that happens.
@matt-allan
matt-allan / Makefile
Created Apr 28, 2015
Makefile for esp8266 IoT_Demo
View Makefile
# Makefile for ESP8266 projects
#
# Note: This Makefile has all the libs for the IoT_Demo
#
# Thanks to:
# - zarya
# - Jeroen Domburg (Sprite_tm)
# - Christian Klippel (mamalala)
# - Tommie Gannert (tommie)
#
View chromebook-bash
cd /tmp/
uname -r
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.18-vivid/linux-headers-3.18.0-031800-generic_3.18.0-031800.201412071935_amd64.deb
uname -r
cd /tmp
sudo mkdir kernel
cd kernel/
cd ../
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.18-vivid/linux-headers-3.18.0-031800-generic_3.18.0-031800.201412071935_amd64.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.18-vivid/linux-headers-3.18.0-031800_3.18.0-031800.201412071935_all.deb
@matt-allan
matt-allan / xbmcSetup.md
Last active Sep 26, 2015
xbmc setup crouton
View xbmcSetup.md
View croutonLauncher.md

If anyone uses this - the php server process doesn't currently kill itself when you return to the chroot.

within the chroot:

sudo apt-get install php5

cd ~/
mkdir scripts
cd scripts
@matt-allan
matt-allan / croutonGamepadFix.md
Last active Nov 3, 2017
setup dragonrise controllers with crouton
View croutonGamepadFix.md

To make dragonrise n64 and snes controllers work with my crouton xfce4/ubuntu chroot, I had to recompile the kernel with support for the hid_dr module. These are the steps to get the controllers working. Almost all steps are taken from the sources listed below. All commands are entered in the chroot's terminal, not the chronos shell.

sudo apt-get install git-core make kernel-package
cd ~
git clone https://chromium.googlesource.com/chromiumos/third_party/kernel -b chromeos-3.8
cd kernel
nano chromeos/config/base.config

type ctrl-w, type 'error_on_warning' and press enter to find the line you need to edit.