Skip to content

Instantly share code, notes, and snippets.

View leepfrog's full-sized avatar

Andy Tran leepfrog

View GitHub Profile
class CsrfController < ApplicationController
def index
render json: { request_forgery_protection_token => form_authenticity_token }.to_json
end
end
test('selections should be populated as checkboxes are marked', function() {
expect(4);
var selections = Em.A();
var testData = {
models: Em.A([
Em.Object.create({ id: 1, name: "Foo", desc: "Hey"}),
Em.Object.create({ id: 2, name: "Bar", desc: "World"}),
]),
value: selections
class Author < ActiveRecord::Base
has_one :history, as: :related
end
class History < ActiveRecord::Base
belongs_to :related, polymorphic: true
validates :related_id, presence: true, uniqueness: {scope: :related_type}
validates :related_type, presence: true, uniqueness: true
end
$(document).ready(function() {
$('.team_title').editable("name", {
type : 'text',
rows : 8,
authenticity_token: encodeURIComponent('<%= form_authenticity_token if protect_against_forgery? %>'),
cancel : 'Cancel',
submit : 'OK',
tooltip : 'Double-click to edit...',
})
});
def model
default_message_if_blank(read_attribute(:model))
end
def default_message_if_blank(args)
if ["",nil].include? args
"None"
else
args
class Blog < ActiveRecord::Base
has_many :posts
accepts_nested_attributes_for :posts, :allow_destroy => true
before_validation :set_self_as_parent
def set_self_as_parent
self.posts.each |post|
post.blog = self
end
# Open / create temp file
temp_file = Tempfile.new(["myfile",".txt"])
# Write into temp file (this is where the problem is... I believe the myprogram is creating a new file)
raise "Problem with my proggy" unless system "/usr/local/bin/myprogram '#{temp_file.path}'"
# Read from temp file
puts temp_file.read
# Close / delete temp file
>> a=File.open("testmsg.emlx")
=> #<File:testmsg.emlx>
>> mail=TMail::Mail.parse(a.read)
=> #<TMail::Mail port=#<TMail::StringPort:id=0x8525896c> bodyport=nil>
>> mail.body
=> "This E-mail was sent from (Aficio MP C2050)\nAttachment: 20100209163759213.pdf\n"
>> mail.body+="testing"
=> "This E-mail was sent from (Aficio MP C2050)\nAttachment: 20100209163759213.pdf\ntesting"
>> mail.body
=> ""
-(IBAction)presentSalesView:(id)sender {
// We hold on to the salesViewController since we'll be using it a bunch
if (nil == self.salesViewController) {
SCSalesViewController *viewController = [[SCSalesViewController alloc] initWithNibName:@"SCSalesView" bundle:nil];
self.salesViewController = viewController;
[viewController release];
}
[self.navigationController pushViewController:self.salesViewController animated:YES];
}
@leepfrog
leepfrog / gist:2156129
Created March 22, 2012 04:52
Unable to use when loading objects from store
App.actionsController = Em.ArrayController.create({
content: [],
sort: function() {
var array, newArray;
array = this.get('content').toArray();
newArray = array.sort(function(a, b) {
var a_due, a_isdone, a_isstarred, b_due, b_isdone, b_isstarred;
a_isdone = a.get('isDone') ? 1 : 0;
b_isdone = b.get('isDone') ? 1 : 0;
a_isstarred = a.get('isStarred') ? 1 : 0;