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
ActiveAdmin.register Project do | |
# Don't forget to add the image attribute (here thumbnails) to permitted_params | |
controller do | |
def permitted_params | |
params.permit project: [:title, :summary, :description, :thumbnail, :date, :url, :client_list, :technology_list, :type_list] | |
end | |
end | |
form do |f| |
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
# It extends activeadmin to show pretty boolean values | |
# | |
# config/initializers/active_admin.rb | |
module ActiveAdmin | |
module Views | |
class TableFor | |
def bool_column(attribute) | |
column(attribute){ |model| model[attribute] ? '✔'.html_safe : '✗'.html_safe } | |
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 self.easter(year) | |
y = year | |
a = y % 19 | |
b = y / 100 | |
c = y % 100 | |
d = b / 4 | |
e = b % 4 | |
f = (b + 8) / 25 | |
g = (b - f + 1) / 3 | |
h = (19 * a + b - d - g + 15) % 30 |
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 gravatar_url(size) | |
gravatar_id = Digest::MD5.hexdigest(email.downcase) | |
"http://gravatar.com/avatar/#{gravatar_id}.png?s=#{size}" | |
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
# Usage | |
# DJ config | |
require Rails.root.join('lib', 'dj_plugin.rb') | |
Delayed::Worker.plugins << Delayed::Plugins::EmailNotify | |
# lib/dj_plugin.rb | |
require 'exception_notification' |
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
# Usage: | |
# | |
# peak_memory = track_memory do | |
# 1000000.times { |i| puts i } | |
# end | |
# | |
# puts peak_memory | |
# -> 845073 | |
require 'thread' |
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
Plugboard = Hash[*('A'..'Z').to_a.shuffle.first(20)] | |
Plugboard.merge!(Plugboard.invert) | |
Plugboard.default_proc = proc { |hash, key| key } | |
def build_a_rotor | |
Hash[('A'..'Z').zip(('A'..'Z').to_a.shuffle)] | |
end | |
Rotor_1, Rotor_2, Rotor_3 = build_a_rotor, build_a_rotor, build_a_rotor |
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 'benchmark' | |
# Levenshtein algorithm written in pure ruby. | |
# https://github.com/threedaymonk/text | |
require 'text' | |
# Levenshtein algorithm in C++ with ruby wrapper | |
# https://github.com/dbalatero/levenshtein-ffi | |
require 'levenshtein' |
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
#!/bin/sh | |
# | |
# Check for ruby style errors | |
red='\033[0;31m' | |
green='\033[0;32m' | |
yellow='\033[0;33m' | |
NC='\033[0m' | |
if git rev-parse --verify HEAD >/dev/null 2>&1 |
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
function sum(from, to) { | |
let total = 0 | |
for (let i = from; i <= to; i += 1) { | |
total += i | |
} | |
return total | |
} |
OlderNewer