Skip to content

Instantly share code, notes, and snippets.

View mistermarco's full-sized avatar

Marco Wise mistermarco

  • Stanford University
View GitHub Profile
@mistermarco
mistermarco / Twitterify.php
Last active September 5, 2015 15:55
Twitterify
// Add links to URLs, link usernames to Twitter timelines, hash tags to searches
// From: http://www.snipe.net/2009/09/php-twitter-clickable-links/
function twitterify($ret) {
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
$ret = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $ret);
$ret = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $ret);
return $ret;
}
# skip already rewritten URIs, unless it's a request to use
# a non-detected page
RewriteCond %{REQUEST_URI} ^/(js|css|favicon.ico)
RewriteRule .* - [L]
RewriteCond %{QUERY_STRING} !device_class=(smart|feature|tablet|desktop)
RewriteCond %{REQUEST_URI} ^/(smart|feature|tablet|desktop)
RewriteRule .* - [L,E=DEVICE_CLASS:%1]
@mistermarco
mistermarco / gist:1226023
Created September 19, 2011 05:27
Display random image
#!/usr/bin/perl -wT
use strict;
use CGI;
use CGI::Carp;
use constant BUFFER_SIZE => 4_096;
use constant IMAGE_DIRECTORY => "/usr/local/apache/data/random-images";
my $q = new CGI;
@mistermarco
mistermarco / Git Tags
Created October 3, 2011 23:17
Create git tags / automatic download
# this creates a tag, which creates a download package on the downloads page
git tag -a v3.x-beta2
git push --tags origin
@mistermarco
mistermarco / random.pl
Created October 21, 2011 05:29
Create random password
#! /usr/bin/perl
# ./pwgen -c 64 | pbcopy
use Getopt::Std;
sub HELP_MESSAGE() {
my $fh = shift;
printf $fh <<END_HELP;
Usage: $0 \[-c\] \[-n\] \[-y\] \[length\]
@mistermarco
mistermarco / page_count.pl
Created November 30, 2011 20:37
Count "pages" in a file, given a template size and an estimated number of characters per page.
#!/usr/bin/perl
use File::Find;
use Getopt::Long;
use Pod::Usage;
use Term::ANSIColor;
use strict;
my $default_overhead_size = 2000;
my $default_page_size = 2500;
@mistermarco
mistermarco / sites.test.php
Created July 25, 2012 08:17
Sites/People test
<pre>
<?php
$site_name = exec('whoami');
echo "Starting Testing...\n";
echo 'Running as ' . $site_name . "\n";
echo 'Server that responded: ' . exec('uname -a') . "\n\n";
@mistermarco
mistermarco / pwgen.pl
Created December 6, 2012 23:54
Generate Passwords
#! /usr/bin/perl
use Getopt::Std;
sub HELP_MESSAGE() {
my $fh = shift;
printf $fh <<END_HELP;
Usage: $0 \[-c\] \[-n\] \[-y\] \[length\]
Create a password length characters long; length defaults to 8
@mistermarco
mistermarco / table_class.js
Created October 11, 2013 01:21
Add the table class to tables (Bootstrap3)
$("table").addClass('table');
@mistermarco
mistermarco / getting_started.sh
Created October 11, 2013 05:11
Getting started with the blog
git clone git@github.com:mistermarco/mistermarco.github.io.git
cd _posts
vi 2013-11-03-new-post.markdown
jekyll serve --watch