Skip to content

Instantly share code, notes, and snippets.

View unixmonkey's full-sized avatar

David Jones unixmonkey

View GitHub Profile
#!/usr/bin/env ruby
#
# Proof-of-Concept exploit for Rails Remote Code Execution (CVE-2013-0156)
#
# ## Advisory
#
# https://groups.google.com/forum/#!topic/rubyonrails-security/61bkgvnSGTQ/discussion
#
# ## Caveats
#
@unixmonkey
unixmonkey / remote-edit.py
Created December 20, 2012 14:28
A SublimeText 2 Plugin to auto-scp files to an ssh server on save http://net.tutsplus.com/tutorials/python-tutorials/how-to-create-a-sublime-text-2-plugin/
import sublime_plugin, os
class RemoteEdit(sublime_plugin.EventListener):
def on_post_save(self, view):
remote = { "/local/path/to/project": "/usr/bin/scp '$1' username@remote_host:'/remote/path/to/project$2'" }
for dirname, target in remote.iteritems():
if view.file_name().startswith( dirname ):
target = target.replace( "$1", view.file_name() )
target = target.replace( "$2", view.file_name()[len(dirname):] )
@unixmonkey
unixmonkey / symfony_cheatsheet.md
Created December 13, 2012 20:28
Notes on Symfony 1.4 development that I keep finding myself having to look up
@unixmonkey
unixmonkey / tt_example.cgi
Created December 10, 2012 15:14
Perl Template Toolkit example using __DATA__ as template
#!/usr/bin/env perl
use strict;
use warnings;
use Template;
my @coordinates = [
11, 22, 39, 393, 102, 102
];
my $vars = {
@unixmonkey
unixmonkey / quiet.rb
Created December 7, 2012 17:38
Method to suppress STDOUT in a block
#!/usr/bin/env ruby
#
# Creates a block that temporarily suppresses STDOUT
# This is useful if you want to run something that uses
# puts or print, but don't actually want it to print to screen
#
require 'stringio'
def quiet(&block)
@unixmonkey
unixmonkey / hack_and_ship.sh
Created October 22, 2012 21:12
Feature, Hack, and Ship
# ===========================================================
# = feature && hack && rake test && ship =
# = http://reinh.com/blog/2008/08/27/hack-and-and-ship.html =
# ===========================================================
# create new named feature branch and switch to it
feature() {
git checkout -b $1
}
@unixmonkey
unixmonkey / wkhtmltopdf.css
Created June 9, 2012 16:13
wkhtmltopdf.css
body { margin:0; padding:0; width:100%;
/* Turn off kerning to prevent odd spacing problem
when copying and pasting from PDFs on Windows */
text-rendering: optimize-speed; }
body, table { font-size: 13px; }
.page-numbers { text-align:right; }
div.alwaysbreak { page-break-before: always; }
div.nobreak:before { clear:both; }
div.nobreak{ page-break-inside: avoid;
/* http://code.google.com/p/wkhtmltopdf/issues/detail?id=9#c21 */
@unixmonkey
unixmonkey / gist:1316430
Created October 26, 2011 13:57
Redirect and still show error messages
# app/controllers/ballots_controller.rb
def create
@ballot = Ballot.new(params[:ballot])
if @ballot.save
redirect_to @ballot, :notice => 'Successful'
else
session[:error_messages] = @ballot.errors.full_messages
redirect_to edit_ballot_path(@ballot, :params => params), :notice => 'Ruh Roh!'
end
end
@unixmonkey
unixmonkey / email.rb
Created July 13, 2011 00:53
email configuration for rails
# Loads ActionMailer settings from config/email.yml
# and turns deliveries on only if configuration block is found
config_file = Rails.root.join('config','email.yml')
if File.file?(config_file)
mailconfig = YAML::load_file(config_file)
if mailconfig.is_a?(Hash) && mailconfig.has_key?(Rails.env)
# enable deliveries
ActionMailer::Base.perform_deliveries = true
module ExpectedBehavior
module ActsAsArchival
module ActMethods
def acts_as_archival
unless included_modules.include? InstanceMethods
include InstanceMethods
before_save :raise_if_not_archival