Skip to content

Instantly share code, notes, and snippets.

@alixaxel
alixaxel / DB.php
Last active December 11, 2015 22:19
<?php
public static function DB($query = null)
{
static $db = array();
static $result = array();
if (isset($db[self::$id], $query) === true)
{
if (empty($result[self::$id][$hash = md5($query)]) === true)
<?php
public static function Dump()
{
foreach (func_get_args() as $argument)
{
switch (gettype($argument))
{
case 'array':
case 'object':
<?php
public static function Typography($string, $quotes = true)
{
if ($quotes === true)
{
$string = preg_replace(array("~'([^']+)'~", '~"([^"]+)"~'), array('‘$1’', '“$1”'), $string);
}
return preg_replace(array('~[.]{2,}~', '~--~', '~-~', '~(?<=\d)(st|nd|rd|th)\b~i'), array('…', '—', '–', '<sup>$1</sup>'), $string);
@alixaxel
alixaxel / Form.php
Last active December 11, 2015 20:59
<?php
/**
* The MIT License
* http://creativecommons.org/licenses/MIT/
*
* Copyright (c) Alix Axel <alix.axel@gmail.com>
**/
class phunction_HTML_Form extends phunction_HTML
<?php
function isVATIN($vatin)
{
if (preg_match('~^[125689][0-9]{8}$~', $vatin) > 0)
{
$vatin = str_split($vatin);
foreach (array_slice($vatin, 0, -1) as $key => $value)
{
@alixaxel
alixaxel / plugin_DatabaseHide.php
Created January 19, 2013 21:39
Collection of Adminer Plugins
<?php
/** plugin_DatabaseHide.php
* @author Alix Axel
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
*/
class AdminerDatabaseHide {
protected $disabled;
function AdminerDatabaseHide($disabled) {
<?php
/**
* Download a large distant file to a local destination.
*
* This method is very memory efficient :-)
* The file can be huge, PHP doesn't load it in memory.
*
* /!\ Warning, the return value is always true, you must use === to test the response type too.
*
* @author dalexandre
These weights are often combined into a tf-idf value, simply by multiplying them together. The best scoring words under tf-idf are uncommon ones which are repeated many times in the text, which lead early web search engines to be vulnerable to pages being stuffed with repeated terms to trick the search engines into ranking them highly for those keywords. For that reason, more complex weighting schemes are generally used, but tf-idf is still a good first step, especially for systems where no one is trying to game the system.
There are a lot of variations on the basic tf-idf idea, but a straightforward implementation might look like:
<?php
$tfidf = $term_frequency * // tf
log( $total_document_count / $documents_with_term, 2); // idf
?>
It's worth repeating that the IDF is the total document count over the count of the ones containing the term. So, if there were 50 documents in the collection, and two of them contained the term in question, the IDF would be 50/2 = 25. To be accurate, we s
@alixaxel
alixaxel / feistel.php
Created October 25, 2012 22:17 — forked from xeoncross/feistel.php
Feistel Hash
<?php
/**
* This function computes a hash of an integer. This can be used to not expose values to a customer, such as
* not giving them the id value for passing them to URLs. This algorithm is a bidirectional encryption (Feistel cipher) that maps
* the integer space onto itself.
*
* @link http://wiki.postgresql.org/wiki/Pseudo_encrypt Algorithm used
* @link http://en.wikipedia.org/wiki/Feistel_cipher Wikipedia page about Feistel ciphers
* @param int $value
* @return int
@alixaxel
alixaxel / example.php
Created July 19, 2012 23:09 — forked from xeoncross/index.php
MySQL database relations
<?php
/*
* What about asking PHP to figure out the relation path!???? AWESOME!
*/
// url.user_id -> belongs_to -> users.id
$start = 'vote'; // We have a vote
$end = 'user'; // We have a user