Skip to content

Instantly share code, notes, and snippets.

delay 1
tell application "ScreenSaverEngine" to activate
@pheisiph
pheisiph / dtachdaemon.rb
Created February 20, 2012 14:33
Daemonizing rake tasks using dtach
namespace :myapp do
namespace :mynamespace do
class MyProcessRunner
def self.basename
"task_name"
end
def self.socket
Rails.root.join("tmp", "sockets", "#{basename}.dtach")
@pheisiph
pheisiph / application_helper.rb
Created April 8, 2012 13:08
Useful standard classes I add to body tags in all my rails apps
module ApplicationHelper
# Public: Add a bunch of default class names to your html body element.
# By default it adds the name of the application, the current
# controller and the action
#
# classes - Arbitrary class names that are appended. Can be an Array
# of Strings or Symbols, or a single String or
# Symbol (or any to_s responder).
#
# Examples
@pheisiph
pheisiph / facebook.html.erb
Created April 25, 2012 15:40
allow Facebook to access (some)content that is login-only normally
#app/views/layouts/facebook.html.erb
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml"
xmlns:og="http://opengraphprotocol.org/schema/">
<head>
<title><%= yield(:title) %></title>
<meta charset="UTF-8">
<meta property="og:title" content="<%= yield :og_title %>">
<meta property="og:type" content="article">
<meta property="og:image" content="<%= yield :og_image %>">
@pheisiph
pheisiph / gist:2700643
Created May 15, 2012 10:25
File Upload with Ajax
$form = $("#edit_item");
// Build the FormData object with some Rails-specific attributes
var formData = new FormData($form[0]);
formData.append('utf8','✓')
formData.append('_method', 'put'); // editing existing record
formData.append('authenticity_token', AUTH_TOKEN);
$.ajax({
@pheisiph
pheisiph / json_vulnerability_tester.rb
Last active December 12, 2015 10:29
Test Rails apps against [Denial of Service and Unsafe Object Creation Vulnerability in JSON [CVE-2013-0269](https://groups.google.com/forum/?fromgroups=#!topic/rubyonrails-security/4_YvCpLzL58). Adapted from [Heroku's script](https://github.com/heroku/heroku-CVE-2013-0269) to work on generic Rails app.
#! /usr/bin/ruby
# Check for Denial of Service and Unsafe Object Creation Vulnerability in JSON
# [CVE-2013-0269]
#
# Adapted from [Heroku's script](https://github.com/heroku/heroku-CVE-2013-0269) to work on generic Rails app.
#
# cd into application path, (where the Gemfile.lock is),
# then run this script or simply `ruby -e "$(curl -fsSL http://bit.ly/CVE-2013-0269)"`.
@pheisiph
pheisiph / bootstrap.rb
Created May 16, 2013 08:54
Two scripts to be put into the script folder of a rails app. ./script/setup prepares the app/system/dependencies for booting the app for the first time. ./script/bootstrap should be run whenever changes from collaborators are pulled in. It installs dependencies and updates gems if necessary. It is fast, because actions are only executed if there…
# ./script/bootstrap
#!/usr/bin/env ruby
require 'fileutils'
# Capture ctrl-c and exit with a message.
Signal.trap("SIGINT") do
puts ; puts "Buh bye".red
exit 1
end
@pheisiph
pheisiph / bootstrap.rb
Last active April 26, 2016 13:26
Puppet Bootstrapping with capistrano
#config/recipes/bootstrap.rb
#capistrano recipe
namespace :bootstrap do
desc "Prepare the system to run Puppet. Requires root access (once)."
task :default do
set :user, 'root' # because we haven't provisioned any users yet
# install puppet standalone
run "wget http://apt.puppetlabs.com/puppetlabs-release-#{config['os_code_name']}.deb"
run "dpkg -i puppetlabs-release-#{config['os_code_name']}.deb"
@pheisiph
pheisiph / gist:6285621
Created August 20, 2013 18:52
Current Sublime Text 2 settings
{
"bold_folder_labels": false,
"caret_style": "wide",
"color_scheme": "Packages/Solarized/Solarized (dark).tmTheme",
"com.khiltd.abacus.debug": true,
"draw_white_space": "selection",
"fade_fold_buttons": true,
"find_selected_text": true,
"font_face": "Espresso Mono",
"font_size": 12.0,
@pheisiph
pheisiph / config.ru
Created March 20, 2014 09:36
Redirect all requests to new domain
require 'rack/rewrite'
use Rack::Rewrite do
r301 %r{/(.*)}, 'https://somewhere.else.website/$1'
end
run lambda { |env| [200, {"Content-Type" => "text/plain"}, ["You shouldn't get here."]] }