Skip to content

Instantly share code, notes, and snippets.

View paulschreiber's full-sized avatar

Paul Schreiber paulschreiber

View GitHub Profile
@paulcc
paulcc / meta_search_hacks.rb
Created December 6, 2010 11:31
Import this to get searchlogic-style scopes from metasearch and rails 3
# by Paul Callaghan, Nov 2010.
# this uses method-missing to trigger generation and execution of the corresponding relation
# eg Product.name_equals("yay")
# TODO: M_S doesn't check for unexpected values, eg match failures in
# matches_attribute_method (so we trap exceptions)
module MetaSearchHacks
def self.build_rel(base_or_scope, method, *args)
@tonsV2
tonsV2 / add_devise_columns_to_user.rb
Created February 9, 2011 01:47
Rails migration for adding devise columns to an existing user model
class AddDeviseColumnsToUser < ActiveRecord::Migration
def self.up
change_table :users do |t|
#if you already have a email column comment the below line
t.database_authenticatable
t.confirmable
t.recoverable
t.rememberable
t.trackable
t.string :encrypted_password, :limit => 128
@mattattui
mattattui / gist:879249
Created March 21, 2011 10:08
Convert named HTML entities to numeric for XML compatibility
<?php
/* html_convert_entities($string) -- convert named HTML entities to
* XML-compatible numeric entities.
*/
function html_convert_entities($string) {
return preg_replace_callback('/&([a-zA-Z][a-zA-Z0-9]+);/S',
'convert_entity', $string);
}
@mattattui
mattattui / gist:879252
Created March 21, 2011 10:12
Convert HTML entities to XML
<?php
$out = htmlspecialchars(
html_entity_decode($in, ENT_QUOTES, 'UTF-8'),
ENT_QUOTES, 'UTF-8'
);
?>
@proofek
proofek / pre-receive
Created June 2, 2011 14:21
pre-receive git hook to run php linter
#!/usr/bin/php
<?php
echo "\nRunning php linter...\n";
$params = explode(' ', file_get_contents('php://stdin'));
$ref = trim($params[1]);
$diff = array();
$return = 0;

Proposal for Improving Mass Assignment

For a while, I have felt that the following is the correct way to improve the mass assignment problem without increasing the burden on new users. Now that the problem with the Rails default has been brought up again, it's a good time to revisit it.

Sign Allowed Fields

When creating a form with form_for, include a signed token including all of the fields that were created at form creation time. Only these fields are allowed.

To allow new known fields to be added via JS, we could add:

@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@jterrace
jterrace / xvfb
Created June 11, 2012 18:46
xvfb init script for Ubuntu
XVFB=/usr/bin/Xvfb
XVFBARGS=":1 -screen 0 1024x768x24 -ac +extension GLX +render -noreset"
PIDFILE=/var/run/xvfb.pid
case "$1" in
start)
echo -n "Starting virtual X frame buffer: Xvfb"
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
echo "."
;;
stop)
@kasparsd
kasparsd / wordpress-plugin-svn-to-git.md
Last active April 17, 2024 12:35
Using Git with Subversion Mirroring for WordPress Plugin Development
@loonies
loonies / pubsub.js
Created October 11, 2012 14:23
jQuery pub/sub plugin by Peter Higgins
/*!
* jQuery pub/sub plugin by Peter Higgins
* https://github.com/phiggins42/bloody-jquery-plugins/blob/master/pubsub.js
*
* Modified by Tobin Bradley
*
* AFL/BSD Licensed
*/
;(function(d){
// the topic/subscription hash