Skip to content

Instantly share code, notes, and snippets.

<?php
// Adding some stupid comments
$system = dirname(dirname(__FILE__));
ini_set('include_path', "$system/include");
require_once 'Solar.php';
Solar::start("$system/config/Solar.config.php");
$campaigns = Solar::factory('Victoria_Model_Campaigns');
$struct = $campaigns->fetch(1);
var some = function (callback) {
callback();
foo();
};
<?php
/**
*
* Runs after _forward
*
* @return void
*
*/
protected function _postRun()
{
(?xi)
\b
( # Capture 1: entire matched URL
(?:
[a-z][\w-]+: # URL protocol and colon
(?:
/{1,3} # 1-3 slashes
| # or
[a-z0-9%] # Single letter or digit or '%'
# (Trying not to match e.g. "URI::Escape")
@anttih
anttih / Replace URIs with anchor tags in a string
Created February 4, 2010 18:34
Code to replace URIs in a string with HTML anchors. Uses Grubers regex with some extra captures.
function hrefs2links(text) {
// Uses Grubers regex with some extra captures
var urire = /\b(?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|(www\d{0,3}[.]))((?:[^\s()<>]+|\([^\s()<>]+\))+(?:\([^\s()<>]+\)|[^`!()\[\]{};:'".,<>?«»“”‘’\s]))/g;
// replace URIs with HTML anchors
return text.replace(urire, '<a href="$&">$1$2</a>');
}
var text = hrefs2links("Check out http://example.com");
/*jslint regexp: false*/
"use strict";
function hrefs2links(text) {
// Uses Grubers regex with some extra captures
var urire = /\b(?:[a-z][\w\-]+:(?:\/{1,3}|[a-z0-9%])|(www\d{0,3}[.]))((?:[^\s()<>]+|\([^\s()<>]+\))+(?:\([^\s()<>]+\)|[^`!()\[\]{};:'".,<>?«»“”‘’\s]))/g;
// replace URIs with HTML anchors
return text.replace(urire, '<a href="$&">$1$2</a>');
}
@anttih
anttih / Assert.io
Created November 4, 2010 18:40
Tests for Object assert
Protos AssertionException := Exception clone
Object do(
assert := method(v, m,
if(true != v,
m ifNil(m = "true != (#{ call argAt(0) })" interpolate)
AssertionException raise(m)
)
)
@anttih
anttih / gist:738010
Created December 12, 2010 12:36
Modules in Io (closure problem)
# I'd like the inner object's methods to have access to Module's `inside` slot.
# The new lexicalDo won't cut it since the proto is long gone when the
# block/method gets called.
Module := Object clone do(
inside := 2
Test := Object clone lexicalDo(
num := method(inside)
numblock := block(inside) setIsActivatable(true)
(context
(lambda (test)
(test "hello")))
;; I would like this to transform to the above
(group
(test "hello"))
@anttih
anttih / to-html.ls
Created August 28, 2012 11:52
Simple templating in LiveScript
toHtml = (x) ->
if $.isArray x
if typeof x[0] is not \string then return map(toHtml, x).join('')
switch x.length
case 3
"<#{x[0]} #{objToAttrs(x[1])}>#{toHtml(x[2])}</#{x[0]}>"
case 2
"<#{x[0]}>#{toHtml(x[1])}</#{x[0]}>"
case 1
"<#{x[0]}/>"