Skip to content

Instantly share code, notes, and snippets.

View fender21's full-sized avatar

Gregg Geil fender21

View GitHub Profile
@fender21
fender21 / csv help
Created June 5, 2011 18:53
csv help!
namespace :address do
task :import do
file_name = 'data.txt'
puts 'Started Importing'
require "csv"
CSV.foreach(file_name, :quote_char => '"', :col_sep =>'\t', :row_sep =>:auto) do |row|
puts row[0]
end
end
@fender21
fender21 / gist:1420876
Created December 2, 2011 00:07
Better way to route?
post :index do
#determine the querystring which is NOT restful and route to approriate view
#URL looks like this http://localhost/app?create&id=10
url = env['REQUEST_URI']
uri = Addressable::URI.parse(url).query_values.to_hash
#Provide Server Info text per spec
if uri.has_key?("create")
tmp_dir = File.join(Padrino.root, 'tmp')
@fender21
fender21 / gist:1551675
Created January 2, 2012 18:41
Multipart Response
HTTP/1.1 200 (OK)
Server: Microsoft-IIS/4.0
Date: Wed, 04 Nov 1998 07:41:03 GMT
Content-Type: multipart/form-data;
boundary=A495ukjfasdfddrg4hztzu...
Content-Length: 32413
X-dateC: 1998-10-07
X-timeC: 07:55:57
X-dateM: 1998-10-07
X-timeM: 07:55:57
@fender21
fender21 / gist:1886923
Created February 22, 2012 20:04
Carrierwave
class UploadedFile < CarrierWave::Uploader::Base
SEPARATOR = "\r\n".freeze
attr_reader :body
include CarrierWave::MimeTypes
process :set_content_type
def filename
@name = key
end
belongs_to :locker, :class_name => "User",
:condition => lambda { {:conditions => ["lock_until < ? ", Time.now]}}