Skip to content

Instantly share code, notes, and snippets.

View moosetraveller's full-sized avatar

Thomas Zuberbühler moosetraveller

View GitHub Profile
@moosetraveller
moosetraveller / rename-file-name.py
Last active October 8, 2020 20:16
Example Script: Rename File Name with Python
# Renames all files in a directory from OLDID_FileName.xtf to NEWID_FileName.xtf. Moves the files as well if
# source and target directory are not the same. A CSV file with 2 columns (OLDID,NEWID) is required.
import re
import os
import csv
# import shutil
source_directory = r"/Users/thozub/Desktop/files"
target_directory = r"/Users/thozub/Desktop/files" # directory must exist
@moosetraveller
moosetraveller / settings.json
Last active December 6, 2020 18:46
Windows Terminal Configuration File with Anaconda Prompt
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"copyOnSelect": false,
"copyFormatting": true,
"profiles": {
"defaults": {
@moosetraveller
moosetraveller / gis-dev-env.md
Last active June 15, 2021 02:19
GIS Development Environment

Version 2021-06-14

GIS Development Environment

This document describes a development environment for a GIS developer who also works as a cartographer. Please note that software/configuration may or may not be useful for you as it depends on the technology stack used. Also, consider that software products evolve quickly and better software enters our lives. ;)

This document is a snapshot (at the time written) and subject of personal opinion.

Technology Stack / Tasks

  • JavaScript and other web development
  • C#, ASP.NET, Python
@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

@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 / 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 / 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 / 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 "name@domain.com"
  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 / 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 / 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