Skip to content

Instantly share code, notes, and snippets.

<?php
class Post extends Eloquent
{
protected $fillable = array(
'title',
'slug'
);
public function setTitleAttribute($value)
@clarkf
clarkf / Exception.txt
Last active January 3, 2016 14:59
Laravel 4.1.2
SQLSTATE[HY000]: General error: 1 ambiguous column name: id
(SQL: select * from "categories" inner join "category_posts" on "categories"."id" = "category_posts"."category_id" where "category_posts"."post_id" = 1 and "id" = 1 limit 1)
@clarkf
clarkf / Dockerfile
Created October 8, 2013 04:45
A dockerfile for
FROM ubuntu:precise
# Install all the things! (TODO: Add your favorite text editor here)
RUN apt-get update
RUN apt-get -y -q install php5-cli sudo php5-curl curl git
# Create a user so that everything isn't run as root
RUN adduser user; adduser user sudo; passwd -d user
# Install composer, and move it to `composer` so it can be used globally
<?php
class RouterThing {
/* ... */
function fireController($controllerInstance, $action) {
/* ... setup ... */
$before = get_object_vars($controllerInstance);
$result = $controllerInstance->$action();
@clarkf
clarkf / tree_r.php
Created August 15, 2013 21:24
A silly little utility for pretty printing multidimensional arrays.
<?php
/**
* Recursively print out a multidimensional array
* prettily. Don't use the `$prefix` parameter.
*
* @param array $array The array to print
* @param string $prefix The prefix (internal)
*
* @return string The nice tree
$ ./node_modules/.bin/r.js -o name=../node_modules/almond/almond baseUrl=client include=main wrap=true optimize=none out=dist/dist.js
Tracing dependencies for: ../node_modules/almond/almond
Error: ENOENT, no such file or directory './client/underscore.js'
In module tree:
main
Error: ENOENT, no such file or directory './client/underscore.js'
In module tree:
main
@clarkf
clarkf / Backbone.BootstrapForm.js
Created February 14, 2012 22:44
Backbone FormView Helper
/*!
* Backbone BootstrapForm
* Copyright (c) 2012 Clark Fischer <[email protected]>
* V0.0.1
* MIT Licensed
*
* This extension depends on Backbone.FormView.js:
* <https://gist.github.com/1831242#file_backbone.form_view.js>
*/
@clarkf
clarkf / route.js
Created February 10, 2012 06:09
DRY?
exports.whater = function (req, res) {
var format = req.params.format ? req.params.format : req.format;
User.findOne({ username: req.params.username }, function (err, doc) {
if (err) throw err;
if (!doc) {
if (format == 'json') {
res.json({ error: "no such user"});
} else {
res.render('404');
//I copied the hash value exactly from a tracker -- this is a hex
//representation of the sha1sum of the info dictionary
var bigint = require('bigint'),
hash = new Buffer('8ac3731ad4b039c05393b5404afa6e7397810b41', 'hex'),
connection_id = new bigint('4497486125440'),
buffer = new Buffer(36);
/* ( http://www.bittorrent.org/beps/bep_0015.html )
@clarkf
clarkf / q.js
Created January 26, 2012 06:25
What did I do here?
var q = require('q'),
guid = 1;
function randomDefer() {
var defer = q.defer(), id = guid++;
console.log("sending %d", id);
setTimeout(function () {
console.log("resolving %d", id);
defer.resolve('hi');