Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View ashchan's full-sized avatar
🏠
Working from Mars

Jianming Chen ashchan

🏠
Working from Mars
View GitHub Profile
require 'zip/zip'
# zip files
Dir.chdir(parent_directory)
zipfile = directory + ".zip"
return false if File.exist?(zipfile)
Zip::ZipFile::open(zipfile, true) do |zf|
Dir["#{directory}/**/*"].each { |f| zf.add(f, f) }
zf.close
class Photo < ActiveRecord::Base
has_attachment options_for_attachment_fu
after_attachment_saved do |foto|
# delete original file for disk space saving
FileUtils.rm foto.full_filename if foto.parent.nil?
end
end
@ashchan
ashchan / gist:71520
Created February 27, 2009 15:25 — forked from jsierles/gist:31100
#!/usr/bin/env ruby
#
# fetch hosts from amazon EC2 meta-data
#
# Based on http://dysinger.net/2008/10/13/using-amazon-ec2-metadata-as-a-simple-dns
#
%w(logger optparse rubygems right_aws resolv pp).each { |l| require l }
LOGGER = Logger.new("/var/log/fetch_hosts.log")
@ashchan
ashchan / gist:589094
Created September 21, 2010 02:34
NSDate class method to get an NSDate from an internet date time string (RFC822 or RFC3339)
// Return date for internet date string (RFC822 or RFC3339)
// - RFC822 http://www.ietf.org/rfc/rfc822.txt
// - RFC3339 http://www.ietf.org/rfc/rfc3339.txt
// - Good QA on internet dates: http://developer.apple.com/iphone/library/qa/qa2010/qa1480.html
// - Cocoa date formatting: http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
+ (NSDate *)dateFromInternetDateTimeString:(NSString *)dateString {
// Setup Date & Formatter
NSDate *date = nil;
static NSDateFormatter *formatter = nil;
@ashchan
ashchan / Capfile
Created November 15, 2010 14:35 — forked from nstielau/Capfile
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
##################################
# Edit these
set :application, "example_node_app"
set :node_file, "hello_world.js"
set :host, "ec2-174-129-114-66.compute-1.amazonaws.com"
ssh_options[:keys] = [File.join(ENV["HOME"], ".ec2", "default.pem")]
set :repository, "git://gist.github.com/479007.git"
set :branch, "master"
@ashchan
ashchan / https_nsoperation.rb
Created January 23, 2011 10:52
https calling in NSOperation caused Segmentation fault
framework 'Cocoa'
require 'net/https'
class SomeOperation < NSOperation
def main
http = Net::HTTP.new("mail.google.com", 443)
http.use_ssl = true
response = nil
http.start do |h|
req = Net::HTTP::Get.new("/mail/feed/atom")
jQuery(function() {
$.cookie('tz', (new Date()).getTimezoneOffset());
});
@ashchan
ashchan / still have problem
Created July 20, 2011 07:23
macruby_deploy app with space in name
$ macruby_deploy --compile --embed --bs Gmail\ Notifr.app
*** Deployment started
*** Embedding MacRuby.framework
*** Embed BridgeSupport system files
*** Fix install path of binaries
*** Fix identification name of libmacruby
/usr/bin/otool: can't open file: Gmail (No such file or directory)
/usr/bin/otool: can't open file: Notifr.app/Contents/Frameworks/MacRuby.framework/Versions/Current/usr/lib/ruby/site_ruby/1.9.2/universal-darwin10.0/bigdecimal.bundle (No such file or directory)
Error when executing `/usr/bin/otool -L Gmail Notifr.app/Contents/Frameworks/MacRuby.framework/Versions/Current/usr/lib/ruby/site_ruby/1.9.2/universal-darwin10.0/bigdecimal.bundle'
@ashchan
ashchan / link_nongiest.rake
Last active December 15, 2015 06:48
Symbolink to digested assets (w/ fingerprint)
@ashchan
ashchan / 0_reuse_code.js
Last active August 29, 2015 14:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console