Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* @author Arian Stolwijk <http://www.aryweb.nl>
* @license MIT-license
*/
/*
$rss = new Rss_Parser();
// Add an outer click Event to an Element
// http://cpojer.net/blog/Custom_outerClick_event (but this page doesn't exist anymore)
Element.Events.outerClick = {
base: 'click',
condition: function(event){
event.stopPropagation();
return false;
},
$(document.body).addEvent('click', 'a', function(){
alert('hi');
});
@arian
arian / Function.use.js
Created July 28, 2010 10:47
Simple snippet that makes it easy to use namespaced.object.like.this
// Simple snippet that makes it easy to use namespaced.object.like.this
Function.use = function(object, fn, bind, args){
var objects = Array.flatten([object]);
fn.apply(bind, args ? objects.concat(args) : objects);
};
// Cleaned up version of Elements.MultiHighlight.js - http://github.com/subhaze/mootools-elements-multihighlight/blob/master/Source/Elements.MultiHighlight.js
/*
- No need for the this.each
- mouseoverVals and mouseoutVals are no object values of another object anymore (better minification)
- Set the mouseoverVals and mouseoutVals in the mouseenter event (the properties might change after the first call)
if (backgroundColor || foregroundColor){ ... to if (!backgroundColor && !foregroundColor) return this;
- applied MooTools coding style
*/
/*
---
@arian
arian / Whomsy.php
Created August 22, 2010 17:20
A class that fetches data from http://whomsy.com and checks if a domain is available
<?php
// A class that fetches data from http://whomsy.com and checks if a domain is available
class Whomsy {
public $server = 'http://whomsy.com/api/%s';
public $timeout = 5;
public static $AVAILABILITIES = array(
@arian
arian / Clean up Code
Created September 7, 2010 18:57
Trim all trailing whitespace
#!/usr/bin/env php
<?php
$files = explode("\n", shell_exec('git ls-files'));
foreach ($files as $file){
$file = trim(__DIR__ . '/' . $file);
if (!(substr($file, -4) == 'html' || substr($file, -2) == 'js')) continue;
$content = file_get_contents($file);
@arian
arian / Object.copy.js
Created September 20, 2010 14:47
Simple JavaScript function to copy values from one object to another
// Simple JavaScript function to copy values from one object to another
Object.copy = function(from, to, keys){
l = keys.length;
while (l--) to[keys[l]] = from[keys[l]];
return to;
};
var obj1 = {foo: 'bar', temp: 'foo', bar: 'temp'};
@arian
arian / Array.Iterator.js
Created October 18, 2010 16:32
Array.Iterator - Iterate trough your arrays
Array.implement({
i: 0,
current: function(){
return this.valid() ? this[this.i] : null;
},
jump: function(i){
if (i < 0) i = -1;
@arian
arian / Function.prototype.memoize.js
Created December 26, 2010 15:48
Function.prototype.memoize
// A memoize function to store function results of heavy functions
Function.prototype.memoize = function(hashFn, bind){
var memo = {},
self = this;
if (!hashFn) hashFn = function(arg){
return arg;
};