Skip to content

Instantly share code, notes, and snippets.

View moosetraveller's full-sized avatar

Thomas Zuberbühler moosetraveller

View GitHub Profile
@moosetraveller
moosetraveller / convert_pdf.py
Last active September 22, 2021 22:34
Convert a PDF File to Images
"""
Converts PDF pages to images.
```python
pip install PyMuPDF
pip install PySimpleGUI
```
:See also:
https://pymupdf.readthedocs.io/en/latest/faq.html
@moosetraveller
moosetraveller / fetch.md
Last active February 28, 2022 18:19
Using fetch with async/await

Cheat Sheet of Thomas Zuberbuehler :)

Retrieve GET

async function retrieveUser(firstName) {

    const response = await fetch(url + "?" + new URLSearchParams({
        firstName: firstName,
    });
 
@moosetraveller
moosetraveller / cheat-sheet-arcgis-js-api.md
Created August 12, 2021 22:59
ArcGIS for JavaScript Cheat Sheet

Add Tooltip to Feature in GraphicsLayer

Note: Works with ArcGIS for JavaScript 3.35, should work with 4.x

let layer = new GraphicsLayer();

layer.on("graphic-node-add", (event) => {

  const title = document.createElementNS("http://www.w3.org/2000/svg", "title");
  
  const isRestaurant = event.graphic.attributes.isRestaurant;
@moosetraveller
moosetraveller / draggable-panel.md
Created August 12, 2021 22:57
Javascript: Draggable Panel

Make Panel Draggable

HTML

<div id="panelContainer">
    <div id="panelTitle">Title</div>
    <div id="panelBody">Body</div>
</div>

CSS

@moosetraveller
moosetraveller / jupyter-notes.md
Created August 12, 2021 22:53
Run Jupyter on a Remote Computer

Run Jupyter on a Remote Computer

If you run Jupyter on a remote computer, you could start Jupyter with --ip 0.0.0.0 and access with the remote computer's IP address. However, this leaves your data wide open to anyone in the internet.

Alternatively, you could also use SSH Port Forwarding:

  1. Start Jupyter on the remote computer with
    jupyter notebook --no-browser --port=XXXX
  2. Enable port forwarding on your local machine with
    ssh -N -f -L localhost:YYYY:localhost:XXXX remoteuser@remotehost
  3. Simply access Jupyter Lab on your local machine with http://localhost:XXXX
@moosetraveller
moosetraveller / multiple-ssh-keys.md
Created August 12, 2021 22:53
How to use multiple SSH keys

How to use multiple SSH keys

Note: Replace USER_NAME with your username.

Create SSH Key

In this scenario we assume that we use two different GIT repos:

  1. Run ssh-keygen -t rsa -C "[email protected]"
  2. Enter file name (and path), e.g. C:\Users\USER_NAME\.ssh\id_rsa_github
  3. Type in a passphrase (use a secure, long passphrase)
  4. Confirm passphrase
  5. Re-do step 1 to 4 for id_rsa_azure
@moosetraveller
moosetraveller / download-instagram-images.py
Last active August 1, 2021 19:56
Download Instagram Images with Python and instagram-scraper
import os
import json
import requests
import shutil
# prerequisites:
# pip install instagram-scraper
# pip install requests
# do only use to download your own images
@moosetraveller
moosetraveller / net-core-exception-filter.md
Last active March 11, 2021 18:16
UnhandledExceptionFilter

Example of an Exception Filter

using System;
using System.Net;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
@moosetraveller
moosetraveller / convert-image-to-base64-string.md
Last active March 6, 2024 14:27
Download and Convert Image to Base64 String

Download and Convert Image to Base64 String

Following code snippet fetches the image from an URL and converts the blob to a base64 string before saving the file to the file system. (Saving the file to the file system can be considered being additional boilerplate as a conversion from a blob to a base64 string is not needed to save a file to the file system. See second example.)

The code snippets shows how to:

  • download an image from a server
  • convert image to a base64 string
/**
 * Fetches an image from given URL.
@moosetraveller
moosetraveller / simple-asp-dotnet-proxy.md
Last active May 26, 2024 00:51
Simple ASP.NET Core HTTP Proxy

Simple ASP.NET Core HTTP Proxy

Why needed?

There is no Esri Proxy (https://github.com/Esri/resource-proxy) for ASP.NET Core. However, it's very easy to implement a simple ASP.NET HTTP proxy. The solution below is not a full replacement of proxy.ashx but elaborates an idea how to handle CORS issues and login credential in a webmap application.

Note: If you have authorization and access to configure the webserver and/or configure ArcGIS Online services, there may be other alternatives (https://github.com/Esri/resource-proxy#alternatives). In addition, it may be worth to consider a dedicated proxy server (depending on the traffic).

Requirements

The NuGet Package AspNetCore.Proxy (https://github.com/twitchax/AspNetCore.Proxy) must be installed.

appsettings.json