Skip to content

Instantly share code, notes, and snippets.

View geminorum's full-sized avatar
🏠
Working from home

Nasser Rafie geminorum

🏠
Working from home
View GitHub Profile
@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) {
var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;
return input.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function(match, index, title){
if (index > 0 && index + match.length !== title.length &&
match.search(smallWords) > -1 && title.charAt(index - 2) !== ":" &&
(title.charAt(index + match.length) !== '-' || title.charAt(index - 1) === '-') &&
title.charAt(index - 1).search(/[^\s-]/) < 0) {
return match.toLowerCase();
}