Skip to content

Instantly share code, notes, and snippets.

@tsamaya
tsamaya / nodejs.shebang
Created May 13, 2023 16:05
NodeJS Shebang
#!/usr/bin/env node
@tsamaya
tsamaya / release.sh
Created April 19, 2023 13:28
my tiny release script
#!/usr/bin/env bash
if [ -z "$1" ]; then echo "usage release.sh [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]"; exit 1; else echo "npm version is set to ${1}"; fi
set -e
set -x
echo "--status"
git status
echo "--checkout develop"
@tsamaya
tsamaya / index.html
Created March 22, 2023 08:32
Maplibre Geocoding with Opencage
<!-- Load the `maplibre-gl-geocoder` plugin. -->
<div id="map"></div>
@tsamaya
tsamaya / tomtom-traffic-with-leaflet.html
Created May 20, 2020 05:20
Tomtom Traffic API use with leaflet
<!DOCTYPE html>
<html>
<head>
<title>Quick Start - Leaflet</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
service: opencage-geocoder
provider:
name: google
runtime: nodejs8
project: opencage-123456
credentials: ~/.gcloud/keyfile.json
region: us-central1
plugins:
- serverless-google-cloudfunctions
- serverless-env-generator
# Plugin config goes into custom:
custom:
envFiles: #YAML files used to create .env file
- environment.yml
functions:
opencage:
handler: geocode
events:
- http: geocode
@tsamaya
tsamaya / geocode.js
Last active November 11, 2018 20:42
require('dotenv').config();
const opencage = require('opencage-api-client');
exports.geocode = (request, response) => {
if (!request.query) {
response.status(400).send({error: 400, message: "Couldn't read query parameters"});
return;
}
if (typeof process.env.OCD_API_KEY === 'undefined' && typeof request.query.key === 'undefined') {
response.status(403).send({error: 403, message: 'missing API key'});
return;
{/* MAP result */}
{activeTab === MAP_TAB &&
results.length > 0 && <ResultMap response={this.props.response} />}