Skip to content

Instantly share code, notes, and snippets.

View rickard2's full-sized avatar

Rickard Andersson rickard2

View GitHub Profile
@rickard2
rickard2 / gist:1631954
Created January 18, 2012 08:23
Replace urls with links
<?php
/**
* Parse a string and match probable URLs, and replace them with clickable links
* @param $string
* @return string
*/
function create_links($string) {
$pattern = array(
'/(?<![\/"])(https?:\/\/[a-z0-9.\-]+\.[a-z]{2,6}\/?([a-z0-9?=&%#:,.~_+\/\-]+)?)/i',
$email = isset($comment->comment_author_email) ? $comment->comment_author_email : null;
if ( !$email && !is_integer($id_or_email) ) {
$email = $id_or_email;
}
if ( !$email && is_integer($id_or_email) ) {
$user = get_userdata($id_or_email);
$email = $user->user_email;
}
@rickard2
rickard2 / gist:2357953
Created April 11, 2012 08:37
interface
<?php
interface iA {
function a();
}
class Alpha implements iA {
@rickard2
rickard2 / gist:2390740
Created April 15, 2012 07:35
EmberJS Data handling
window.App = Ember.Application.create({});
Item = Ember.Object.extend({
});
App.ListController = Ember.ArrayController.create({
content: [],
currentItem: null,
@rickard2
rickard2 / gist:2499527
Created April 26, 2012 13:24
jQuery and native functions
// Works just fine
$(document).on('click', '#print', function() { window.print() });
// Doesnt work
$(document).on('click', '#print', window.print );
@rickard2
rickard2 / gist:2717746
Created May 17, 2012 09:31
WordPress HTML test
<p>The purpose of this HTML is to help determine what default settings are with CSS and to make sure that all possible HTML Elements are included in this HTML so as to not miss any possible Elements when designing a site.</p>
<hr />
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
<p><small><a href="#wrapper">[top]</a></small></p>
<hr />
RewriteEngine On
RewriteRule .? - [F,L]
@rickard2
rickard2 / gist:3038841
Created July 3, 2012 10:02
vhost config
<Directory ~ "/www/example.com/webroot/(media|generated)/">
php_flag engine off
<FilesMatch "\.(php|inc)$">
Order allow,deny
Deny from all
</FilesMatch>
</Directory>
@rickard2
rickard2 / gist:3047041
Created July 4, 2012 12:21
OpenCart IE9 HTML mail bug fix
function fetchData( $elements ) {
var data = {};
$elements.each(function() {
var $this = $(this),
name = $this.attr('name'),
value = $this.val();
if ( name.substr(-2, 2) === '[]' ) {
@rickard2
rickard2 / gist:3101176
Created July 12, 2012 21:32
Drupal to WordPress comment migration
INSERT INTO wp_comments (comment_ID, comment_post_ID, comment_date, comment_content, comment_parent, comment_author, comment_author_email, comment_author_url, comment_approved)
SELECT
cid AS comment_ID,
nid AS comment_post_ID,
FROM_UNIXTIME(TIMESTAMP) AS comment_date,
comment AS comment_content,
IF( LENGTH(thread) = 3, 0, ( SELECT cid
FROM drupal.comments c2
WHERE c2.nid = c1.nid
AND c2.thread = CONCAT( SUBSTR( c1.thread, 1, LENGTH(c1.thread) - 4 ), '/' )