Skip to content

Instantly share code, notes, and snippets.

View lsiden's full-sized avatar

Lawrence Siden lsiden

View GitHub Profile
@lsiden
lsiden / gist:9161456
Created February 22, 2014 20:05
angular-test-patterns run error
lsiden@morpheus [angular-test-patterns] (master=) [1]$ npm test
> [email protected] test /home/lsiden/projects/scratch/angular-test-patterns
> npm run testRules && npm run testPatterns && npm run testExamples
> [email protected] testRules /home/lsiden/projects/scratch/angular-test-patterns
> node spec/rule.tester.js
@lsiden
lsiden / gist:8773448
Created February 2, 2014 19:26
Stack trace from calling render_to_string in a controller after_filter
ERROR TypeError: no implicit conversion of nil into String
/home/lsiden/.rvm/gems/ruby-2.1.0@myapp/gems/rack-1.5.2/lib/rack/handler/webrick.rb:73:in `block in service'
/home/lsiden/.rvm/gems/ruby-2.1.0@myapp/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in `each'
/home/lsiden/.rvm/gems/ruby-2.1.0@myapp/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in `each'
/home/lsiden/.rvm/gems/ruby-2.1.0@myapp/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in `each'
/home/lsiden/.rvm/gems/ruby-2.1.0@myapp/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in `each'
/home/lsiden/.rvm/gems/ruby-2.1.0@myapp/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in `each'
/home/lsiden/.rvm/gems/ruby-2.1.0@myapp/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in `each'
/home/lsiden/.rvm/gems/ruby-2.1.0@myapp/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in `each'
/home/lsiden/.rvm/gems/ruby-2.1.0@myapp/gems/rack-1.5.2/lib/rack/handler/webrick.rb:72:in `service'
@lsiden
lsiden / gist:8310790
Created January 8, 2014 02:32
Here's a way to make a relation immutable that doesn't break.
# Prevent self.user from being changed
alias_method :old_user_assign, :user=
def user=(new_user)
if self.new_record?
old_user_assign new_user
else
logger.warn "Attempt to modify user of record, id=#{self.id} with user id=#{new_user.id}"
return false
end
@lsiden
lsiden / gist:8310536
Created January 8, 2014 02:10
A test that fails when this solution, http://stackoverflow.com/a/6456889/270511, is applied.
test "inverse of user.profiles" do
user = create :user
profile = create :profile, user: user
assert_equal profile, user.profiles.first, "profile == user.profiles.first"
end
@lsiden
lsiden / nf-iconbox
Created December 20, 2013 21:04
Custom Wordpress plugin to import into <mysite>/wp-admin/options-general.php?page=post-snippets/post-snippets.php&tab=snippets to match functionality of Inovado-theme "iconbox" shortcode. See http://themeforest.net/item/inovado-retina-responsive-multipurpose-theme/3810895 The initials "nf" stand for my client's http://company: thenewfoundry.com
a:1:{i:0;a:7:{s:5:"title";s:10:"nf-iconbox";s:4:"vars";s:13:"title,imgpath";s:9:"shortcode";b:1;s:3:"php";b:0;s:11:"wptexturize";b:0;s:7:"snippet";s:196:"<div class="iconbox">
<span class="nf-iconbox" style="background-image: url('{imgpath}'); background-repaeat: no-repeat; vertical-align: middle !important; "></span><br>
<h3>{title}</h3>
</div>";s:11:"description";s:75:"Insert a custom NewFoundry iconbox. Same functionality as Inovado iconbox.";}}
@lsiden
lsiden / TestAnnouncementsController.php
Created August 9, 2012 14:53
Test AnnouncementsController::isAuthorized()
<?php
App::uses('AnnouncementsController', 'Controller');
class MockAnnouncementsController extends AnnouncementsController {
var $name = 'Announcements';
var $autoRender = false;
/*
function redirect($url, $status = null, $exit = true) {
$this->redirectUrl = $url;
@lsiden
lsiden / demo.sql
Created July 20, 2012 13:06
Impossible WHERE noticed after reading const tables
-- MySQL dump 10.11
--
-- Host: localhost Database: demo
-- ------------------------------------------------------
-- Server version 5.0.96
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
# mount
rootfs on / type rootfs (ro,relatime)
tmpfs on /dev type tmpfs (rw,relatime,mode=755)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
none on /acct type cgroup (rw,relatime,cpuacct)
tmpfs on /mnt/asec type tmpfs (rw,relatime,mode=755,gid=1000)
tmpfs on /mnt/obb type tmpfs (rw,relatime,mode=755,gid=1000)
none on /dev/cpuctl type cgroup (rw,relatime,cpu)
@lsiden
lsiden / my-rvm-prompt
Created January 8, 2012 06:28
Wrapper for rvm-prompt that searches parent directories for files that tell we're in a Ruby project dir or sub-dir
#!/bin/bash
# Use this script instead of ~/.rvm/bin/rvm-prompt
# and the output of rvm-prompt will show up in your command prompt
# only if you are in a Ruby project directory.
# see http://stackoverflow.com/a/4264351/270511
# and http://unix.stackexchange.com/questions/13464/is-there-a-way-to-find-a-file-in-an-inverse-recursive-search
# modified from https://gist.github.com/763374
module DataMapper
module Resource
def taint! property
self.persistence_state = PersistenceState::Dirty.new(self) \
unless self.persistence_state.kind_of?(PersistenceState::Dirty)
self.persistence_state.original_attributes[properties[property]] = Object.new
end
end
end