Skip to content

Instantly share code, notes, and snippets.

View rafaltrojanowski's full-sized avatar
🛰️
KISS (BUZI), DRY, SOLID, YAGNI

Rafał Trojanowski rafaltrojanowski

🛰️
KISS (BUZI), DRY, SOLID, YAGNI
View GitHub Profile
puts JSON.pretty_generate(PresenceSerializer.new(Presence.first).serializable_hash)
def self.to_google_params(params)
def self.map_it(hash, mappings)
sliced_hash = hash.slice(*mappings.keys)
Hash[sliced_hash.map {|k, v| [mappings[k], v] }]
end
# Our style is exclude = true. Google's is include = true. So we need to invert the value.
params[:privacy] = !params[:privacy] if params.has_key? :privacy
{}.tap do |google_params|
# add newer versions to this array if the method definition didn't change, otherwise do an if-cascade
if ['0.7.0'].include?(I18n::VERSION)
module I18n
module Backend
class Simple
# Monkey-patch-in localization debugging.. ( see: http://www.unixgods.org/~tilo/Rails/which_l10n_strings_is_rails_trying_to_lookup.html )
# Enable with ENV['I18N_DEBUG']=1 on the command line in server startup, or ./config/environments/*.rb file.
#
def lookup(locale, key, scope = [], options = {})
init_translations unless initialized?
Devise.stretches = 1
User.find_each do |user|
user.password = 'q1w2e3r4'
user.save
end
Devise.stretches = 10
test "Sebastian commented on Matylda's gallery: Looks awesome!", (assert) ->
assert.expect 1
commenter = Ember.Object.create( # mock for Ember DS.Model
displayName: "Sebastian"
)
galleryOwner = Ember.Object.create(
id: 2,
displayName: "Matylda"
)
def solution(n)
binary_array = to_binary(n)
i = 0
j = 0
max = 0
counter = 0
while i < binary_array.size - 1
def solution(a)
hash = {}
a.each do |element|
if hash[element].nil?
hash[element] = 1
else
hash[element] += 1
end
def solution(a)
((1..a.size + 1).to_a - a).first
end
def solution(a)
sum = 0
sum = a.inject(&:+)
l = 0
r = 0
p = 0
ret = nil
def solution(a)
# write your code in Ruby 2.2
i = 1
hash = {}
a.each do |element|
hash[element] = 1
end
while 1 do