Skip to content

Instantly share code, notes, and snippets.

View thorwebdev's full-sized avatar
🔨
building

Thor 雷神 Schaeff thorwebdev

🔨
building
View GitHub Profile
<div id="log"></div>
<script type="text/javascript" src="https://dl.dropboxusercontent.com/sh/oexkzj4z2zzs02d/AADB02b-GUnvoxDr9EvD61yZa/adyen.encrypt.nodom.min.js"></script>
<script src="https://js.braintreegateway.com/js/braintree-2.22.2.min.js"></script>
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script type="text/javascript">
(function() {
//Copy your public keys here
var stripePK = "pk_test_jg6c4WIhuzDD7kcYW0Nu7T6r";
var adyenPK = "10001|B01FDAF7CD9B73F094906C5B078963FAAE57AFC619D561EFC784EA505EC6CCA94AF0CA3F97CA9CFC04E2151F39A461BF45DE7CB7DEA46C56EB3420502DA69BF4A6FFA21464D46861051367A26422EF3A9E6288F821CB47E8F88B4C2D9BEEF96AF0686E6F1C4171C5B5BD1C80E23A112BE57B990389E783B8F614F07CDBBBB68D7175F0282C7E0FA985D881E2A9EB6B54BE231D5733912A217F92D5952C6AA1ECF1765F11337441502FFCDD9B9DD3F2A40F98E96DDF51E60B06D8987D3622EB119AF7360055626DC99E6555724FBBFC1F985DB506E16E6A9B040959799C3C6ADD7F21C97493D7823CE7A234491377165815CE075ED55375F772F101DA0335D70D";
var brainTreePK
@thorwebdev
thorwebdev / avg_fare_amount.sql
Created December 15, 2014 20:43
These are some interesting queries you can run on this BigQuery table: https://bigquery.cloud.google.com/table/nyctaximap:dataflow.nyc_output_join_fare_distinct . The data has been aggregated using Google Cloud Dataflow. For more background information on how the data has been processed see: https://googlecloudplatform.blogspot.com
SELECT
pickup_polyId,
SUM(fare_amount)/COUNT(*) AS average_fare,
COUNT(*) AS no_of_trips
FROM
[nyctaximap:dataflow.nyc_output_join_fare_distinct]
WHERE
fare_amount!=0
GROUP BY
pickup_polyId
@thorwebdev
thorwebdev / no_of_trips.sql
Created December 15, 2014 20:34
Calculate the number of trips that started in a certain area.
SELECT
pickup_polyId,
COUNT(*) AS no_of_trips
FROM
[nyctaximap:dataflow.nyc_output_join_fare_distinct]
GROUP BY
pickup_polyId
ORDER BY
no_of_trips DESC;
@thorwebdev
thorwebdev / avg_fare_amount.sql
Last active August 29, 2015 14:11
Calculate the average fare amount for each area. Exclude fares with value 0.
SELECT
pickup_polyId,
SUM(fare_amount)/COUNT(*) AS average_fare,
COUNT(*) AS no_of_trips
FROM
[nyctaximap:dataflow.nyc_output_join_fare_distinct]
WHERE
fare_amount!=0
GROUP BY
pickup_polyId
@thorwebdev
thorwebdev / avg_tip_amount.sql
Last active August 29, 2015 14:11
Calculate the average tip amount for each area with more than 50,000 trips that have a tip recorded. Exclude tips with value 0.
SELECT
pickup_polyId,
SUM(tip_amount)/COUNT(*) AS average_tip,
COUNT(*) AS no_of_trips
FROM
[nyctaximap:dataflow.nyc_output_join_fare_distinct]
WHERE
tip_amount!=0
GROUP BY
pickup_polyId
@thorwebdev
thorwebdev / queryPoint_snippet.java
Last active August 29, 2015 14:10
We need an endpoint to test any latitude-longitude-pair against all our fences. This is the actual geofencing part. We want to be able to know, if the point falls into any of our fences and if so, we want to get back the ids of the fences the point is in. For this we first need to retrieve our index from Memcache. We then query the index with th…
@ApiMethod(name = "point", httpMethod = "get", path = "point")
public ArrayList < MyFence > queryPoint(@Named("group") String group, @Named("lng") double lng, @Named("lat") double lat) {
ArrayList < MyFence > fences = new ArrayList < MyFence > ();
//Get the Index from Memcache.
MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
GeometryFactory gf = new GeometryFactory();
STRtree index = (STRtree) syncCache.get(group); // read from cache
if (index != null) {
Coordinate coord = new Coordinate(lng, lat);
@thorwebdev
thorwebdev / polyline_snippet.java
Last active August 29, 2015 14:10
The process of testing for a point can easily be adapted to test our fences against polylines and polygons. In the case of polylines we query the index with the polyline’s bounding box and then test if the polyline actually crosses the returned fences.
@ApiMethod(name = "polyline", httpMethod = "post", path = "polyline")
public ArrayList < MyFence > queryPolyLine(@Named("group") String group, MyPolyLine polyline) {
ArrayList < MyFence > fences = new ArrayList < MyFence > ();
//Get the index from Memcache.
MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
GeometryFactory gf = new GeometryFactory();
STRtree index = (STRtree) syncCache.get(group); // read from cache
if (index != null) {
//Create coordinate array.
@thorwebdev
thorwebdev / polygon_snippet.java
Last active August 29, 2015 14:10
When testing for a polygon I want to get back all fences that are either completely or partly contained in my polygon. Therefore I test if the returned fences are within my polygon or are not disjoint.
@ApiMethod(name = "polygon", httpMethod = "post", path = "polygon")
public ArrayList < MyFence > queryPolygon(@Named("group") String group, MyPolyLine polyline) {
ArrayList < MyFence > fences = new ArrayList < MyFence > ();
//Get index from Memcache
MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
STRtree index = (STRtree) syncCache.get(group); // read from cache
if (index != null) {
//Create coordinate array.
double[][] points = polyline.getCoordinates();
@thorwebdev
thorwebdev / listFences_snippet.java
Created December 7, 2014 16:04
For some use cases it makes sense to fetch all the fences at once in the beginning, so we want to have an endpoint to list all fences from a certain group.
@ApiMethod(name = "list", httpMethod = "get", path = "list")
public ArrayList < MyFence > listFences(@Named("group") String group) {
ArrayList < MyFence > fences = new ArrayList < MyFence > ();
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key fenceKey = KeyFactory.createKey("Geofence", group);
Query query = new Query("Fence", fenceKey).addSort("id", Query.SortDirection.DESCENDING);
List < Entity > fencesFromStore = datastore.prepare(query).asList(FetchOptions.Builder.withDefaults());
@thorwebdev
thorwebdev / getFenceById_snippet.java
Created December 7, 2014 16:03
When we query our fences we only return the ids of the fences that were returned, therefore we need an endpoint to retrieve the metadata that corresponds to a fence id. This endpoint simply accepts an id, queries the Datastore and returns the metadata of the fence with the corresponding id.
@ApiMethod(name = "getById", httpMethod = "get", path = "getById")
public ArrayList < MyFence > getFenceById(@Named("group") String group, @Named("id") long id) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key fenceKey = KeyFactory.createKey("Geofence", group);
Filter propertyFilter = new FilterPredicate("id", FilterOperator.EQUAL, id);
Query query = new Query("Fence", fenceKey).setFilter(propertyFilter);
Entity fenceFromStore = datastore.prepare(query).asSingleEntity();
ArrayList < MyFence > fences = new ArrayList < MyFence > ();
if (fenceFromStore != null) {