Skip to content

Instantly share code, notes, and snippets.

View Ibmurai's full-sized avatar

Jens Riisom Schultz Ibmurai

View GitHub Profile
@Ibmurai
Ibmurai / PHP - finding escaped backslashes
Created August 19, 2011 10:19
PHP, regex and double quoted strings are fun...
<?php
/* This handy script lets you locate escaped backslashes in the prettiest way. */
$input = $_POST['value'];
$matches = array();
if (preg_match("/\\\\/", $input, $matches)) {
var_dump($matches);
} else {
@Ibmurai
Ibmurai / lol.js
Created February 6, 2012 09:50
A basic pattern for jQuery plugins
(function($) {
$.fn.lol = function() {
var scope = function($this) {
var f = {
/**
* The "constructor"
*/
init : function() {
console.log('init');
@Ibmurai
Ibmurai / lol.php
Created February 20, 2012 15:08
php unnamed variable and silly stdClass casting
<?php
$lol = null;
$$lol->enabled = true;
var_dump($$lol);
var_dump($lol);
/* Output:
PHP Strict Standards: Creating default object from empty value in /Users/ibmurai/lol.php on line 4
@Ibmurai
Ibmurai / php-log-highlight.php
Created April 27, 2012 11:08
PHP apache error log highlighter
#!/usr/bin/php
<?php
/**
* Usage: tail -f /var/log/apache2/error.log | php-log-highlight
*/
ini_set('display_errors', E_ALL & ~E_STRICT);
// Dependencies
require_once 'Console/Color.php';
@Ibmurai
Ibmurai / fixstuff.php
Created September 27, 2012 12:34
Fix all calls to htmlentities and htmlspecialchars, if you want to do ISO-8859-1 on PHP 5.4 or just be prepared.
#!/opt/local/bin/php
<?php
function getDirectoryList($dir, $skipExtensions = []) {
$dirList = $fileList = [];
if ($dfp = opendir($dir)) {
while (($entry = readdir($dfp)) !== false) {
$skip = false;
foreach ($skipExtensions as $extension) {
if (substr($entry, strlen($entry) - strlen($extension)) === $extension) {
@Ibmurai
Ibmurai / docker-sweep.sh
Created January 19, 2017 12:31
Non destructive docker cleanup
#!/bin/bash
docker rm $(docker ps -aq --filter status=exited)
docker rmi $(docker images -f "dangling=true" -q)
@Ibmurai
Ibmurai / docker-clean.sh
Created January 19, 2017 12:35
Full docker cleanup - remove every image and container
#!/bin/bash
docker stop $(docker ps -aq --filter status=running)
docker rm $(docker ps -aq)
docker rmi $(docker images -q)
@Ibmurai
Ibmurai / lol.sh
Created February 7, 2017 13:40
Is tvtid backend good?
#!/bin/bash
if [ $(curl -s -H "Accept: application/json" https://tvtid-backend.tv2.dk/tvtid-app-backend/schedules/channels | grep "{},") ]; then
echo "It's bad!!"
else
echo "It's good!"
fi
@Ibmurai
Ibmurai / tv2e.fish
Created May 8, 2018 06:13
Fish function to convert a letter to a TV 2 team
function tv2e
switch "$argv"
case 'a'
echo "playfe"
case 'b'
echo "is"
case 'c'
echo "cms"
case 'd'
echo "app"