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
$.fn.mobileScroll = function(options) { | |
if (typeof options !== 'string') { | |
options = $.extend({}, options, { | |
minMovement: 80, | |
deadzone: 12 | |
}); | |
} | |
var extra_args = Array.prototype.slice.call(arguments).slice(1); | |
return this.each(function() { |
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 Application < Rails::Application | |
# ... | |
config.autoload_paths << File.join(config.root, "app", "workers") | |
# ... | |
end |
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
tries = [ | |
lambda { puts "1"; false }, | |
lambda { puts "2"; false }, | |
lambda { puts "3"; true }, | |
lambda { puts "4"; true } | |
] | |
puts "Found %s" % tries.inject(nil) {|v, l| v ||= l.call } | |
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
RSpec.configure do |c| | |
def profile | |
result = RubyProf.profile { yield } | |
name = example.metadata[:full_description].downcase.gsub(/[^a-z0-9_-]/, "-").gsub(/-+/, "-") | |
printer = RubyProf::CallTreePrinter.new(result) | |
open("tmp/performance/callgrind.#{name}.#{Time.now.to_i}.trace", "w") do |f| | |
printer.print(f) | |
end | |
end |
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 Enumerable | |
def each_with_position *args, &block | |
puts "#each_with_position called!" | |
# EachWithPosition::Handler.new(:each, self, *args, &block).invoke! | |
end | |
end | |
[].each_with_position # => "#each_with_position called!" |
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 'rufus/scheduler' | |
class CronManager | |
def self.schedule(redis, &block) | |
@singleton ||= new(redis, &block) | |
end | |
def every(timing, options = {}, &block) | |
# In order to make sure that jobs are executed at the same time regardless of who runs them | |
# we quantitize the start time to the next-nearest time slice. This more closely emulates | |
# cron-style behavior. |
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 'rufus/scheduler' | |
class CronManager | |
def self.schedule(redis, options = {}, &block) | |
log options[:logger], "Booting #{self.to_s}..." | |
if Object.const_defined? :Rails | |
return unless options[:permit_test_mode] if Rails.env.test? | |
end | |
options[:worker] ||= :sidekiq if Object.const_defined? :Sidekiq |
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
12:15:43 AM - yakko: I mean, as a SQL replacement? | |
12:15:48 AM - Antiarc: how do you like neo4j? | |
12:15:55 AM - blazes816: nosql don't replace sql | |
12:15:56 AM - Antiarc: I've been looking for an excuse to take it for a testdrive | |
12:15:59 AM - blazes816: that isn't how it works | |
12:16:04 AM - blazes816: I love neo | |
12:16:08 AM - pushpa has left the room (Quit: Remote host closed the connection). | |
12:16:23 AM - Antiarc: mongo is the closest to a regular column-based document store, but it's very much not 1:1 and you should have a reason to use it other than "it's not SQL" | |
12:16:25 AM - hbpoison has left the room (Quit: Read error: Connection reset by peer). | |
12:16:37 AM - blazes816: it's query language cypher is really nice, and there's a good ruby lib for it |
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 User | |
FILLABLE_ATTRIBUTES = [:name, :age, :sex] | |
def profile_percent_complete | |
FILLABLE_ATTRIBUTES.inject(0) {|c, u| c += send(u).present? && 1 || 0 } / FILLABLE_ATTRIBUTES.length.to_f | |
end | |
end |
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 index | |
contacts_cancan = Contact.accessible_by(current_ability) | |
respond_to do |format| | |
format.html # index.html.erb | |
format.json { render json: ContactsDatatable.new(view_context, contacts_cancan) } | |
end | |
end |