Skip to content

Instantly share code, notes, and snippets.

View nomadrat's full-sized avatar
:shipit:
Working from the wormhole

Dmitry S. nomadrat

:shipit:
Working from the wormhole
View GitHub Profile
@nomadrat
nomadrat / cloudflare-worker-geolocation-fetch.js
Created December 3, 2022 15:52
How To Access Cloudflare Worker From The Browser
async function fetchVisitorGEO() {
const response = await fetch('https://empty-bird-5317.your-name.workers.dev/');
const ipInfo = await response.json();
console.log(ipInfo);
}
fetchVisitorGEO();
/** OR */
@nomadrat
nomadrat / cloudflare-worker.js
Created December 3, 2022 15:20
Geolocate the Location of an IP Address With Cloudflare Workers
/**
Read more at:
https://abstractkitchen.com/blog/geolocation-with-cloudflare-workers/
*/
addEventListener("fetch", event => {
const city = event.request.cf.city;
const country = event.request.cf.country;
const clientIP = event.request.headers.get("CF-Connecting-IP");
from flask import Flask
app = Flask(__name__)
app.config["SERVER_NAME"] = "flaskapp.local:5000"
@app.route("/")
def root_index():
return "this is flaskapp.local"
@nomadrat
nomadrat / create_sitemap.py
Last active August 12, 2022 07:43
create sitemap. python
#
# this is part of https://abstractkitchen.com/blog/sitemaps-for-devs
#
import os
import gzip
from xml.etree import cElementTree
import coordtransform from "coordtransform";
mapboxgl.accessToken = '<your mapbox access token>';
let exampleMap;
// CHANGE WITH COORDINATES FROM HERE http://api.map.baidu.com/lbsapi/getpoint/
const bd09Coords = [113.341334, 23.193119];
function renderMap() {
function flatten(inputArray) {
/**
* One can argue that it's a good idea to validate inputArray
* value here, but i disagree. In this exact case it's better
* to not reinvent the wheel — if inputArray is not an Array
* application will throw error anyway at .reduce step
*/
return inputArray.reduce((accumulator, current) => {
function getLocale() {
return (navigator.userLanguage || navigator.language || navigator.systemLanguage).toLowerCase();
}
function loadScript(src, fn) {
var script, done, head;
script = document.createElement('script');
script.src = src;
script.async = true;
script.onload = script.onreadystatechange = function() {
if (!done && (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete')) {
done = true;