This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function url_std($url) { | |
extract(parse_url($url)); | |
if ($scheme == '') { | |
$scheme = 'http'; | |
} | |
$url = $scheme . "://" . $host . $path; | |
// Append a forward slash if needed | |
if ( !preg_match('|/$|', $url) ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = 'http://computerandu.wordpress.com/2011/06/29/how-to-get-google-invite/'; | |
$emails = scrape_email($url); | |
echo implode($emails, ' '); | |
function scrape_email($url) { | |
if ( !is_string($url) ) { | |
return ''; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// A sample class | |
class Human { | |
$age = 0; | |
function birthday() { | |
$age++; | |
echo 'Happy Birthday!'; | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
''' | |
Ordered dict | |
http://ak.net84.net/projects/python-ordered-dictionary/ | |
Example usage: | |
>>> o = Ordict( ('abc', 123), ('def', '456', 3) ) | |
>>> o['ghi'] = '789' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def expand_list(list_of_lists): | |
list = [] | |
for i in list_of_lists: | |
if type(i) is type([]): | |
i = expand_list(i) | |
for j in i: | |
list.append(j) | |
else: | |
list.append(i) | |
return list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Remove the last unfinished sentence in a paragraph if it contains $min_word_count or less words | |
function remove_unfinished_sentence($paragraph, $min_word_count = 3, $replace = '.') { | |
$min_word_count = $min_word_count > 1 ? $min_word_count : 1; | |
return preg_replace('#(\.\s*([^\s\.]+\s+){0,'.($min_word_count-1).'}([^\s\.]+\s*))$#ms', $replace, $paragraph); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Derived from http://www.cssnewbie.com/example/placeholder-support/ | |
// I needed to capture both "text" and "email" input types. | |
// This adds 'placeholder' to the items listed in the jQuery .support object. | |
jQuery(function() { | |
jQuery.support.placeholder = false; | |
test = document.createElement('input'); | |
if('placeholder' in test) jQuery.support.placeholder = true; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// My take on the JavaScript module pattern | |
// By Aram Kocharyan, 2012. | |
// http://ak.net84.net/ | |
(function($) { | |
window.moduleName = new function() { | |
var base = this; | |
// Internally visible |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adds placeholder to browsers that don't support it (IE) | |
$(document).ready(function() { | |
if(!$.support.placeholder) { | |
var sel = "*[placeholder]"; | |
var addPlaceholders = function () { | |
if ($(this).attr('placeholder') && $(this).val() == "") { | |
$(this).val($(this).attr('placeholder')); | |
$(this).addClass('placeholder'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var loc = window.location; | |
var currentURL = loc.protocol + '//' + loc.host + loc.pathname; |
OlderNewer