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
Future <String> marvel = executor.submit(new Callable <String> () { | |
public String call() { | |
return getMarvelHeroWithCharacter(“C”); // totally not making this up | |
} | |
}); | |
// other very important stuff of course, non-blocking ftw | |
System.out.println(marvel.get()); // this bit is blocking if the result isn’t ready yet |
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
CompletableFuture <String> cf = | |
CompletableFuture.completedFuture("I'm done!"); | |
cf.isDone(); // return true | |
cf.join(); // return "I'm done" |
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
CompletableFuture <String> marvel = executor.submit(new Callable <String> () { | |
public String call() { | |
return getMarvelHeroWithCharacter(“C”); | |
} | |
}); | |
// other stuff goes here | |
marvel.complete(“Mystique”); // sets a “default” value if not yet completed |
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
import static com.google.common.truth.Truth.assertThat; | |
Set < Foo > foo = ...; | |
assertThat(foo).isEmpty() | |
org.truth0.FailureStrategy$ThrowableAssertionError: Not true that is empty | |
at org.truth0.FailureStrategy.fail(FailureStrategy.java: 33) | |
... |
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
import org.junit.runner.RunWith; | |
import org.junit.runners.JUnit4; | |
import org.mockito.Mock; | |
import org.mockito.Mockito; | |
/** | |
* Test for CannotMockFinalClass. | |
*/ | |
@RunWith(JUnit4.class) | |
public class CannotMockFinalClassPositiveCases { |
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
import static strman.Strman.leftPad | |
leftPad("1", "0", 5) | |
// result => "00001" |
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
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() | |
.iterations(1) | |
.weightInit(WeightInit.XAVIER) | |
.activation("relu") | |
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT) | |
.learningRate(0.05) | |
// ... other hyperparameters | |
.backprop(true) | |
.build(); |
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 static String randomString(int i) | |
{ | |
Random ran = new Random(i); | |
StringBuilder sb = new StringBuilder(); | |
while (true) | |
{ | |
int k = ran.nextInt(27); | |
if (k == 0) | |
break; |
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 static void main(String[] args) throws ParseException { | |
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
String str3 = "1927-12-31 23:54:07"; | |
String str4 = "1927-12-31 23:54:08"; | |
Date sDt3 = sf.parse(str3); | |
Date sDt4 = sf.parse(str4); | |
long ld3 = sDt3.getTime() /1000; | |
long ld4 = sDt4.getTime() /1000; | |
System.out.println(ld4-ld3); | |
} |
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
for (int i = 0; i < 100000; ++i) | |
{ | |
// Primary loop | |
for (int c = 0; c < arraySize; ++c) | |
{ | |
if (data[c] >= 128) | |
sum += data[c]; | |
} | |
} |
OlderNewer