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
#!/bin/sh | |
# install shit on mac osx | |
# author: mcor | |
# date: 2015-12-17 | |
# install brew | |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
# install cask | |
brew tap caskroom/cask |
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
// https://blog.gaplotech.com/content/images/2016/06/Screen-Shot-2016-06-22-at-22-09-29.png | |
// Result not consistent : 12291 false, 37709 true | |
for(var i=0; i<50000; ++i) { | |
console.log(typeof null === 'undefined') | |
} | |
// OR | |
for(var i=0; i<50000; ++i) { | |
console.log(typeof null == 'undefined') | |
} |
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
// Kotlin null safe example | |
// Java null risk example https://gist.github.com/gaplo917/5dc037bedea39a348854ae59ba89c063 | |
fun doSth(str: String): String { | |
return str.toLowerCase() | |
} | |
fun doSthOptional(str: String?): String? { | |
// Optional chainning, similiar to Swift | |
return str?.toLowerCase() |
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
// Java null risk workaround example | |
// Kotlin null safe example https://gist.github.com/gaplo917/77d7ee9f48ed20f4a60bc20a1b39a2e6 | |
import org.jetbrains.annotations.NotNull; | |
import org.jetbrains.annotations.Nullable; | |
import java.util.Optional; | |
import static java.lang.System.*; | |
class NullRisk { |
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
// Java 9 | |
final Map<String,Integer> abc = Map.of("a",1, "b", 2, "c", 3); | |
// Java >= 5 | |
final Map<String,Integer> abc = new HashMap<String, Integer>() {{ | |
put("a",1); | |
put("b",2); | |
put("c",3); | |
}}; |
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
// Java | |
// Ugly work around to save time (compared to method overload) | |
void doSomething( | |
@NotNull String fname, | |
@NotNull String lname, | |
@Nullable String addr, | |
@Nullable Gender gender | |
) { | |
requireNonNull(fname); | |
requireNonNull(lname); |
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
// Kotlin | |
// Default argument | |
fun doSomething( | |
fname: String, | |
lname: String, | |
addr: String = "N/A", | |
gender: Gender = Gender.Unknown | |
){ | |
// do something that really need fname,lname, addr, gender.. | |
} |
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
// Java | |
// please focus on the function name & declaration | |
// As we all know, String is a final class and we can't extend | |
class StringUtils{ | |
public static TypeA toTypeA(String str) | |
} | |
// Assume TypeA is from third party library that you can't extend | |
class TypeAUtils { |
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
// Kotlin | |
// extension, give toTypeA() functionality to String | |
fun String.toTypeA(): TypeA { | |
return TypeA(str = this) | |
} | |
// give calculateResult() functionality to TypeA | |
fun TypeA.calculateResult(): Double { | |
return this.str.length + 0.123456789 |
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
// Kotlin | |
data class User( | |
// primary construtor | |
val id: UUID, | |
val username: String, | |
val firstName: String? = null, | |
val lastName: String? = null, | |
val address: String? = null, | |
val isEmailVerified: Boolean = false |
OlderNewer