Skip to content

Instantly share code, notes, and snippets.

View leepfrog's full-sized avatar

Andy Tran leepfrog

View GitHub Profile
$(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;
{"projects":[{"id":1,"name":"Books","project_type_id":1}]}
@leepfrog
leepfrog / gist:3141061
Created July 19, 2012 05:58
downcase only first letter
// given a string SomeCrazyString => someCrazyStringID
NSString *keyName = [[NSString alloc] initWithFormat:@"%@%@ID", [[modelKey lowercaseString] substringToIndex:1], [modelKey substringFromIndex:1]];
DDLogInfo(@"primaryKey[%@]: %@", modelKey, keyName);
_clockFormat = [[NSDateFormatter alloc] init];
[_clockFormat setTimeStyle:NSDateFormatterLongStyle];
[_clockFormat setLocale:[NSLocale systemLocale]];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
_clockTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_source_set_timer(_clockTimer, DISPATCH_TIME_NOW, kClockUpdateInterval * NSEC_PER_SEC, 0);
dispatch_source_set_event_handler(_clockTimer, ^{
self.clock.text = [_clockFormat stringFromDate:[NSDate date]];