(See also https://gist.github.com/ryansobol/5252653)
Originally published November, 2013
How would you toggle the visibility of several controls on the page?
$$('#element_one, #element_two').invoke('toggle');
class Foo | |
def meth(a:, b:, c:) | |
method(__method__).parameters.map(&:last).each do |var| | |
instance_variable_set("@#{var}", binding.local_variable_get(var)) | |
end | |
end | |
def inspect | |
puts "@a = #{@a}" | |
puts "@b = #{@b}" | |
puts "@c = #{@c}" |
require 'base64' | |
class ValidateCsrfTokens | |
class << self | |
def validate(form_token:, cookie_token:) | |
decoded_form_token = Base64::decode64(form_token) | |
decoded_cookie_token = Base64::decode64(cookie_token) | |
form_token_length = decoded_form_token.bytes.length | |
cookie_token_length = decoded_cookie_token.bytes.length |
class ApprovalError < StandardError | |
def initialize(response) | |
@response = response | |
@request = response.request | |
end | |
def inspect | |
"uri: #{@request.uri}, response_body: #{@response.body}" | |
end | |
end |
# Cribbed from https://stackoverflow.com/questions/24438655/ruby-fibonacci-algorithm | |
def fib_memo(n, memo) | |
memo[n] ||= fib_memo(n-1, memo) + fib_memo(n-2, memo) | |
end | |
def fib(n) | |
raise "fib not defined for negative numbers" if n < 0 | |
fib_memo(n, [0, 1]) | |
end |
a = "abc\xffdef" | |
a.force_encoding('UTF-8') # => "abc\xFFdef" | |
a.encoding.name # => "UTF-8" | |
# ok | |
a.valid_encoding? # => false | |
# wtf? |
class DegreeClock | |
HOURS_PER_DAY = 24 | |
MINUTES_PER_HOUR = 60 | |
DEGREES_PER_HOUR = 360 | |
DEGREES_PER_DAY = DEGREES_PER_HOUR * HOURS_PER_DAY | |
DEGREES_PER_MINUTE = DEGREES_PER_HOUR / MINUTES_PER_HOUR | |
HOURS_PER_HALF_DAY = HOURS_PER_DAY / 2 | |
class Time |
# https://rpm.newrelic.com/account/131856/agent/3256655/metrics/425412176 | |
# https://rpm.newrelic.com/accounts/131856/plugins?type=6106 | |
# http://note.io/1bjT5FW | |
[<2013-11-08 23:00:22, 2013-11-08 23:01:22> metric: count:1 total:7.0, | |
<2013-11-08 23:01:21, 2013-11-08 23:02:21> metric: count:1 total:7.0, | |
<2013-11-08 23:02:21, 2013-11-08 23:03:21> metric: count:1 total:7.0, | |
<2013-11-08 23:03:22, 2013-11-08 23:04:22> metric: count:1 total:7.0, | |
<2013-11-08 23:04:22, 2013-11-08 23:05:22> metric: count:1 total:7.0, | |
<2013-11-08 23:05:23, 2013-11-08 23:06:23> metric: count:1 total:7.0, | |
<2013-11-08 23:06:23, 2013-11-08 23:07:23> metric: count:1 total:7.0, |
@account = Account.find(131856) | |
@account.set_shard_connection | |
@agent = Agent.find(3256655) | |
@metric = Metric.find(425412176) | |
time_window = TimeWindow.new((Time.now.utc - 1.day).to_i, Time.now.utc.to_i) | |
@timeslice_data = Timeslice.find_and_aggregate(@agent, time_window, @metric, :aggregate_time => false, :raw_data => true) |
class PluginRater | |
def self.rate_plugin_for_user!(rating, plugin, user) | |
plugin.update_rating_for_user(rating, user) | |
Event::Publish('user_rated_a_plugin', rating, plugin, user) | |
Auditor::AuditRatingChange(rating, plugin, user) | |
end | |
end | |
class Controller | |
def rate |
(See also https://gist.github.com/ryansobol/5252653)
Originally published November, 2013
How would you toggle the visibility of several controls on the page?
$$('#element_one, #element_two').invoke('toggle');