This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mongoose = require "mongoose" | |
Busboy = require "busboy" | |
secrets = require "../config/secrets" | |
GridStream = require "gridfs-stream" | |
Files = require "../models/files" | |
sharp = require "sharp" | |
async = require "async" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'time' | |
class BusinessHours | |
def initialize opening, closing | |
@hours = Hash.new( [opening, Time.parse(closing)-Time.parse(opening)] ) | |
end | |
def calculate_deadline interval, drop_off | |
target = seconds_before_closing( time = Time.parse(drop_off) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "test/unit" | |
require File.dirname(__FILE__) + '/business_hours' | |
class BusinessHoursTest < Test::Unit::TestCase | |
def setup | |
@hours = BusinessHours.new("8:00 AM", "5:00 PM") | |
end | |
def test_within_working_hours | |
assert_equal Time.parse("Dec 21, 2009 3:05 PM"), @hours.calculate_deadline(5*60, "Dec 21, 2009 3:00 PM") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/show_exceptions.rb | |
require 'action_dispatch/middleware/show_exceptions' | |
module ActionDispatch | |
class ShowExceptions | |
private | |
def render_exception_with_template(env, exception) | |
body = ErrorsController.action(rescue_responses[exception.class.name]).call(env) | |
log_error(exception) | |
body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tip(msg); puts; puts msg; puts "-"*100; end | |
# | |
# 30 Ruby 1.9 Tips, Tricks & Features: | |
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/ | |
# | |
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2" | |
tip "Ruby 1.9 supports named captures in regular expressions!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JobClass | |
def perform | |
begin | |
#I do stuff here | |
rescue Exception => e | |
# catch all exceptions | |
HoptoadNotifier.notify(e) | |
ensure | |
# we want this job to just run continuously, but we don't have an 'auto' way to do that | |
# so we schedule a new one every time we run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worker_processes 1; | |
user nobody nogroup; | |
pid /tmp/nginx.pid; | |
error_log /tmp/nginx.error.log; | |
events { | |
worker_connections 1024; | |
accept_mutex off; | |
} | |
http { | |
default_type application/octet-stream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MergeSort | |
def self.sort(list) | |
list = list.map{|i| [i]} | |
list = pairs list while list.size > 1 | |
list.flatten | |
end | |
def self.pairs(list) | |
return list if list.size < 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./executable-with-subcommands-using-thor.rb | |
Tasks: | |
executable-with-subcommands-using-thor.rb help [TASK] # Describe available tasks or one specific task | |
executable-with-subcommands-using-thor.rb subA [TASK] # Execute a task in namespace subA | |
executable-with-subcommands-using-thor.rb subB [TASK] # Execute a task in namespace subB | |
executable-with-subcommands-using-thor.rb test # test in CLI | |
$ ./executable-with-subcommands-using-thor.rb help | |
Tasks: | |
executable-with-subcommands-using-thor.rb help [TASK] # Describe available tasks or one specific task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rbconfig' | |
# Based on a script at: | |
# http://stackoverflow.com/questions/891537/ruby-detect-number-of-cpus-installed | |
class CpuCounter | |
def self.count | |
new.count | |
end | |
def count |
OlderNewer