Skip to content

Instantly share code, notes, and snippets.

View DCarper's full-sized avatar

Dan Carper DCarper

View GitHub Profile
source 'https://rubygems.org'
gem 'rails', '3.2.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'haml-rails'
@DCarper
DCarper / compass.rb
Created February 22, 2012 18:07
~/code/projects/my_app > bundle exec compass init --using blueprint
# This configuration file works with both the Compass command line tool and within Rails.
require 'compass/h5bp'
# Require any additional compass plugins here.
project_type = :rails
# Set this to the root of your project when deployed:
http_path = "/"
class ApiController < ApplicationController
def integer_to_string
render :json => { :value => params[:value] }.to_json
end
def concat
sum = params[:a] + params[:b]
render :soap => { :value => sum }.to_json
end
<%= { :new_form => render(:partial => 'blah/form.html.haml') }.to_json -%>
@DCarper
DCarper / array_test.rb
Created October 27, 2011 16:00
What's the reasoning behind these special cases?!?
a = [0, 2, 3]
a[3, 1] ## => [] # official special case
a[4, 1] ## => nil
a[5, 1] ## => nil
##
a = [0, 1, 2, 3]
class Sensitive < ActiveRecord::Base
attr_accessor :plain_data
attr_protected :encrypted_data, :encrypted_key, :encrypted_iv
before_save :encrypt_sensitive
def decrypt_sensitive(password)
if self.encrypted_data
private_key = OpenSSL::PKey::RSA.new(File.read(APP_CONFIG['private_key']),password)
cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
@DCarper
DCarper / haml.html
Created October 6, 2011 15:41 — forked from carols10cents/haml.html
Haml vs html -- can have "display: inline" tags inline?
<!-- haml -->
%blockquote
I am not running for president. -
%strong
everyone
, ever
<!-- html -->
server {
listen 443;
ssl on;
ssl_certificate /opt/nginx/conf/server.crt;
ssl_certificate_key /opt/nginx/conf/server.key;
server_name www.sub.domain.com;
root /Users/Dan/code/my_app/public;
passenger_enabled on;
keepalive_timeout 70;
}
# lib/some_presenter
class some_presenter
attr_accessor :my_object
def initialize(some_object)
self.my_object = some_object
end
debugger
// $form.serialize => "authenticity_token=H38DglaC0V2fJYzFyVwmzl83iqPpgbrCbxjYeHwPoWI%3D&comment%5Bcontent%5D=adf&commit=Post+Comment"
$form.ajaxSubmit({
//$.ajax({
url: form.action + '.json',
data: $form.serialize(),
type: 'post',
//dataType: 'json',
context: $form.parent(".responses, #comments"),
success: insertComment });