Skip to content

Instantly share code, notes, and snippets.

@0xnbk
0xnbk / font_resizing.js
Created September 13, 2010 04:18
Font resizing
$(document).ready(function(){
// Reset Font Size
var originalFontSize = $('html').css('font-size');
$(".resetFont").click(function(){
$('html').css('font-size', originalFontSize);
});
// Increase Font Size
$(".increaseFont").click(function(){
var currentFontSize = $('html').css('font-size');
var currentFontSizeNum = parseFloat(currentFontSize, 10);
@0xnbk
0xnbk / disable_right_click.js
Created September 13, 2010 04:18
Disable right-click contextual menu
$(document).ready(function(){
$(document).bind("contextmenu",function(e){
return false;
});
});
@0xnbk
0xnbk / abc.php
Created September 13, 2010 04:32
Highlight specific words in a phrase
<?php
function highlight($sString, $aWords) {
if (!is_array ($aWords) || empty ($aWords) || !is_string ($sString)) {
return false;
}
$sWords = implode ('|', $aWords);
return preg_replace ('@\b('.$sWords.')\b@si', '<strong style="background-color:yellow">$1</strong>', $sString);
}
?>
@0xnbk
0xnbk / automatic_password.php
Created September 13, 2010 04:33
Automatic password creation
<?php
function generatePassword($length=9, $strength=0) {
$vowels = 'aeuy';
$consonants = 'bdghjmnpqrstvz';
if ($strength >= 1) {
$consonants .= 'BDGHJLMNPQRSTVWXZ';
}
if ($strength >= 2) {
$vowels .= "AEUY";
}
@0xnbk
0xnbk / short_url.php
Created September 13, 2010 04:35
Get short urls for Twitter
<?php
function getTinyUrl($url) {
return file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
}
?>
@0xnbk
0xnbk / calculate_age.php
Created September 13, 2010 04:36
Calculate age using date of birth
<?php
function age($date){
$year_diff = '';
$time = strtotime($date);
if(FALSE === $time){
return '';
}
$date = date('Y-m-d', $time);
list($year,$month,$day) = explode("-",$date);
@0xnbk
0xnbk / calculate_exec_time.php
Created September 13, 2010 04:37
Calculate execution time
<?php
//Create a variable for start time
$time_start = microtime(true);
// Place your PHP/HTML/JavaScript/CSS/Etc. Here
//Create a variable for end time
$time_end = microtime(true);
//Subtract the two times to get seconds
$time = $time_end - $time_start;
@0xnbk
0xnbk / maintanance_mode.php
Created September 13, 2010 04:43
Maintenance mode with PHP
<?php
function maintenance($mode = FALSE){
if($mode){
if(basename($_SERVER['SCRIPT_FILENAME']) != 'maintenance.php'){
header("Location: http://example.com/maintenance.php");
exit;
}
}else{
if(basename($_SERVER['SCRIPT_FILENAME']) == 'maintenance.php'){
header("Location: http://example.com/");
<link href="/stylesheet.css?<?php echo time(); ?>" rel="stylesheet" type="text/css" /&glt;
@0xnbk
0xnbk / abc.php
Created September 13, 2010 06:02
Add (th, st, nd, rd, th) to the end of a number
<?php
function make_ranked($rank) {
$last = substr( $rank, -1 );
$seclast = substr( $rank, -2, -1 );
if( $last > 3 || $last == 0 ) $ext = 'th';
else if( $last == 3 ) $ext = 'rd';
else if( $last == 2 ) $ext = 'nd';
else $ext = 'st';
if( $last == 1 && $seclast == 1) $ext = 'th';