This file contains hidden or 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
// Text may contain bold markdown so let's make it work | |
fun formattedText(text: String): AnnotatedString { | |
// Bold ** - only one we care about right now | |
val boldPieces = text.split(Regex("\\*\\*")) | |
if (boldPieces.size == 1) { | |
return AnnotatedString(text) | |
} | |
// This does not work if the string begins with ** |
This file contains hidden or 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 timer(id) | |
start_time = Time.zone.now | |
result = yield | |
elapsed_time = Time.zone.now - start_time | |
puts "Find #{id} Execution time: #{elapsed_time.round(2)}s" | |
result | |
end |
This file contains hidden or 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
# Construct a hash to create a given model for testing | |
# Pressing return ignores the column | |
def make_me_a model | |
{}.tap do |model_hash| | |
model.columns.dup.delete_if { |x| x.name.in?(%w[created_at updated_at]) }.each do |column| | |
name = column.name | |
puts "#{name}?" | |
value = gets.chomp | |
model_hash[name.to_sym] = value if value.length > 0 | |
end |
This file contains hidden or 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
IO.readlines("db/structure.sql").each do |line| | |
if line["INSERT INTO schema_migrations"] | |
migration_id = line.split(/'/)[1] | |
puts "#{migration_id} is missing" if Dir.glob("db/migrate/#{migration_id}_*.rb").empty? | |
end | |
end |
This file contains hidden or 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/bash | |
# Get info xmrpc get the ip sort count sort for humans | |
cat /var/log/apache2/*log | grep xmlrpc | awk '{ print $1 '} | sort | uniq -c | sort -h |
This file contains hidden or 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 Models | |
def self.generate what = :model | |
Rails.application.eager_load! | |
ActiveRecord::Base.descendants.each do |model| | |
method(what)[model] | |
end | |
true | |
end | |
def self.factory model | |
factory_file_name = "spec/factories/#{model.name.underscore}.rb" |
This file contains hidden or 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
strings = ["Not Set", "Participant", "Manager"] | |
strings.product(strings).each do |pair| | |
puts sprintf("|1 |%-12s |%-12s |", *pair) | |
end |
This file contains hidden or 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 make_group col | |
<<-EOT | |
<div class="control-group"> | |
<%= form.label :#{col}, class: 'control-label' %> | |
<div class="controls"> | |
<%= form.text_field :#{col}, { class: 'input-xlarge' } %> | |
</div> | |
</div> | |
EOT | |
end |
This file contains hidden or 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
#! /usr/bin/ruby | |
require 'date' | |
require 'set' | |
quotes = $<.readlines.map { |line| line.strip } | |
tag = "#unicorns" | |
url = "https://leanpub.com/unicorns" |
NewerOlder