Skip to content

Instantly share code, notes, and snippets.

View uuklanger's full-sized avatar

uuklanger

View GitHub Profile
@uuklanger
uuklanger / tilda.inputrc
Created June 29, 2021 13:18
Turn off bash bell sound in Terminal
# ~/.inputrc or /etc/inputrc
set bell-style none
@uuklanger
uuklanger / helpful_shell_commands.md
Last active August 18, 2021 02:46
Helpful Shell Commands

Helpful Command Cheet Sheet

These are commands that I forget regularly and need to look up.

Format JSON output as pretty

cat boring.json | python3 -m json.tool > pretty.json

Overview

If you want to reformat JSON output from a single line to a nicely formatted document, you can use the following trick.

cat boring.json | python3 -m json.tool > pretty.json
@uuklanger
uuklanger / remove_old_alternative.sh
Last active November 11, 2020 23:08
remove_old_alternative.sh
# ---------------------------------------------------------------
# If you are setting up a clean (never used) system, you can run this full batch
# Otherwise, I suggest running this line by line (copy/paste).
#
# Show if java, javac, or jar are already setup. Run these commands before running the rest
#
JDK_VERSION='jdk1.8.0_261'
echo "==============================================================="
echo " Processing Aternatives for "${JDK_VERSION}
@uuklanger
uuklanger / setup_alternatives.sh
Last active October 28, 2020 00:48
setup_alternatives.sh
# ---------------------------------------------------------------
# If you are setting up a clean (never used) system, you can run this full batch
# Otherwise, I suggest running this line by line (copy/paste).
#
# Show if java, javac, or jar are already setup. Run these commands before running the rest
#
JDK_VERSION='jdk1.8.0_271'
echo "==============================================================="
echo "Processing Aternatives for "${JDK_VERSION}
@uuklanger
uuklanger / RPI_framebuffer_resolution.md
Created July 31, 2020 18:11
HOWTO Set the resolution of the boot console using Ubuntu 20.04 on a Raspberry Pi 3B

Overview

If you have some Raspberry PI's running Ubuntu Server 20.04 connected to a flatpanel monitor, here are the steps to configure the screen resolution. In my monitor, the default Ubuntu is selecting is terrible looking and impossible to read. It is even worse at odd angles.

Check out this raspberry pi site for video resolutions. Based on my setup...

  • I have Ubuntu 20.04 running on a RPI3B+
  • I would like 1920x1080 for a 60Hz display. I have an LG 24" monitor
  • Reading my monitors documentation, I know this is the max safe resolution
  • My monitor is connected by an HDMI cable and is digital
@uuklanger
uuklanger / check_if_file_is_image.py
Created February 10, 2020 17:41
HOWTO - Check to see if File is Image
#!/usr/bin/env python3
#
# http://www.blog.pythonlibrary.org/2020/02/09/how-to-check-if-a-file-is-a-valid-image-with-python/
#
import imghdr # for imghdr
from PIL import Image # for Image.open
path = 'python.jpg'
imghdr.what(path)
# returns 'jpeg'
@uuklanger
uuklanger / python_bubble_sort.py
Created February 10, 2020 17:34
HOWTO - Bubble Sort in Python
#!/usr/bin/env python3
#
# https://stackabuse.com/bubble-sort-in-python/
#
def bubble_sort(our_list):
# We go through the list as many times as there are elements
for i in range(len(our_list)):
# We want the last pair of adjacent elements to be (n-2, n-1)
for j in range(len(our_list) - 1):
if our_list[j] > our_list[j+1]:
@uuklanger
uuklanger / howto_control_json_formatting_in_ihttpactionresult.md
Last active December 3, 2019 03:01
HOWTO - Control formatting of JSON in an IHttpActionResult REST API Response

Overview

In some cases, you may have an object the you are returning in an System.Web.Http.IHttpActionResult response where properties in the object you are returning have null values. To minimize the size of the data structure you are returning, a formatter can be specified which will let you supress null values.

Formatter

Add using System.Net.Http.Formatting to the top of your code file.

protected JsonMediaTypeFormatter getJsonFormatter()
@uuklanger
uuklanger / howto_connect_to_pgsql_via_ssh.md
Last active June 11, 2020 16:05
HOWTO - Connect to a PostgreSQL DB though an SSH Tunnel

Overview

In cases where you want a layer around your PostgreSQL DB to minimize access, versus opening another port on a server for direct access (which you can restrict to an IP address or range), there is the option of accessing your DB through an SSH tunnel.

Considerations

  • This can be slower
  • You will want authorized_hosts setup to allow the tunnel to open automatically
  • Some tools like Navicat, will help do this for you if you set your server to "local" in the General tab and use the server dns name in the SSH tab. The following is only needed if you are using the psql command from a client system's terminal.