Skip to content

Instantly share code, notes, and snippets.

@mattyo161
mattyo161 / gist:07f4de6479621ea7e194
Created February 6, 2015 17:14
Eloquent Model Iterator
<?php
/* This gist is offered as is, make sure to test in your environment
*
* This class can be used to iterate over a large Eloquent query. It uses a combination of the PDO Fetch and
* the chunk methods to collect a series of items in memory. The chunk part was necessary in order to implement
* eager loading options. You can set the CHUNK_SIZE in the code to set how many rows to load in memory at a time
* again for the eager loading purposes.
*
* I am sure there are other ways to implement this technique more effectively
@mattyo161
mattyo161 / gist:5526387
Last active December 17, 2015 01:09
DataTables plug-in for supporting custom sorting of any data type using a simple comment prefix in the field. Place the sortable value using a string, float, integer or date to sort with. In the format <!-- CDX:<data> --> where "X" is "S" for string, "I" for Integer, "F" for Float, "D" for Date.
/* DataTables plug-in to allow for a custom Data Value for sorting based on a comment */
jQuery.fn.dataTableExt.aTypes.unshift(function(sData) {
/* Look for a special comment <!-- CDx:<data> --> if found then return that type */
if (sData.indexOf('<!-- CDI:') >= 0) {
return 'comment-dt-integer';
} else if (sData.indexOf('<!-- CDS:') >= 0) {
return 'comment-dt-string';
} else if (sData.indexOf('<!-- CDF:') >= 0) {
return 'comment-dt-float';
} else if (sData.indexOf('<!-- CDD:') >= 0) {
@mattyo161
mattyo161 / ical-yearly-events.applescript
Created February 25, 2012 01:51
Applescript for getting list of yearly events from iCal
tell application "iCal"
set results to ""
set todaysDate to current date
repeat with a in every calendar
set results to results & return & (name of a)
tell a
set eventList to {}
repeat with b in every event
if (recurrence of b) = "FREQ=YEARLY;WKST=SU" then
set startDate to start date of b
@mattyo161
mattyo161 / install_homebrew.rb
Created January 6, 2012 14:05 — forked from fenollp/install_homebrew.rb
Installs Homebrew to /usr/local so you don't need sudo to `brew install`
#!/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere you can just
# untar https://github.com/sceaga/homebrew/tarball/tiger anywhere you like.
module Tty extend self
def blue; bold 34; end
def white; bold 39; end
def red; underline 31; end
def reset; escape 0; end
def bold n; escape "1;#{n}" end