Untitled XML (28-Jul @ 18:12)

remy

Syntax Highlighted Code

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xml>
  3. [EACH ITEM]
  4.   <project id="{{VALUE.PROJECT}}">
  5. [17 more lines...]

Plain Code

<?xml version="1.0" encoding="UTF-8"?>
<xml>
[EACH ITEM]
  <project id="{{VALUE.PROJECT}}">
    <rank>{{VALUE.PROJECT_RANK}}</rank>
    <featured>{{VALUE.FEATURED}}</featured>
    <thumbnail>{{VALUE.THUMBNAIL}}</thumbnail>
    <ratings>[IF defined(VALUE.RATINGS)][HTMLINSERT VALUE.RATINGS][ELSE]0[END IF]</ratings>
    <testings>[IF defined(VALUE.TESTINGS)][HTMLINSERT VALUE.TESTINGS][ELSE]0[END IF]</testings>
    <last_update>[IF defined(VALUE.LAST_UPDATE)][HTMLINSERT VALUE.LAST_UPDATE][ELSE]0[END IF]</last_update>
    <level_required>[IF defined(VALUE.LEVEL_REQUIRED)]{{VALUE.LEVEL_REQUIRED}}[ELSE]0[END IF]</level_required>
    <asset_count>
      <game>{{VALUE.N_GAME}}</game>
      <image>{{VALUE.N_IMAGE}}</image>
      <audio>{{VALUE.N_AUDIO}}</audio>
      <video>{{VALUE.N_VIDEO}}</video>
    </asset_count>
    <title>[HTMLINSERT VALUE.TITLE]</title>
    <description>[HTMLINSERT VALUE.DESCRIPTION]</description>
  </project>
[END EACH]
</xml>

Untitled HTML (18-Jul @ 15:31)

remy

Syntax Highlighted Code

  1.     <td>
  2.         <img src="{URLTOTHUMBNAIL}" />
  3.         <span class="level">level {REQUIRED_LEVEL}</span>
  4. [12 more lines...]

Plain Code

<tr>
    <td>
        <img src="{URLTOTHUMBNAIL}" />
        <span class="level">level {REQUIRED_LEVEL}</span>
    </td>
    <td>
        <span class="title">{PROJECT_TITLE}</span>
        <ul class="assetTypesSmall">
            <!-- for each asset type --> 
            <li class="{ASSET_TYPE}"><span>{ASSET_TYPE}</span></li>
        </ul>
    </td>
    <!-- Remy needs to discuss this line with James -->
    <td><div class="power powerSmall"><span class="completed assets3"><em>3</em></span><em> completed with </em><span class="todo assets4"><em>4</em></span><em> remaining</em></div>
    </td>
    <td>{AVERAGE_RATING}</td>
</tr>

Block rotator (10-Jul @ 16:28)

remy

Syntax Highlighted Code

  1. $.fn.rotate = function (delay) {
  2.     var rotators = this,
  3.         n = this.length,
  4.         current = 0,
  5. [10 more lines...]

Plain Code

$.fn.rotate = function (delay) {
    var rotators = this, 
        n = this.length, 
        current = 0,
        timer = null;

    rotators.hide().eq(current).show();
    timer = setInterval(function () {
        current++;
        if (current == n) current = 0;
        rotators.hide().eq(current).show();
    }, delay);
    
    return rotators;
};

Editable (8-Jul @ 10:45)

remy

Syntax Highlighted Code

  1. javascript:document.body.contentEditable='true'; document.designMode='on'; void 0;
  2.  

Plain Code

javascript:document.body.contentEditable='true'; document.designMode='on'; void 0;

addEvent (26-Jun @ 23:36)

remy

Syntax Highlighted Code

  1. addEvent = (function () {
  2.     return document.body.addEventListener ? function (e, ev, fn) {
  3.         e.addEventListener(ev, fn, false);
  4.     } : function () {
  5. [2 more lines...]

Plain Code

addEvent = (function () {
    return document.body.addEventListener ? function (e, ev, fn) {
        e.addEventListener(ev, fn, false);
    } : function () {
        e.attachEvent("on" + ev, fn);
    };
})();

DateJS throttling (21-Jun @ 13:46)

remy

Syntax Highlighted Code

  1. function delay(fn, time) {
  2.     return function () {
  3.         var t = this;
  4.  
  5. [27 more lines...]

Plain Code

function delay(fn, time) {
    return function () {
        var t = this;

        if (fn.timer) {
            clearTimeout(fn.timer);
        }
        fn.timer = setTimeout(function () {
            fn.apply(t);
        }, time);
    };
}

$(function () {
    var humanDate = $('#human_date').keyup(delay(function () {
        if (humanDate.data('prevValue') == humanDate.val()) return;
        humanDate.data('prevValue', humanDate.val());

        var date = '';
        try {
            date = Date.parse(this.value).toString("d-MMMM yyyy"); // note different formats available
        } catch (e) {
            date = 'Sorry, I cant do that date';
        }

        $('#info').html(''); // error notice field
        $('#actualDate').text(date); // date selected (i.e. in plain text)
    }, 200));

    // force a trigger
    humanDate.keyup();
});

Untitled HTML (19-Jun @ 13:03)

remy

Syntax Highlighted Code

  1. <img class="plain floatRight" alt="Telefono" src="/images/telefono.gif"/>
  2. <p style="margin-top: 22px;"> Per saperne di pi  </p>
  3.  

Plain Code

<img class="plain floatRight" alt="Telefono" src="/images/telefono.gif"/>
<p style="margin-top: 22px;"> Per saperne di pi  </p>

Untitled JavaScript (13-Jun @ 17:33)

remy

Syntax Highlighted Code

  1. $.fn.codaSlider = function (options, scrollOptions) {
  2.     var defaults = {
  3.         horizontal : true,
  4.         // etc
  5. [13 more lines...]

Plain Code

$.fn.codaSlider = function (options, scrollOptions) {
    var defaults = {
        horizontal : true,
        // etc 
        navigation : '.navigation a' // required
    };
    
    var settings = $.extend({}, defaults, options);
    
    var ret = this.each(function () {
        // do coda business
    };

    $.localScroll(scrollSettings); // where does scrollSettings derive from?
    return ret; 
} 

center align (9-Jun @ 09:51)

remy

Syntax Highlighted Code

  1. .center {
  2.   display: block;
  3.   margin: 0 auto;
  4. }

Plain Code

.center {
  display: block;
  margin: 0 auto;
}

Code Igniter - load a model from a model (7-Jun @ 19:11)

remy

Syntax Highlighted Code

  1. // from within your model
  2.  
  3. $CI =& get_instance();
  4. $CI->load->model('other');
  5. [1 more lines...]

Plain Code

// from within your model

$CI =& get_instance();
$CI->load->model('other');

$event = $CI->Other->method($var);

Sample hCalendar (28-May @ 11:26)

remy

Syntax Highlighted Code

  1. <dl class="vevent">
  2.     <dt>Game</dt>
  3.     <dd class="summary">Grand Theft Auto: Liberty City Stories (PSP)</dd>
  4.     <dt>Where</dt>
  5. [7 more lines...]

Plain Code

<dl class="vevent">
    <dt>Game</dt>
    <dd class="summary">Grand Theft Auto: Liberty City Stories (PSP)</dd>
    <dt>Where</dt>
    <dd><span class="location">Work</span>, <abbr title="2008-05-28T12:30:00-00:00">Wednesday 28th May @ 12:30PM GMT</abbr></dd>
    <dt>Type</dt>
    <dd>Multiplayer</dd>
    <dt>Added by</dt>
    <dd><a href="/people/chrismahon">Chrismahon</a></dd>
</dl>

Arguments to array (28-May @ 00:54)

remy

Syntax Highlighted Code

  1. var args = Array.prototype.slice.apply(arguments);

Plain Code

var args = Array.prototype.slice.apply(arguments);

Untitled Diff (26-May @ 21:26)

remy

Syntax Highlighted Code

  1. Index: /Users/remy/Sites/test.com/htdocs/jqueryjs/jquery/src/selector.js
  2. ===================================================================
  3. --- /Users/remy/Sites/test.com/htdocs/jqueryjs/jquery/src/selector.js    (revision 5696)
  4. +++ /Users/remy/Sites/test.com/htdocs/jqueryjs/jquery/src/selector.js    (working copy)
  5. [10 more lines...]

Plain Code

Index: /Users/remy/Sites/test.com/htdocs/jqueryjs/jquery/src/selector.js
===================================================================
--- /Users/remy/Sites/test.com/htdocs/jqueryjs/jquery/src/selector.js    (revision 5696)
+++ /Users/remy/Sites/test.com/htdocs/jqueryjs/jquery/src/selector.js    (working copy)
@@ -336,7 +336,7 @@
                 for ( var i = 0, rl = r.length; i < rl; i++ ) {
                     var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ];
 
-                    if ( z == null || /href|src|selected/.test(m[2]) )
+                    if ( z == null || /style|href|src|selected/.test(m[2]) )
                         z = jQuery.attr(a,m[2]) || '';
 
                     if ( (type == "" && !!z ||

getQuery (24-May @ 00:16)

remy

Syntax Highlighted Code

  1. function getQuery(s) {
  2.     var query = {};
  3.    
  4.     s.replace(/\b([^&=]*)=([^&=]*)\b/g, function (m, a, d) {
  5. [9 more lines...]

Plain Code

function getQuery(s) {
    var query = {};
    
    s.replace(/\b([^&=]*)=([^&=]*)\b/g, function (m, a, d) {
        if (typeof query[a] != 'undefined') {
            query[a] += ',' + d;
        } else {
            query[a] = d;
        }
    });
    
    return query;
}

Untitled JavaScript (16-May @ 08:26)

remy

Syntax Highlighted Code

  1. $.ajax({
  2.     'url' : settings.url,
  3.     'dataType' : 'json',
  4.     'data' : { 'tag' : currentTag.tag },
  5. [7 more lines...]

Plain Code

$.ajax({
    'url' : settings.url,
    'dataType' : 'json',
    'data' : { 'tag' : currentTag.tag },
    'async' : false, // wait until this is ajax hit is complete before continue
    'success' : function (m) {
        matches = m.matches;
    }
});


Untitled HTML (10-May @ 12:09)

remy

Syntax Highlighted Code

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. [19 more lines...]

Plain Code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
    <div id="twitters">
    <p><img src="/resources/images/ajaxload.gif" /> Connecting to live social updates...</p>
    </div>
    <script src="/include/scripts/twitter.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" charset="utf-8">
        getTwitters('tweet', { 
          id: 'matbe81', 
          count: 1, 
          enableLinks: true, 
          ignoreReplies: true, 
          clearContent: true,
          template: '<img src="%user_profile_image_url%"/> %text% <a href="http://twitter.com/%user_screen_name%/statuses/%id%/">%time%</a><a href="http://twitter.com/statuses/user_timeline/%user_screen_name%.rss"><img src="/resources/icons/feed-icon-12x12.gif" border="0"/></a>'
        });
    </script>
</body>
</html>

Button background images (1-May @ 18:36)

remy

Syntax Highlighted Code

  1. input.button {
  2.   background: transparent url(/images/button.jpg) no-repeat;
  3.   border: none;
  4.   cursor: pointer;
  5. [3 more lines...]

Plain Code

input.button {
  background: transparent url(/images/button.jpg) no-repeat;
  border: none;
  cursor: pointer;
  /* height and width of real image */
  height: 28px !important;
  width: 69px !important;  
}

Generic menu layout (1-May @ 08:29)

remy

Syntax Highlighted Code

  1. /** generic menu layout */
  2. ul.navigation {
  3.   list-style: none;
  4.   margin: 0;
  5. [16 more lines...]

Plain Code

/** generic menu layout */
ul.navigation {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}

ul.navigation li {
  display: block;
  float: left;
  margin: 0;
  padding: 0;
}

ul.navigation li.right {
  right: 0;
  position: absolute;
}

Untitled JavaScript (28-Apr @ 12:35)

remy

Syntax Highlighted Code

  1. $(this).parents('form:first');

Plain Code

$(this).parents('form:first');

Untitled JavaScript (25-Apr @ 17:36)

remy

Syntax Highlighted Code

  1. getTwitters('tweet', {
  2.   id: 'thobu',
  3.   count: 3,
  4.   enableLinks: true,
  5. [5 more lines...]

Plain Code

getTwitters('tweet', { 
  id: 'thobu', 
  count: 3, 
  enableLinks: true, 
  ignoreReplies: true, 
  clearContents: true,
  template: '"%text%" <a href="http://twitter.com/%user_screen_name%/statuses/%id%/" onclick="javascript:pageTracker._trackPageview' + 
    "('/outbound/article/http://twitter.com/%user_screen_name%/statuses/%id%/');" + 
    '">%time%</a>'
});

Generate dummy file (22-Apr @ 11:42)

remy

Syntax Highlighted Code

  1. dd if=/dev/zero of=dummy.file bs=1000000 count=1

Plain Code

dd if=/dev/zero of=dummy.file bs=1000000 count=1

jQuery.requires (18-Apr @ 10:50)

remy

Syntax Highlighted Code

  1. jQuery.extend({
  2.     compareVersions : function (have, require) {
  3.         if (typeof require == 'undefined') {
  4.             require = have;
  5. [34 more lines...]

Plain Code

jQuery.extend({
    compareVersions : function (have, require) {
        if (typeof require == 'undefined') {
            require = have;
            have = jQuery.fn.jquery;
        }
        
        function parts(val) {
            // Expecting following format 1.2.3rc1, 1.2.4a, etc.
            return val.replace(/[a-z]+/i, function(m) { 
                return '.' + (m == 'pre' ? '0pre' : m);
            }).split('.');
        }
        
        if (require == have) return 0;
        
        var latest = parts(have), 
            required = parts(require), 
            i = 0;

        while (latest[i] && required[i]) {
            if (latest[i] < required[i]) {
                return -1;
            } else if (latest[i] > required[i]) {
                return 1;
            }
            i++;
        }

        return (latest[i]
                ? (/^d/.test(latest[i]) ? 1 : -1)
                : (/^d/.test(required[i]) ? -1 : 1));
    },
    hasVersion : function() { 
        var ok = this.compareVersions.apply(this, arguments);
        return (ok === 0 || ok === 1); 
    }
});

Untitled JavaScript (16-Apr @ 10:28)

remy

Syntax Highlighted Code

  1. $(function () {
  2.     var max = 8;
  3.     var min = 1;
  4.     var cur = 5;
  5. [44 more lines...]

Plain Code

$(function () {
    var max = 8;
    var min = 1;
    var cur = 5;
    
    var up = $('#up').click(function () {
        var moved = false;
        if (cur != min) {
            cur--;
            moved = true;
        }
        
        console.log(cur);
        $('ul').trigger('redraw', [moved]);
        return false;
    });
    
    var down = $('#down').click(function () {
        var moved = false;
        if (cur != max) {
            cur++;
            moved = true;
        }

        console.log(cur);
        $('ul').trigger('redraw', [moved]);
        return false;
    });
    
    $('ul').bind('redraw', function (moved) {
        // helps us optimise
        if (moved) {
            if (cur == min) {
                up.html('up - disabled');
            } else {
                up.html('up');
            }

            if (cur == max) {
                down.html('down - disabled');
            } else {
                down.html('down');
            }

            $('li', this).slice(0, cur).show().end().slice(cur).hide();
        }
    }).trigger('redraw', [true]);
});

sleep (15-Apr @ 07:55)

remy

Syntax Highlighted Code

  1. function sleep(milliseconds) {
  2.   var start = new Date().getTime();
  3.   for (var i = 0; i < 1e7; i++) {
  4.     if ((new Date().getTime() - start) > milliseconds){
  5. [4 more lines...]

Plain Code

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

Password Generator (14-Apr @ 11:48)

remy

Syntax Highlighted Code

  1. function generatePassword(limit, inclNumbers) {
  2.     var vowels = 'aeiou'.split('');
  3.     var constonants = 'bcdfghjklmnpqrstvwxyz'.split('');
  4.     var word = '', i, num;
  5. [19 more lines...]

Plain Code

function generatePassword(limit, inclNumbers) {
    var vowels = 'aeiou'.split('');
    var constonants = 'bcdfghjklmnpqrstvwxyz'.split('');
    var word = '', i, num;

    if (!limit) limit = 8;

    for (i = 0; i < (inclNumbers ? limit - 3 : limit); i++) {
        if (i % 2 == 0) { // even = vowels
            word += vowels[Math.floor(Math.random() * 4)]; 
        } else {
            word += constonants[Math.floor(Math.random() * 20)];
        } 
    }

    if (inclNumbers) {
        num = Math.floor(Math.random() * 99) + '';
        if (num.length == 1) num = '00' + num;
        else if (num.length == 2) num = '0' + num;
        word += num;
    }

    return word.substr(0, limit);
}

Password Generator (14-Apr @ 11:13)

remy

Syntax Highlighted Code

  1. function GeneratePassword($limit = 8) {
  2.     $vowels = array('a', 'e', 'i', 'o', 'u');
  3.     $const = array('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z');
  4.  
  5. [14 more lines...]

Plain Code

function GeneratePassword($limit = 8) {
    $vowels = array('a', 'e', 'i', 'o', 'u');
    $const = array('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z');

    $word = '';

    for ($i = 0; $i < ($limit - 3); $i++) {
        if ($i % 2 == 0) { // even = vowels
            $word .= $vowels[rand(0, 4)]; 
        } else {
            $word .= $const[rand(0, 20)];
        } 
    }

    $num = rand(0,999);
    str_pad($num, 3, '0', STR_PAD_LEFT);

    return substr($word . $num, 0, $limit);
}

JavaScript namespace (12-Apr @ 12:49)

remy

Syntax Highlighted Code

  1. String.prototype.namespace = function(separator) {
  2.     var ns = this.split(separator || '.'), p = window;
  3.     for (i = 0; i < ns.length; i++) {
  4.         p = p[ns[i]] = p[ns[i]] || {};
  5. [1 more lines...]

Plain Code

String.prototype.namespace = function(separator) {
    var ns = this.split(separator || '.'), p = window;
    for (i = 0; i < ns.length; i++) {
        p = p[ns[i]] = p[ns[i]] || {};
    }
};

Untitled Bash (12-Apr @ 12:48)

remy

Syntax Highlighted Code

  1. mysql $DB -u$USERNAME -p$PASSWORD -e 'show tables like "$LIKE%"' |
  2. grep -v Tables_in |
  3. xargs mysqldump --add-drop-table $DB -u$USERNAME -p$PASSWORD

Plain Code

mysql $DB -u$USERNAME -p$PASSWORD -e 'show tables like "$LIKE%"' | 
grep -v Tables_in | 
xargs mysqldump --add-drop-table $DB -u$USERNAME -p$PASSWORD

Detect insertion position (8-Apr @ 16:10)

remy

Syntax Highlighted Code

  1. (function () {
  2.     function getLastChild(el) {
  3.         return (el.lastChild && el.lastChild.nodeName != '#text') ? getLastChild(el.lastChild) : el;
  4.     }
  5. [10 more lines...]

Plain Code

(function () {
    function getLastChild(el) {
        return (el.lastChild && el.lastChild.nodeName != '#text') ? getLastChild(el.lastChild) : el;
    }

    // should be our script tag
    var insertPosition = getLastChild(document.lastChild);
    
    $(document).ready(function () {
        // get widget via jsonp
        
        // target element should be create at insertPosition, i.e.
        $(insertPosition).after('<p>widget inserted here</p>');
    });
})();

Untitled JavaScript (4-Apr @ 15:16)

remy

Syntax Highlighted Code

  1. <h1>Fade Method 1</h1>
  2.  
  3. <img src="images/who.jpg">
  4.  
  5. [19 more lines...]

Plain Code

<h1>Fade Method 1</h1>

<img src="images/who.jpg">

<span style="margin: 0pt; 
     padding: 0pt; 
     background: transparent url(images/who_ro.jpg) no-repeat scroll 0%; 
     height: 183px; 
     width: 260px; 
     display: -moz-inline-block; 
     -moz-background-clip: -moz-initial; 
     -moz-background-origin: -moz-initial; 
     -moz-background-inline-policy: -moz-initial;">
     <img class="fade" src="images/who.jpg" style="background-color: transparent; 
         background-repeat: no-repeat; 
         background-attachment: scroll; 
         background-position: 0%; 
         -moz-background-clip: -moz-initial; 
         -moz-background-origin: 
         -moz-initial; 
         -moz-background-inline-policy: -moz-initial;">
</span>

<img src="images/who_ro.jpg">

filterData plugin (3-Apr @ 15:42)

remy

Syntax Highlighted Code

  1. $.fn.filterData = function (k, v) {
  2.     return this.filter(function () {
  3.         return ($(this).data(k) == v);
  4.     });
  5. };

Plain Code

$.fn.filterData = function (k, v) {
    return this.filter(function () {
        return ($(this).data(k) == v);
    });
};

Extend to single instance (31-Mar @ 14:07)

remy

Syntax Highlighted Code

  1. var WFE = {};
  2. WFE.PanelManager = Base.extend({
  3.     init: function () {
  4.         console.log('parent initialised');
  5. [17 more lines...]

Plain Code

var WFE = {};
WFE.PanelManager = Base.extend({
    init: function () {
        console.log('parent initialised');
        this.id = 'PanelManager';
    }
});

WFE.PanelManager = WFE.PanelManager.extend({
    constructor: null, // forced the class in to a single instance http://dean.edwards.name/weblog/2006/03/base/
    init: function () {
        console.log('child init - testing parent...');
        this.base();
    }
});

// WFE.PanelManager is now a single object that can be extended as per above
// and it's correctly inherited the properties and methods of it's parent.    
console.log(WFE.PanelManager);


On ready (4-Jan @ 17:59)

remy

Syntax Highlighted Code

  1. $(function () {
  2. // do stuff
  3. });

Plain Code

$(function () {
// do stuff
});

Ajax validation plugin (4-Jan @ 17:57)

remy

Syntax Highlighted Code

  1. (function ($) {
  2.     $.fn.liveCheck = function () {
  3.         return this.each(function () {
  4.             var $$ = $(this);
  5. [38 more lines...]

Plain Code

(function ($) {
    $.fn.liveCheck = function () {
        return this.each(function () {
            var $$ = $(this);
            var t = this;
            
            var url = $$.parents('form:first').attr('action');
            
            var infospan = $$.parent().find('span');
            if (!infospan.length) {
                infospan = $$.after(' <span></span>').next();
            }
            
            $$.keyup(function () {
                // prevent tabbing in to the field firing an ajax hit
                if (t.value == '' && (t.lastValue == undefined)) return true;
                
                if (t.value != t.lastValue) {
                    if (this.timer) clearTimeout(this.timer);
                    infospan.removeClass('error').html('<img src="/images/ajax-loader.gif" height="16" width="16" /> validating...');
                    this.timer = setTimeout(function () {
                        $.ajax({
                            url: url,
                            data: t.name + '=' + t.value,
                            dataType: 'json',
                            type: 'post',
                            success: function (j) {
                                infospan.toggleClassIf(!j.ok, 'error').html(j.msg);
                            }
                        });
                    }, 200);
                    t.lastValue = t.value;
                }
            });
        });
    };
    
    $.fn.toggleClassIf = function (v, c) {
        return v ? this.addClass(c) : this.removeClass(c);
    };
    
})(jQuery);

Test for Module (14-Dec @ 08:22)

remy

Syntax Highlighted Code

  1. eval {require Module};
  2. unless ($@)
  3. {
  4.     require Module;
  5. [3 more lines...]

Plain Code

eval {require Module};
unless ($@) 
{
    require Module;
    import Module;

    # do stuff with Module
}

Excel file header (5-Dec @ 21:15)

remy

Syntax Highlighted Code

  1. <?php
  2.     $export_file = "my_name.xls";
  3.     ob_end_clean();
  4.     ini_set('zlib.output_compression','Off');
  5. [12 more lines...]

Plain Code

<?php
    $export_file = "my_name.xls";
    ob_end_clean();
    ini_set('zlib.output_compression','Off');
    
    header('Pragma: public');
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');  // Date in the past    
    header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
    header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 
    header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
    header('Pragma: no-cache');
    header('Expires: 0');
    header('Content-Transfer-Encoding: none');
    header('Content-Type: application/vnd.ms-excel;'); // This should work for IE & Opera
    header('Content-type: application/x-msexcel'); // This should work for the rest
    header('Content-Disposition: attachment; filename="' . basename($export_file) . '"');
?>

MySQL dump tables like (4-Dec @ 19:11)

remy

Syntax Highlighted Code

  1. mysql $DB -u$USERNAME -p$PASSWORD -e 'show tables like "$LIKE%"' |
  2. grep -v Tables_in | xargs mysqldump --add-drop-table $DB -u$USERNAME -p$PASSWORD

Plain Code

mysql $DB -u$USERNAME -p$PASSWORD -e 'show tables like "$LIKE%"' | 
grep -v Tables_in | xargs mysqldump --add-drop-table $DB -u$USERNAME -p$PASSWORD

CamelCase (22-Nov @ 21:44)

remy

Syntax Highlighted Code

  1. String.prototype.toCamelCase = function() {
  2.   return this.toString()
  3.     .replace(/([A-Z]+)/g, function(m,l){
  4.       return l.substr(0,1).toUpperCase() + l.toLowerCase().substr(1,l.length);
  5. [4 more lines...]

Plain Code

String.prototype.toCamelCase = function() {
  return this.toString()
    .replace(/([A-Z]+)/g, function(m,l){
      return l.substr(0,1).toUpperCase() + l.toLowerCase().substr(1,l.length);
    })
    .replace(/[-_s](.)/g, function(m, l){
      return l.toUpperCase();
    });
};

Loose DOM parsing (3-Oct @ 12:30)

remy

Syntax Highlighted Code

  1. $dom = new DOMDocument();
  2. $dom->preserveWhiteSpace = false;
  3. $dom->strictErrorChecking = false;
  4. $dom->loadHTMLFile($url);

Plain Code

$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->strictErrorChecking = false;
$dom->loadHTMLFile($url);

base64encode (30-Sep @ 12:30)

remy

Syntax Highlighted Code

  1. perl -MMIME::Base64 -e' open(FILE, $ARGV[0]) or die "$!";while (read(FILE, $buf, 60*57)) {print encode_base64($buf);}'

Plain Code

perl -MMIME::Base64 -e' open(FILE, $ARGV[0]) or die "$!";while (read(FILE, $buf, 60*57)) {print encode_base64($buf);}'

to hex (13-Sep @ 12:30)

remy

Syntax Highlighted Code

  1. d.toString(16)

Plain Code

d.toString(16)