Skip to content

Instantly share code, notes, and snippets.

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
// 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);
}
});
// 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 + "; "));
// 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
// ------------------------- 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;
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) {
<!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],
@rayhon1014
rayhon1014 / .htaccess
Last active February 11, 2017 09:12
Useful wordpress settings
# 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
@rayhon1014
rayhon1014 / wordpress_db.sql
Last active February 11, 2017 21:40
Useful wordpress database commands
#-------------------------------------------------------
# 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');
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());
}