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
from sklearn.datasets import load_iris | |
from sklearn.ensemble import RandomForestClassifier | |
import pandas as pd | |
import numpy as np | |
iris = load_iris() | |
print "iris.target = ", iris.target | |
print "iris.target_name = ", iris.target_names | |
# populate panda DataFrame where data parameter can take dict, numpy.narray |
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
// traditionally we will do the following to sort the list | |
List<String> names = Arrays.asList("peter", "anna", "mike", "xenia"); | |
for (String name : names) { | |
System.out.print(name + "; "); | |
} | |
// (1) Using lambda expression and functional operations | |
players.forEach((player) -> System.out.print(player + "; ")); | |
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
// traditionally we will do the following to sort the list | |
List<String> names = Arrays.asList("peter", "anna", "mike", "xenia"); | |
Collections.sort(names, new Comparator<String>() { | |
@Override | |
public int compare(String a, String b) { | |
return b.compareTo(a); | |
} | |
}); |
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
// lambda in verbose form | |
(int x, int y) -> {return x + y} | |
// for single like method body, you can remove { } and return. | |
// due to smart input type inference for lambda, you also do not need to specify data type. | |
(x, y) -> x + y | |
// lambda that takes no input and returns 5 | |
() -> 5 |
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
// ------------------------- define functional interface ------------------------------ | |
@FunctionalInterface | |
interface Converter<F, T> { | |
T convert(F from); | |
} | |
// ------------------------- use it in the code --------------------------------------- | |
//pass static method as reference | |
Converter<String, Integer> converter = Integer::valueOf; |
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 <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier) { | |
return asyncSupplyStage(asyncPool, supplier); | |
} | |
public <U> CompletableFuture<U> thenApply(Function<? super T,? extends U> fn) { | |
return uniApplyStage(null, fn); | |
} | |
public CompletableFuture<Void> thenAccept(Consumer<? super T> action) { |
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
"http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | |
<title>BarkBox - Show LOVE to your little friend</title> | |
<!-- Google Tag Manager --> | |
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': | |
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[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
# Secure wp-config.php file | |
<files wp-config.php> | |
order allow,deny | |
deny from all | |
</files> | |
# Disable Directory Indexing and Browsing | |
# Put the folowing line at the end of file. | |
Options -Indexes | |
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
#------------------------------------------------------- | |
# Migrate wordpress site to another domain name | |
#------------------------------------------------------- | |
# ref: http://coolestguidesontheplanet.com/updating-wordpress-mysql-database-after-moving-to-a-new-url/ | |
UPDATE wp_options SET option_value = replace(option_value, 'http://[old].com', 'http://[new].com') WHERE option_name = 'home' OR option_name = 'siteurl'; | |
UPDATE wp_posts SET guid = replace(guid, 'http://[old].com','http://[new].com'); | |
UPDATE wp_posts SET post_content = replace(post_content, 'http://[old].com', 'http://[new].com'); | |
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://[old].com','http://[new].com'); |
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
List<String> strList = Stream.of("1", "2", "illegal_3", "4", "illegal_5", "6").collect(Collectors.toList()); | |
//return null and filter null | |
intList = strList.stream()// same with "parallelStream()" | |
.map(x -> { | |
try { | |
return Integer.parseInt(x); | |
} catch (NumberFormatException nfe) { | |
System.err.println(nfe.getMessage()); | |
} |
OlderNewer