Skip to content

Instantly share code, notes, and snippets.

View pwlin's full-sized avatar
🎧
Listening to Africa by Toto

pwlin pwlin

🎧
Listening to Africa by Toto
View GitHub Profile
@pwlin
pwlin / gist:435647
Created June 12, 2010 11:25
javascript linkify
String.prototype.linkify = function() {
return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
return m.link(m);
});
};
function twitterCallback2(twitters) {
var statusHTML = [];
for (var i=0; i<twitters.length; i++){
var username = twitters[i].user.screen_name;
var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
return '<a href="'+url+'">'+url+'</a>';
}).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
return reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
});
statusHTML.push('<li><span>'+status+'</span> <a style="font-size:85%" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id+'">'+relative_time(twitters[i].created_at)+'</a></li>');
@pwlin
pwlin / fizzbuzz.php
Created June 13, 2010 16:45
FizzBuzz
<?php
// FizzBuzz
for ($i = 1; $i <= 100; $i++)
{
if ($i % 15 == 0)
print "FizzBuzz";
elseif ($i % 3 == 0)
print "Fizz";
elseif ($i % 5 == 0)
print "Buzz";
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxx-x']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
const timelib_tzdb_index_entry timezonedb_idx_builtin[565] = {
{ "Africa/Abidjan" , 0x000000 },
{ "Africa/Accra" , 0x000055 },
{ "Africa/Addis_Ababa" , 0x0000FD },
{ "Africa/Algiers" , 0x000153 },
{ "Africa/Asmara" , 0x00027E },
{ "Africa/Asmera" , 0x0002D4 },
{ "Africa/Bamako" , 0x00032A },
{ "Africa/Bangui" , 0x000395 },
{ "Africa/Banjul" , 0x0003EA },
for (i=0;i<11;i++){
setTimeout(function(x){return function(){alert(x)};}(i),1000);
}
function(x){return function(){alert(x)};}(i)
function func(x) {return function(){alert(x)};} // defines the function
func(i); // runs the function
500 INTERNAL SERVER ERROR
Sorry, something went wrong.
A team of highly trained monkeys has been dispatched to deal with this situation.
Also, please include the following information in your error report:
@pwlin
pwlin / gist:485717
Created July 22, 2010 08:23
php Remove Excess White Space
# Remove Excess White Space
preg_replace('/\s+/xms', ' ', trim($str))
@pwlin
pwlin / gist:506131
Created August 3, 2010 10:00
javascript random number
function RandomNumber(n1,n2){
return(Math.floor(Math.random()*(n2-n1))+n1);
}
n=RandomNumber(20,80);
@pwlin
pwlin / gist:514076
Created August 8, 2010 14:19
X-Frame-Options response header
X-FRAME-OPTIONS: DENY (or SAMEORIGIN)
X-Content-Security-Policy: allow 'self'; frame-ancestors 'none'