ThinkHTML Tools and stuff

Text Manipulation

Proxies

JavaScript

Cronjob

Date to day

HTML

XPath Axis

XPath Class selector

  //*[contains(concat(" ", normalize-space(@class), " "), " foo ")] 

PHP Downloader

PHP HTML Parser

HTML Boilerplate

HTML Encode/Decode

PHP get full URL

PHP PDO Wrapper

PHP Markdown

PHP Iterate over a folder

$dir = '../cookieid/';
$files = glob($dir.'/*.{jpg,png,gif}', GLOB_BRACE);
foreach($files as $file){
    echo $file.PHP_EOL;
}

Cookies

JavaScript code minimizer/compressor

JavaScript for loop

JavaScript avoid console errors

// Swallow console.log in IE8 to prevent JS error.
if (typeof console === "undefined" || typeof console.log === "undefined") {
    console={};
    console.log = function(msg){};
    console.error = function(msg){};
}

JavaScript jQuery - DOM HTML manipulation / wrapper

JavaScript JSON - Data storage format

HTML datalist polyfill

MySQL Create table

CREATE TABLE `prefix_table` (
 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
 `content_id` int(11) unsigned NOT NULL,
 `ckid` char(22) DEFAULT NULL,
 `userid` int(11) unsigned NOT NULL,
 `rating` tinyint(3) NOT NULL,
 `created` datetime DEFAULT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `constraint1` (`content_id`,`userid`),
 UNIQUE KEY `constraint2` (`content_id`,`ckid`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

MySQL Timezones

MySQL Rank

MySQL Materialized view

MySQL Select duplicates

MySQL Optimize RAND

MySQL Remove primary key

MySQL Common tags

MySQL Select last from each group

MySQL Max Value Column

PHP PDO MySQL Connect

MYSQL TODO: Code to work with closure tables

Regex

Match word: \b[\pL\pM\p{Nl}\p{Nd}\p{Pc}]+\b

\pL matches any kind of letter from any language
\pM matches a character intended to be combined with another character (e.g. accents, umlauts, enclosing boxes, etc.)
\p{Nl} matches a number that looks like a letter, such as a Roman numeral
\p{Nd} matches a digit zero through nine in any script except ideographic scripts
\p{Pc} matches a punctuation character such as an underscore that connects words

Allow whitespace in regex rule: /.*/x flag
Treat ^$ as stard and end of line and . matches newline: /.*/m flag
Support unicode: /.*/u flag
Case insensitive match: /.*/i flag
Start and end of string: \A, \Z
Any digit: \d
Any word: \w (surrounded by word boundaries, \W negated \w)
Word boundary: \b (\B negated \b)
Non-empty line: /.*\S.*/
Empty line: /\s*/ or /^\s*$/m
One newline: (\r\n|\r|\n)
Match unicode grapheme: \X (unicode version of . except \X matches linebreak) or \P{M}\p{M}*+
Match unicode grapheme for those that don't support \X: \P{M}\p{M}*+ or (?>\P{M}\p{M}*), (?>\P{M}\p{M}*)+ for match many
Match codepoint: \uFFFF (JavaScript) or \x{FFFF} (Perl/PCRE/PHP) or  (XPath)
Match codepoint in "letter" category: \p{L} (Negated: \P{L})
Match codepoint in "combining mark" category: \p{M}*+
Match letter with accent: \p{L}\p{M}*+
Match non mark without combining marks: \P{M}\p{M}*+
Any kind of space: \p{Zs}
Match cyrillic script: \p{Cyrillic} (russian letters)
Unicode letter: \p{L}
Unicode mark: \p{M} (accents for example)
Unicode number: \p{N} (1,2,3,I,II,III)
Unicode symbol: \p{S} (Math)
Unicode space: \p{Z} (\n\r)
Unicode punctuation: \p{P} (.,-_()[]{})
Unicode control char: \p{C}
Non capture group: (?:http|ftp)://([^/\r\n]+)(/[^\r\n]*)? (does not match http/ftp)

More on groups
More on special groups
More on unicode
More on dot
More here (partially misleading)

Facebook

Google

Yandex

Crontab

#type in putty
crontab -e
0 2 * * * /usr/bin/php5 /var/www/star_admin/www/spider.php --uri=tenstars >> /var/www/star_admin/www/spider-debug.txt
edit it like a text document, every crontab on a new line
exit
y (to save)
enter
crontab -l (list crontabs)

--------------------------------------------------------------------------------------------------------
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
--------------------------------------------------------------------------------------------------------
* * * * *   every minute
*/1 * * * * every minute
*/3 * * * * every 3 minutes
0 * * * *   every hour (at minute 0)
0 0 * * *   every day (at hour 0 minute 0)
0 3 * * *   every day (at hour 3am)
--------------------------------------------------------------------------------------------------------

#crontab unfinished example
#in putty
#crontab mysql
crontab -e
#every day at 12:00
#min hour day week
0 12 * * * {path to mysql?} mysql -h localhost -u root -p"zolotieyaica" -e 'UPDATE `jos_k2_items` SET `sticky`=0 WHERE `id` IN(SELECT `itemid` FROM `jos_k2_sticky_expires` WHERE `expires` <= CURRENT_TIMESTAMP());'
crontab -l
#crontab php (every day at 2am)
0 2 * * * /usr/bin/php5 /var/www/dev_aggregator/public_html/index.php --uri=cron/run >> spider-debug.txt
0 2 * * * /usr/bin/php5 /var/www/dev_aggregator/public_html/spider.php --uri=tenstars >> /var/www/dev_aggregator/public_html/spider-debug.txt
0 2,10,18 * * * /usr/bin/php5 /var/www/star_admin/www/spider.php --uri=tenstars >> /var/www/star_admin/www/spider-debug.txt
--------------------------------------------------------------------------------------------------------

Joomla remove chrome in module

$attribs['style'] = 'none';

Joomla common vars

$doc =&JFactory::getDocument();
$user = &JFactory::getUser();
$db = &JFactory::getDBO();
$now = &JFactory::getDate();
$url = JURI::getInstance()->toString(array('path','query'));
global $mainframe;  $template = $mainframe->getTemplate();
$tmp = clone JFactory::getURI();
$tmp->setVar('v',$ver['version']);
$tmp->toString(array('path','query'));
$db->loadAssocList()
$db->loadAssocList('key')
$db->loadAssoc()
$db->loadObject()
$db->setQuery($query);
$db->query();

Joomla minimum (microjoomla)

define( '_JEXEC', 1 );
define('JPATH_BASE', realpath(dirname(dirname(__FILE__).'/../../..')));
define( 'DS', DIRECTORY_SEPARATOR );
require JPATH_BASE . DS . 'includes' . DS . 'defines.php';
require JPATH_BASE . DS . 'includes' . DS . 'framework.php';
$mainframe = JFactory::getApplication('site');

Joomla Plugins

jimport('joomla.plugin.helper');
JPluginHelper::importPlugin ('system');
$mainframe->triggerEvent('onAfterInitialise');

IP Tools

Books