Skip to content

Instantly share code, notes, and snippets.

@johanb
johanb / Gemfile
Created January 31, 2012 14:40
Bundler fun
source "http://rubygems.org"
gem 'ruby-debug19', :platforms => :ruby_19
gem 'ruby-debug', :platforms => :ruby_18
# Specify your gem's dependencies in warden-podio.gemspec
gemspec
@johanb
johanb / date_time.rb
Created February 17, 2012 10:43
weekend ?
class DateTime
def weekend?
(saturday? || sunday? || (friday? && hour >= 17)) ? true : false
end
end
@johanb
johanb / crash.log
Created March 5, 2012 17:24
Plex crash
Process: Plex Media Server [98402]
Path: /Applications/Plex Media Server.app/Contents/MacOS/Plex Media Server
Identifier: com.plexapp.plexmediaserver
Version: 0.9.5.3 (0.9.5.3-dff0bd5)
Code Type: X86 (Native)
Parent Process: launchd [484]
Date/Time: 2012-03-05 18:14:03.700 +0100
OS Version: Mac OS X Server 10.7.3 (11D50b)
Report Version: 9
def bieruur?
true
end
@johanb
johanb / gist:2080126
Created March 18, 2012 19:35
Stream httpndownload straight to disk.
Net::HTTP.start("someurl_without_the_protocol.com") do |http|
begin
file = open("/path/to/file.mov", 'wb')
http.request_get('/' + URI.encode("file.mov")) do |response|
response.read_body do |segment|
file.write(segment)
end
end
ensure
file.close
gem install spree
ERROR: While executing gem ... (Gem::DependencyError)
Unable to resolve dependencies: railties requires activesupport (= 3.1.4), actionpack (= 3.1.4); actionmailer requires actionpack (= 3.1.4); activeresource requires activesupport (= 3.1.4), activemodel (= 3.1.4); activerecord requires activesupport (= 3.1.4), activemodel (= 3.1.4)
gem install spree 38.27s user 0.30s system 71% cpu 53.572 total
require 'rubygems'
gemfile = File.expand_path("../../../../Gemfile", __FILE__)
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'
Bundler.setup
require 'spree_core'
require 'spree_mollie/engine'
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
@johanb
johanb / Downloading Zipping Shelled Out.rb
Created April 5, 2012 13:36
Just zipping up some photos.. this leaks memory. How can I optimize this routine ?
# This seem sot be my solution of avoiding a huge amount of memory usage. (Thanks to [hanke](http://twitter.com/hanke) & [alloy](http://twitter.com/alloy) )
FileUtils.mkdir_p(zip_path)
photos.each do |photo|
url = photo.photo_url
path = photos.photo.path
system("cd #{zip_path} && curl -L #{url} -o #{path} --create-dirs")
end
class Photo < ActiveRecord::Base
mount_uploader :photo, PhotoUploader
end