Skip to content

Instantly share code, notes, and snippets.

@geminorum
geminorum / PHP-Strings.md
Created April 2, 2017 00:46
What is the difference between single-quoted and double-quoted strings in PHP?

PHP strings can be specified not just in two ways, but in four ways.

  1. Single quoted strings will display things almost completely "as is." Variables and most escape sequences will not be interpreted. The exception is that to display a literal single quote, you can escape it with a back slash \', and to display a back slash, you can escape it with another backslash \\ (So yes, even single quoted strings are parsed).
  2. Double quote strings will display a host of escaped characters (including some regexes), and variables in the strings will be evaluated. An important point here is that **you can use curly braces to iso
@geminorum
geminorum / google_jsapi.php
Created November 27, 2016 22:10 — forked from franz-josef-kaiser/google_jsapi.php
WordPress plugin to add a Google Pie Charts / Visualization in a MetaBox.
<?php
namespace WPSE;
/** Plugin Name: Google JSAPI test plugin */
add_action( 'admin_enqueue_scripts', __NAMESPACE__.'\addScripts' );
function addScripts()
{
wp_enqueue_script(
<?php
/**
* Copyright (c) 2008, David R. Nadeau, NadeauSoftware.com.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
.entry-content {
img {
box-sizing: border-box;
max-width: 100%;
height: auto;
border: 1px solid #ccc;
padding: 2px;
}
@geminorum
geminorum / round.scss
Created October 29, 2016 02:04
sass sound/ceil/floor
line-height: ceil(@height * .666); // 20px (round up)
line-height: floor(@height * .666); // 19px (round down)
line-height: round(@height * .666); // 20px (round to closest integer)
line-height: round(@height * .666, 1); // 20.0px (round to 1 decimal place)
/**
* Shuffles array in place.
* @param {Array} a items The array containing the items.
*/
function shuffle(a) {
var j, x, i;
for (i = a.length; i; i--) {
j = Math.floor(Math.random() * i);
x = a[i - 1];
a[i - 1] = a[j];
@geminorum
geminorum / Conversation Markup.md
Last active June 11, 2016 18:18
Conversation Markup
@geminorum
geminorum / Apache rewrite rule for REST API.md
Created June 9, 2016 00:48
Apache “rewrite rule” for REST API

Here’s how you can configure your Apache webserver for a REST API, without using rewrite rules (thus: you don’t need the rewrite engine). Simply add the following line to your <VirtualHost>:

AliasMatch ^/api/rest/v1/(.*)$ /var/www/[mywebsite]/htdocs/api/rest/v1/index.php

In index.php, you can read the parameters like so:

$path = preg_replace('~^/rest/v1/~', '', $_SERVER['SCRIPT_NAME']);
$parts = explode('/', $path);
var_dump($parts);
@geminorum
geminorum / The difference between UTF-8 and Unicode.md
Created June 8, 2016 22:19
The difference between UTF-8 and Unicode?

If asked the question, “What is the difference between UTF-8 and Unicode?”, would you confidently reply with a short and precise answer? In these days of internationalization all developers should be able to do that. I suspect many of us do not understand these concepts as well as we should. If you feel you belong to this group, you should read this ultra short introduction to character sets and encodings.

Actually, comparing UTF-8 and Unicode is like comparing apples and oranges:

UTF-8 is an encoding - Unicode is a character set

A character set is a list of characters with unique numbers (these numbers are sometimes referred to as “code points”). For example, in the Unicode character set, the number for A is 41.

An encoding on the other hand, is an algorithm that translates a list of numbers to binary so it can be stored on disk. For example UTF-8 would translate the number sequence 1, 2, 3, 4 like this:

@geminorum
geminorum / mail_with_attachments.php
Created May 23, 2016 09:24 — forked from m-manu/mail_with_attachments.php
PHP function to send e-mail with attachments
<?php
/*
Copyright (c) 2012, Manu Manjunath
All rights reserved.
Redistribution and use of this program in source/binary forms, with or without modification are permitted.
Link to this gist is preferred, but not a condition for redistribution/use.
*/
function mail_with_attachments($to, $subject, $message, Array $filepaths, $from = null, $replyto = null) {