The arel_extensions gem has a couple of bugs...
DateSubdoesn't work:
(table[:column] - 10.hours).to_sql
# => NoMethodError: undefined method `to_sql' for nil:NilClass- For MySQL,
DateAddgenerates a double-minus when given a negative duration:
The arel_extensions gem has a couple of bugs...
DateSub doesn't work:(table[:column] - 10.hours).to_sql
# => NoMethodError: undefined method `to_sql' for nil:NilClassDateAdd generates a double-minus when given a negative duration:| #!/usr/bin/env ruby | |
| # Custom Psych parser that captures line number information from a YAML file. | |
| # | |
| # For a project I'm working on I need to be able to determine which line(s) in a YAML | |
| # file a particular value comes from. There are a few bits of advice on the internet | |
| # about this, the best of them that I've found involves monkey-patching, which is a | |
| # fairly low bar for "best" in my opinion. I found it on Stack Overflow: | |
| # | |
| # https://stackoverflow.com/questions/29462856/loading-yaml-with-line-number-for-each-key |
| # Examples | |
| # | |
| # MyModel.order(MyModel.arel_table[:name].asc.nulls_last) | |
| # MyModel.order(MyModel.arel_table[:name].desc.nulls_first) | |
| module Arel | |
| module NullOrder | |
| def nulls_last | |
| Arel::Nodes::NullsLast.new self | |
| end |
| #!/usr/bin/env ruby | |
| # Usage: ruby rails-locales-conflicts.rb [<rails root>] | |
| require "pathname" | |
| require "yaml" | |
| class Translations | |
| def initialize | |
| @translations = Hash.new do |h, k| |
| def common_array_prefix(*arrays) | |
| arrays.reduce do |a, b| | |
| index = a.zip(b).index { |x, y| x != y } | |
| a[0...index] | |
| end | |
| end | |
| def common_string_prefix(*strings) | |
| common_array_prefix(*strings.map(&:chars)).join("") | |
| end |
| #!/usr/bin/env ruby | |
| # Converts the output from reek to GitHub-flavoured Markdown. | |
| # | |
| # Usage: | |
| # Basically pipe the output from reek through this script. | |
| # | |
| # reek --sort-by smelliness app lib | ruby reek-to-markdown.rb | |
| def scan_line(line, pattern) |
Solutions to the Calculating with Functions CodeWars kata.
| module FlexStruct | |
| def initialize(*args, **options) | |
| super(*args, *options.values_at(*members[args.length..-1])) | |
| end | |
| def self.new(*args, &block) | |
| Struct.new(*args, &block).include self | |
| end | |
| end |
I hereby claim:
To claim this, I am signing this object:
| # logfilename [owner:group] mode count size when flags [/pid_file] [sig_num] | |
| /Users/your-username/path-your-rails-project/log/*.log your-username:staff 644 4 * $D0 GJ | |
| # NOTES | |
| # | |
| # Place file in /etc/newsyslog.d | |
| # '$D0' under 'when' tells newsyslog to rotate logs daily at midnight. | |
| # Alternatively you could use '24' for 'when', which would specify "every 24 hours" | |
| # '*' under 'size' specifies that logs should be rotated regardless of their size. | |
| # 'G' under 'flags' tells newsyslog that the 'logfilename' is a pattern and it should rotate all log files matching the pattern. |