Skip to content

Instantly share code, notes, and snippets.

@alixaxel
alixaxel / hacks.css
Created November 20, 2011 20:59 — forked from xeoncross/hacks.css
CSS hacks
/*
Comprehensive List of Browser-Specific CSS Hacks
http://paulirish.com/2009/browser-specific-css-hacks/
*/
/***** Selector Hacks ******/
/* IE6 and below */
* html #uno { color: red }
<?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),
@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 / 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
@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
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
/*
So you like the style of impress.js demo?
Or maybe you are just curious how it was done?
You couldn't find a better place to find out!
Welcome to the stylesheet impress.js demo presentation.
Please remember that it is not meant to be a part of impress.js and is
not required by impress.js.

Microframework

This is a PHP microframework based on anonymous functions.

Features

  • requested URLs matched using regular expressions
  • request methods (matches using regular expressions too)
  • differenced FIFO queues for each $priority
  • command line usage
  • backward compatibility
  • integrated Dependency Injection system
  • settings system
@alixaxel
alixaxel / Doo.php
Created May 11, 2013 03:27 — forked from eb1024/Doo.php
<?php
function DB($query)
{
static $db = null;
static $result = array();
if (is_file($query) === true)
{
$db = new PDO('sqlite:' . $query, null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));