Skip to content

Instantly share code, notes, and snippets.

View jaredhoyt's full-sized avatar

Jared Hoyt jaredhoyt

View GitHub Profile

Keybase proof

I hereby claim:

  • I am jaredhoyt on github.
  • I am jaredhoyt (https://keybase.io/jaredhoyt) on keybase.
  • I have a public key whose fingerprint is 58FF 2A64 9B63 53D3 C440 611F BC73 8EF8 EA27 3795

To claim this, I am signing this object:

begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
@jaredhoyt
jaredhoyt / pre-push
Last active December 24, 2015 22:49
git pre-push hook to prevent force push to master
#!/usr/bin/env ruby
# This script has been slightly adapted from:
# http://blog.bigbinary.com/2013/09/19/do-not-allow-force-pusht-to-master.html
class PrePushHandler
def handle
reject if force_pushing? && pushing_to_master?
end
@jaredhoyt
jaredhoyt / gist:5725338
Last active December 18, 2015 04:29
CheckBoxLabelExtension
namespace System.Web.Mvc.Html {
using System.Collections;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
public static class CheckBoxLabelExtensions {
public static MvcHtmlString CheckBoxLabel(this HtmlHelper html, string expression) {
return CheckBoxLabel(html, expression, null);
@jaredhoyt
jaredhoyt / gist:932905
Created April 20, 2011 21:25
Reports Shell
<?php
App::import('Core', 'Controller');
App::import('Component', 'Email');
class ReportsShell extends Shell {
var $uses = array('PaymentException');
/**
* Controller/EmailComponent instances.
*
* @var class
*/
@jaredhoyt
jaredhoyt / gist:896608
Created March 31, 2011 15:45
Payments import
<?php
ini_set('max_execution_time', 90);
ini_set('memory_limit', '512M');
class Payment extends AppModel {
var $actsAs = array('SoftDeletable');
var $belongsTo = array('Payer', 'Procedure');
var $validate = array(
'import' => array(
'rule' => 'validImport',
'message' => 'Please submit a valid import document.'
@jaredhoyt
jaredhoyt / gist:895156
Created March 30, 2011 19:50
Submitting a form and reloading results via ajax (jQuery)
<script type="text/javascript">
jQuery(function(){
$('form').submit(function(event){
$.post(form.action, $(form).serializeArray(), function(response){
$('table').html($(response).find('table').children());
});
event.preventDefault();
});
});
</script>
@jaredhoyt
jaredhoyt / gist:876242
Created March 18, 2011 15:18
Shell using Email Component
<?php
App::import('Core', 'Controller');
App::import('Component', 'Email');
class ExampleShell extends Shell {
function main() {
$this->Controller =& new Controller();
$this->Email =& new EmailComponent(null);
$this->Email->initialize($this->Controller);
}
}
@jaredhoyt
jaredhoyt / prevent-cache.js
Created March 16, 2011 14:16
jQuery Cache Prevention
// This will affect all subsequent ajax calls made with jQuery
jQuery(function(){
$.ajaxSetup({
cache: false
});
});
@jaredhoyt
jaredhoyt / gist:826903
Created February 15, 2011 00:59
Example Permissionable usage
<?php
# Controller
$job = $this->Note->Job->find('summary', array(
'conditions' => array('Job.id' => $job_id),
'contain' => array('Note.CreatedBy', 'TodoList.TodoItem.Note.CreatedBy', 'Submittal.Note.CreatedBy')
));