Skip to content

Instantly share code, notes, and snippets.

@hakre
hakre / insert-query-packet-limit.php
Created March 15, 2012 14:59
Large insert query SQL builder
<?php
/**
* @link http://stackoverflow.com/questions/9719032/php-insert-array-into-db-i-know-there-already-posts-existing-but
*/
/**
* Insert Query SQL Builder based on packed size limits
*/
class SQLInsertQuery
{
@hakre
hakre / unicode-encode-utf8.php
Created April 10, 2012 14:05
Unicode Codepoint to UTF-8
<?php
/**
* @see Unicode 6.0.0 Ch2 General Structure, rfc3629
* @param int|string $codepoint e.g. 0xC9 / "U+00C9"
* @return string
*/
function unicodeCodePointToUTF8($codepoint)
{
is_string($codepoint) && sscanf($codepoint, 'U+%x', $codepoint);
if ($codepoint < 0) {
@hakre
hakre / imap-attachment.php
Created April 11, 2012 22:50
Save attachments from imap messages to disk.
<?php
/**
* imap-attachment.php
*
* @author hakre <hakre.wordpress.com>
* @link http://stackoverflow.com/questions/9974334/how-to-download-mails-attachment-to-a-specific-folder-using-imap-and-php
*/
/**
* Utility Class
@hakre
hakre / curry-pairs.php
Created April 13, 2012 18:57
Curry Pairs
<?php
/**
* curry-pairs.php
*
* @link http://stackoverflow.com/questions/10144996/permutations-of-values-in-array
*/
/**
* @param array $a
* @param array $b
@hakre
hakre / gist:2397187
Created April 16, 2012 09:06
Contextual user-friendly time and dates with PHP
<?php
/**
* @link http://snipt.net/pkarl/pkarlcom-contextualtime/
* @link http://pkarl.com/articles/contextual-user-friendly-time-and-dates-php/
*/
function contextualTime($small_ts, $large_ts=false) {
if(!$large_ts) $large_ts = time();
$n = $large_ts - $small_ts;
if($n <= 1) return 'less than 1 second ago';
if($n < (60)) return $n . ' seconds ago';
@hakre
hakre / attacks-xml.php
Created April 18, 2012 21:49
PHP DOMDocument/libxml billion laughs / quadratic blowup
<?php
/**
* @link http://stackoverflow.com/q/10212752/367456
* @link http://msdn.microsoft.com/en-us/magazine/ee335713.aspx
*/
$file = 'billion-laughs-2.xml';
$file = 'quadratic-blowup-2.xml';
printf("Mem: %s (Peak: %s)\n", number_format(memory_get_usage(), 0, '', ' '), number_format(memory_get_peak_usage(), 0, '', ' '));
@hakre
hakre / mirc.php
Created April 26, 2012 09:12
Tokenizer Example of Mirc Color and Style (bold) Codes.
<?php
/**
* Tokenizer Example of Mirc Color and Style (bold) Codes.
*
* @link http://stackoverflow.com/q/10329443/367456
*/
$mirc = "\x034this text is red\x033this text is green\x03 \x02bold text\x02
\x034,3this text is red with a green background\x03";
@hakre
hakre / specificity.php
Created May 18, 2012 10:15 — forked from absfarah/specificity.php
CSS sepcificty
<?php
/**
* CSS sepcificty
*
* @link http://stackoverflow.com/questions/10636340/order-css-based-on-selector-specificity
* @return int
*/
function specificity($selector)
{
// Pseudo classes
@hakre
hakre / bopypad.md
Last active October 5, 2015 07:07
SO copypad

This question appears to be off-topic because it is about ...

Tutoring with a software named Wordpress, here a Tutorial for Extending it with a specific Plugin and an individual Theme.

Tutoring a Software Product named Magento.

a very individual problem without given any further reference to commons in programming in a useful manner. See also: Stack Overflow question checklist

a Debugging request of larger chunks of non-isolated code that may (or may not) contain the code the question asks about. Instead the code should be reduced the a bare minimum example code that outlines the problem and question in a compact and self-explaining manner.

@hakre
hakre / jquery.aftertext.js
Created June 21, 2012 12:42
jQuery afterText Plugin
/**
* jQuery afterText Plugin
*
* Copyright (C) 2012 hakre <http://hakre.wordpress.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*