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
public class Palindrome { | |
// This method checks whether its input reads the same forwards | |
// as backwards. For example, isPalindrome("noon") should return | |
// true, but isPalindrome("night") should return false. | |
// Note that this implementation contains a deliberate bug. | |
public static boolean isPalindrome(String s) { | |
if (s.length() == 0) { |
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
class BasicObject | |
def &&(other) | |
other | |
end | |
def ||(other) | |
self | |
end | |
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
require 'memoist' | |
# Usage: | |
# | |
# customers = Customer.preload(Customer.orders.line_items.item) | |
# | |
# customers.each do |customer| | |
# customer.orders.each do |order| | |
# order.line_items.each do |line_item| | |
# line_item.item # yay, no more N+1, only 4 queries executed ! |