Skip to content

Instantly share code, notes, and snippets.

@rayhon1014
rayhon1014 / US Zip Codes from 2013 Government Data
Created June 20, 2018 18:16 — forked from erichurst/US Zip Codes from 2013 Government Data
All US zip codes with their corresponding latitude and longitude coordinates. Comma delimited for your database goodness. Source: http://www.census.gov/geo/maps-data/data/gazetteer.html
This file has been truncated, but you can view the full file.
ZIP,LAT,LNG
00601,18.180555, -66.749961
00602,18.361945, -67.175597
00603,18.455183, -67.119887
00606,18.158345, -66.932911
00610,18.295366, -67.125135
00612,18.402253, -66.711397
00616,18.420412, -66.671979
00617,18.445147, -66.559696
00622,17.991245, -67.153993
// Wrap the $.getJSON() call to return a real Promise
// properly handling rejection with the available `.fail` method
var fetchJSON = function(url) {
return new Promise((resolve, reject) => {
$.getJSON(url)
.done((json) => resolve(json))
.fail((xhr, status, err) => reject(status + err.message));
});
}
// 2 problems for the code below:
// (1) use somethingAsync(function(err, result)) format that could swallowed up the error in the nested call.
// (2) nested async call as a whole can be flattened out
firstThingAsync().then(function(result) {
// handle success but any error coming from secondThingAsync() will be swallowed
secondThingAsync().then(function(result2) {
// do something with result1 and result2
});
},
function(err) {
package example;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import com.amazonaws.util.StringUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import example.model.ApiGatewayRequest;
import example.model.ApiGatewayResponse;
import example.model.Article;
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());
}
@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');
@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
<!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],
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) {
// ------------------------- 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;