Skip to content

Instantly share code, notes, and snippets.

View corazzi's full-sized avatar
:shipit:
shipping

Sacha Corazzi corazzi

:shipit:
shipping
View GitHub Profile
@corazzi
corazzi / parseQueryParams.js
Last active August 14, 2019 09:26 — forked from kares/jquery.parseparams.js
parseQueryParams - parse query string parameters into an object [non-jQuery version]
parseQueryParams = function (query) {
var re = /([^&=]+)=?([^&]*)/g;
var decodeRE = /\+/g;
var decode = function (str) {
return decodeURIComponent(str.replace(decodeRE, " "));
};
var params = {}, e;
while (e = re.exec(query)) {
var k = decode(e[1]), v = decode(e[2]);
@corazzi
corazzi / gmaps-advanced-drawing.html
Created July 17, 2017 16:39 — forked from knownasilya/index.html
Google Maps Advanced Drawing
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="UTF-8">
<title>Drawing Tools</title>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false&libraries=drawing"></script>
<style type="text/css">
#map, html, body {
@corazzi
corazzi / UserInputTest.txt
Last active July 10, 2017 09:04
Test sanitised user input with this list of possible vectors of attack
// Javascript
<script>alert('Test');<script>
// PHP
<?php echo 'Test echo 1'; ?>
<?= 'Test echo 2' ?>
<?php include('non_existent_file'); ?>
<?php require('non_existent_file'); ?>
// HTML
@corazzi
corazzi / wp_get_uploaded_year.php
Created July 4, 2017 08:17
Get the year the file was uploaded relative to its location in wp-content/uploads/
<?php
/**
* Get the year the file was uploaded relative to its location in wp-content/uploads/
*
* @param string Can be a URL or an absolute path to the file
*
* @return string Returns the year as a string, but can easily be cast to an int
*/
function get_uploaded_year($uri)
@corazzi
corazzi / which_os.sh
Last active March 21, 2017 10:12
Determine the operating system from the command line
###########################################################
# Determine the operating system from the command line
#
# NB: Only handles Ubuntu, CentOS, and MacOS so far
###########################################################
function which_os() {
# Setup an OSNAME variable to capture the OS's name
OSNAME='Unknown';
# If there is an /etc/os-release file, use that
@corazzi
corazzi / laravel-view-namespaces.php
Last active January 24, 2017 10:23
Use view namespaces in Laravel controllers
<?php
/**
* Return a view under the controller's view namespace if one is set
*
* @param string $template
* @param array $data
* @param array $mergeData
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
@corazzi
corazzi / acf-textarea-markdown.php
Created December 1, 2016 22:58
Add Jetpack Markdown to an ACF Textarea field
<?php
/**
* Filter an ACF field to add Markdown support with Jetpack
*
* @link https://www.advancedcustomfields.com/resources/acfload_value/
*/
add_filter('acf/load_value/type=textarea', function ($content) {
return wpautop(
WPCom_Markdown::get_instance()->transform($content)
@corazzi
corazzi / debugging-in-wp-config.php
Last active November 15, 2017 06:20
Quick way of turning all of the debugging options on or off in wp-config.php
<?php
// [...]wp-config.php contents[...]
define('DEBUGGING_ON', false);
define('WP_DEBUG', DEBUGGING_ON);
define('WP_DEBUG_LOG', DEBUGGING_ON);
define('WP_DEBUG_DISPLAY', DEBUGGING_ON);
@ini_set('display_errors', DEBUGGING_ON);
@corazzi
corazzi / debug_step.php
Last active May 13, 2016 15:10
Echo out a step in your debugging trace to find out where your code is executed
<?php
function debug_step($message = '')
{
if (isset($_GET['debug'])) {
/**
* Count how many times the debug step has been called
* @var integer
*/
static $i = 1;
@corazzi
corazzi / dirmtime.php
Last active March 30, 2016 10:10
Get the directory's modified time based on when the last file or directory within it was updated
<?php
/**
* Get the directory's modified time based on when the last file within it was updated
*
* @param string Which directory to look within
* @param string A regular expression to match files
*
* @return int The timestamp
*/