- What order (Invoice) was the most expensive?
Total: 25.86,
SELECT Invoice.InvoiceId, MAX(Invoice.Total) FROM Invoice;
InvoiceId: 404,
CustomerId: "6",
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
# Add factorial method to Math standard module in Ruby | |
module Factorial | |
def factorial(n) | |
Integer Math.gamma(n.to_i + 1) | |
end | |
end | |
Math.extend Factorial |
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
ActiveSupport::Inflector.inflections(:en) do |inflect| | |
inflect.plural('human', 'humans') | |
inflect.plural('cayman', 'caymans') | |
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
# CAUTION, it opens String class | |
String.class_eval do | |
# HACK: quick and dirty english pluralization. | |
def to_plural(*arg) | |
plural = lambda do |str| | |
if str =~ /\s\z|men\z|people\z|[^aious]s\z/i # is a plural already | |
str | |
elsif str =~ /\Aman\z|woman\z/i # man & woman, except caiman, human... | |
str.sub(/an\z/i, 'en') | |
elsif str =~ /[^aeiou][aeiou]?(f|fe)\z/ # knife, half... |
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
// Number.formatISOAPA returns a correctly SI+APA formatted number. | |
// (SI, System Internationale) ISO 31-0 & APA style EXPLANATION: | |
// <https://en.wikipedia.org/wiki/ISO_31-0#Numbers> | |
// ISO 31-0: The decimal sign is either the comma on the line | |
// or the point on the line. Both "1,33" & "1.33" are valid. | |
// ISO 31-0: Do not use "." nor "," for thousand separators. | |
// Both "1,000.00" "1.000,00" are INVALID. | |
// ISO 31-0: For numbers whose magnitude is less than 1, the decimal | |
// sign should be preceded by a zero. "0.5" instead of ".5" | |
// APA style: Psychologically, there is no need to group numbers with |
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
# Countdown class is for making countdown ranges without reversing. | |
# a = Countdown.new 5 | |
# b = Countdown.new 1 | |
# print (a..b).map(&:value).join(', ') # => | |
# 5, 4, 3, 2, 1 => nil | |
class Countdown | |
VERSION = 0 | |
attr_accessor :value | |
def initialize(value) |
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
# Caesar cipher module | |
# | |
# USAGE: | |
# ===== | |
# ```ruby | |
# my_var = Plaintext.new 'TOO MANY SECRETS' | |
# my_var.rotn # => "GBB ZNAL FRPERGF" | |
# my_var # => "TOO MANY SECRETS" | |
# ``` | |
# There is a bang method to make changes permanent: |
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
// Can be run online at https://p5js.org/ or alpha.editor.p5js.org/full/SykVmQWVG | |
const SCREEN = { | |
width: 800, | |
height: 600 } | |
const T12 = { | |
radii: [5.943, 7.290, 8.365, 11.315, 12.576, 14.497, 13.067, 12.151, 8.788, 7.941, 6.383, 5.495], | |
cavity: 38.149 } | |
const FACTOR = 4 | |
var myCircles |
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 EXAMPLES: | |
Is the tenth row hidden? | |
> isRowHidden(sheet.getRange('B10')) | |
Is column B hidden? | |
> isColumnHidden(sheet.getRange('B10')) | |
Is cell B10 visible? (not in a hidden row and/or column) |
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
#!/usr/bin/env bash | |
# C9.io Installation of the Red Language. +Info on "red-lang.org". | |
## USAGE: `chmod +x ./install-red.sh && sudo ./install-red.sh` | |
REDLANG_PATH="/usr/local" | |
# For Linux 64-bit distros, you need to install 32-bit supporting libraries. | |
# So, for Debian-based distros, install them using: |
OlderNewer