Skip to content

Instantly share code, notes, and snippets.

View xeoncross's full-sized avatar

David Pennington xeoncross

View GitHub Profile
@xeoncross
xeoncross / fixEvent.js
Created November 4, 2011 18:54
Fix a JavaScript event
function fixEvent(event)
{
if (!event) var event = window.event;
// Fix target property, if necessary (IE 6/7/8 & Safari2)
if ( ! event.target)
{
event.target = originalEvent.srcElement || document;
}
@xeoncross
xeoncross / bijective.php
Created November 4, 2011 20:12
URL shortener
<?php
class Bijective
{
public $dictionary = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
public function __construct()
{
$this->dictionary = str_split($this->dictionary);
}
@xeoncross
xeoncross / Email.php
Created November 10, 2011 20:14 — forked from anonymous/Email.php
<?php
function Email($name, $from, $to, $subject, $message, $bcc = null, $attachments = null)
{
ini_set('SMTP', 'localhost');
ini_set('sendmail_from', $from);
$name = filter_var($name, FILTER_SANITIZE_STRING);
$from = filter_var($from, FILTER_SANITIZE_EMAIL);
$subject = filter_var($subject, FILTER_SANITIZE_STRING);
@xeoncross
xeoncross / benchmark.php
Created November 18, 2011 20:06
Simple PHP benchmark class
<?php
define('SYSTEM_START_TIME', microtime(TRUE));
define('SYSTEM_START_MEMORY', memory_get_usage());
register_shutdown_function('_usage');
function _usage()
{
if(PHP_SAPI !== 'cli')
@xeoncross
xeoncross / postgres-install
Created November 21, 2011 21:06 — forked from mikeclarke/postgres-install
Basic PostgreSQL install
# Install the postgres packages
yum install postgresql postgresql-server
# Configure postgresql to start automatically on boot
chkconfig postgresql on
# Stat posgresql
service postgresql start
# Switch to postgres user (required to make initial connection to postgresql with default configuration)
su - postgres
# Make initial connection to the database to test connectivity
psql -d template1 -U postgres
@xeoncross
xeoncross / i.full.php
Created December 6, 2011 19:23
A simple, easy-to-type, default-value, input class for PHP
<?php
/**
* Here is a non-magic-method version for those that need better auto-complete and faster access times.
* It also filters the input to be valid UTF-8 just when needed thanks to phunction.
*/
class input
{
public static $encoding = 'UTF-8';
public static function server($key, $default = NULL, $control = true)
@xeoncross
xeoncross / grid-ie.css
Created December 17, 2011 02:09
Responsive 2, 3, & 4 column grid
/* IE 6/7/8 (1024px+) */
.superflous { display: block; }
.container { margin: 0 auto; width: 960px; }
.third, .twothirds, .forth, .half, .threeforths, .full { display: inline; float: left; margin: 0 0 0 24px; }
.first, .full { margin: 0;}
.forth { width: 222px; }
.third { width: 304px; }
.half { width: 468px; }
@xeoncross
xeoncross / LICENSE.txt
Created December 17, 2011 19:44 — forked from jed/LICENSE.txt
bind and unbind events
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@xeoncross
xeoncross / xss.encode.php
Created December 18, 2011 20:49
Stop dangerous HTML using different criteria for editing and display. This is a very basic example of how easy it is to encoded text so you don't have to remove dangerous stuff!
<?php
// @see http://stackoverflow.com/questions/8419038/what-is-the-correct-way-to-detect-whether-string-inputs-contain-html-or-not
// Lets disable HTML/XML for our safety
//header('Content-Type: text/plain');
$text_mode = false;
# Get the hackers Cheat Sheet
# $ wget http://ha.ckers.org/xssAttacks.xml
@xeoncross
xeoncross / f.php
Created December 20, 2011 22:30
1kB Forum with added IP logging
<?checkdnsrr(join('.',array_reverse(explode('.',$p=getenv('REMOTE_ADDR')))).".opm.tornevall.org","A")&&die('Bad Bot');mysql_connect(0,'root','');mysql_select_db('d');extract($_REQUEST);$v=(int)@$v;$i=0;$q='mysql_query';$f='mysql_fetch_row';$n='mysql_num_rows';$x='<input type="';$s="SELECT*FROM";$t='CREATE TABLE IF NOT EXISTS t(i INT AUTO_INCREMENT,a INT,b TEXT,KEY(i))';$h='htmlspecialchars';$q($t);$q(strtr($t,'t','p'));$l=' ORDER BY';$o='';$u='INSERT INTO';$c="b)VALUES(";if(@$b){if(!$v)$q("$u t(a,$c INET_ATON('$p'),'$e')");$v=max($v,mysql_insert_id());$q("$u p(a,$c'$v','$b')");}if($v){$t=$q("$s p WHERE a=$v$l i");echo'<a href="f.php">Back</a>';for(;$i<$n($t);++$i){$r=$f($t);echo'<hr/>'.nl2br($h($r[2]));}}else{$t=$q("$s t$l-i");for(;$i<$n($t);++$i){$r=$f($t);echo'<a href="f.php?v='.$r[0].'">'.$h($r[2]).'</a><br/>';}$o='Title:'.$x.'text"name="e"/><br/>';}echo'<hr/>Post:<form method="post">'.$x.'hidden"name="v"value="'."$v\"/>$o<textarea name=\"b\"></textarea>$x";?>submit"name="w"value="Post"/></form>