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 self.recursive_symbolize_keys! hash | |
| hash.symbolize_keys! | |
| inner = hash.values.select{|v| v.is_a? Hash}.each{|h| recursive_symbolize_keys!(h)} | |
| inner.each {|inner| hash.merge(inner)} | |
| hash | |
| 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
| for i in [1,2,3]: | |
| print i | |
| else: | |
| print 4 | |
| #Will print 1 2 3 4 | |
| #But if you break the loop... | |
| for i in [1,2,3]: | |
| print i |
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
| import RPi.GPIO as GPIO | |
| import urllib2 | |
| import simplejson | |
| import time | |
| import sys | |
| GPIO.setmode(GPIO.BCM) | |
| print "Setup Pin 10 to output" | |
| GPIO.setup(10, GPIO.OUT) |
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
| public T orElse(T other) | |
| public T orElseGet(Supplier<? extends T> other) |
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
| import java.util.Optional; | |
| public class OptionalOrElse { | |
| public static void main(String[] args) { | |
| // Correct usage of orElseGet. createInventoryForUser is not invoked unless. | |
| System.out.println("Using the APIs in a correct way"); | |
| findInventoryByUserId(1).orElseGet(() -> createInventoryForUser(1)); | |
| findInventoryByUserId(2).orElseGet(() -> createInventoryForUser(2)); |