Skip to content

Instantly share code, notes, and snippets.

View xeoncross's full-sized avatar

David Pennington xeoncross

View GitHub Profile
@xeoncross
xeoncross / frameworks.nginx.conf
Created September 2, 2011 02:20
Route all subdomains to their own folders
server {
listen 80;
server_name ~^(.+)\.frameworks\.loc$;
set $file_path $1;
root /home/_______/www/frameworks/$file_path/public;
index index.html index.php;
include /etc/nginx/defaults.conf;
}
# make sure to create matching entries in /etc/hosts!
@xeoncross
xeoncross / timelapse.screencase.linux.sh
Created September 6, 2011 21:27
Command line screencast timelapse
http://labs.laan.com/wp/2011/01/how-to-make-time-lapse-screencaptures-of-your-design-work-for-free-mac/
In ubuntu I created a bash script and ran it all day while I worked (using apt-get install ImageMagick)
#!/bin/bash
i=1;
while [ 1 ];
do import -window root -resize 50% my/foldername/$i.jpg
let i++;
sleep 10;
@xeoncross
xeoncross / timezone.php
Created September 8, 2011 18:43
The perfect TimeZone selectbox list for PHP 5.3+
<?php
$regions = array(
'Africa' => DateTimeZone::AFRICA,
'America' => DateTimeZone::AMERICA,
'Antarctica' => DateTimeZone::ANTARCTICA,
'Aisa' => DateTimeZone::ASIA,
'Atlantic' => DateTimeZone::ATLANTIC,
'Europe' => DateTimeZone::EUROPE,
'Indian' => DateTimeZone::INDIAN,
'Pacific' => DateTimeZone::PACIFIC
@xeoncross
xeoncross / gist:1250888
Created September 29, 2011 14:49 — forked from TheNicholasNick/gist:1040044
node.js SMTP Server
/*
smtpd.js is SMTP server written for node.js
this one works with node 0.4.8 and is standalone
sudo node smtpd.js
MIT License
*/
@xeoncross
xeoncross / apache.conf
Created October 3, 2011 16:21
Basic server vhost
<VirtualHost *:80>
ServerName domain.tld
ServerAdmin [email protected]
DocumentRoot /var/www/domain.tld/
# mod_rewrite rules
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
@xeoncross
xeoncross / classes.grid.html
Created October 8, 2011 16:46
IE7+ Classes CSS grid with margin support
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Demo</title>
<style>
#main{margin:0 auto; width:950px; background-color:#0000FF}
div {float:left; width:70px; height:70px; background-color:red;}
div + div { float:left; margin-left: 10px; width:70px; height:70px; background-color:red;}
@xeoncross
xeoncross / tf-idf.php
Created October 10, 2011 15:51
tf-idf Value (for Keywords)
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
@xeoncross
xeoncross / PasswordHash.php
Created October 20, 2011 16:56
PHPass - BLOWFISH only version
<?php
#
# Portable PHP password hashing framework.
#
# Version 0.3 / genuine.
#
# Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in
# the public domain. Revised in subsequent years, still public domain.
#
# There's absolutely no warranty.
@xeoncross
xeoncross / php.utf8.locale.php
Created October 26, 2011 17:59
PHP UTF-8, Locale, and I18N support
For those that are interested, it seems full support for [locales](http://php.net/manual/en/function.setlocale.php) and i18n in PHP is finally starting to take place.
// Set the current locale to the one the user agent wants
$locale = Locale::acceptFromHttp(getenv('HTTP_ACCEPT_LANGUAGE'));
// Default Locale
Locale::setDefault($locale);
setlocale(LC_ALL, $locale . '.UTF-8');
// Default timezone of server
@xeoncross
xeoncross / $w.js
Created November 2, 2011 18:03 — forked from rmanalan/$w.js
Illustration of a jQuery like object
var $w = function(){
var $w = function(){
return new $w.init;
}
$w.prototype = {
// add all of the methods/props you want accessible as $w().method() or $w().prop here:
init: function(){
console.log('init called');
},