Skip to content

Instantly share code, notes, and snippets.

<?php
function isTor()
{
$host = array
(
$_SERVER['REMOTE_ADDR'],
$_SERVER['SERVER_PORT'],
$_SERVER['SERVER_ADDR'],
'ip-port.exitlist.torproject.org',
@alixaxel
alixaxel / index.php
Created May 14, 2012 16:59
helper functions
<?php
require_once('./xpto.php');
Dump(get_loaded_extensions(false));
die();
$xref = array
(
<?php
require('pathing.php');
$gmap = array(
array(6, 5, 6, 4, 6, 1, 2, 6, 9, 6, 6, 5, 6, 4, 6, 1, 2, 6, 9, 6),
array(8, 5, 3, 2, 9, 9, 3, 2, 4, 7, 8, 5, 3, 2, 9, 9, 3, 2, 4, 7),
array(4, 8, 7, 7, 3, 5, 2, 8, 3, 5, 4, 8, 7, 7, 3, 5, 2, 8, 3, 5),
array(7, 5, 5, 8, 7, 7, 8, 4, 8, 5, 7, 5, 5, 8, 7, 7, 8, 4, 8, 5),
array(4, 5, 1, 6, 4, 6, 9, 3, 8, 1, 4, 5, 1, 6, 4, 6, 9, 3, 8, 1),
/* Imagine we want to serve a the same portrait rendering for iPad and Kindle, we could do: */
@media only screen and (device-height : 1024px) and (orientation : portrait) and (min-device-width : 600px) and (max-device-width : 768px) {
/* CSS for iPad and Kindle here (portrait) */
}
/* The following would make it easier to split the rules if needed later on (although I've grouped the common conditions here): */
@media only screen and (device-height : 1024px) and (orientation : portrait) and (
.grid {
margin: 0 auto;
width: 960px;
}
.grid [class^="_"] { /* my columns start with "_", _1, _2, ... */
display: inline;
float: left;
}
@alixaxel
alixaxel / longest_common_substring.php
Created July 9, 2012 03:06 — forked from chrisbloom7/longest_common_substring.php
Find the longest common substring in an array of strings (PHP)
<?php
function longest_common_substring($words)
{
$words = array_map('strtolower', array_map('trim', $words));
$sort_by_strlen = create_function('$a, $b', 'if (strlen($a) == strlen($b)) { return strcmp($a, $b); } return (strlen($a) < strlen($b)) ? -1 : 1;');
usort($words, $sort_by_strlen);
// We have to assume that each string has something in common with the first
// string (post sort), we just need to figure out what the longest common
// string is. If any string DOES NOT have something in common with the first
// string, return false.
@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 / fortune.fish
Created October 30, 2015 21:42 — forked from montanaflynn/fortune.fish
Fun with fish and fortunes
# place this in your fish path
# ~/.config/fish/config.fish
function fish_greeting
if not type fortune > /dev/null 2>&1
apt-get install fortune
end
fortune -a
end
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
<?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