Skip to content

Instantly share code, notes, and snippets.

View uuklanger's full-sized avatar

uuklanger

View GitHub Profile
@uuklanger
uuklanger / zsh_rc_profile.txt
Created October 17, 2019 22:32
Snippets for creating a ZSH Environment
# --------------- .zshrc ---------------
# Set up the prompt
autoload -Uz promptinit
promptinit
#prompt adam1
prompt adam1 blue
#prompt fade blue white green
@uuklanger
uuklanger / dos2unix_tr.md
Last active October 30, 2019 16:15
HOWTO - Convert DOS to UNIX format

Convert DOS file to UNIX Format

If you clone a repo to a windows system and want to run shell scripts like bash or zsh within the Windows Subsystem for Linux you might need to fix the end-of-line characters. This depends on if you preserve end-of-line characters based on what is in the repo or if you have your local repo auto manage that.

Use Translate to fix this

tr -d '\r' < a.txt > b.txt
@uuklanger
uuklanger / howto_run_coverage_unittest_all.md
Last active November 12, 2019 21:11
HOWTO - Run Coverage for All Code with Unittests

Overview

Within most IDEs you can run "coverage" on your code which tells you how much of your unittests cover the code you have written. If you want to run this kind of coverage from the command line (terminal) for a Python project there are just a few simple steps to follow.

This can be tried directly by cloning this project and running the following.

Assumptions

  • Python 3.7+
  • macOS, linux, or even Windows 10 (WSL preferred).
@uuklanger
uuklanger / howto_setup_pylint_with_pycharm.md
Last active September 29, 2024 04:35
HOWTO - Setup pylint with PyCharm and the PyLint Plugin

Overivew

Setting up a linter can help detect odd or non-typical coding practices. The following will describe how to setup PyCharm for basic linting with the PyCharm PyLint plugin.

This assumes you have a venv setup within your current project.

Install Pylint

For pylint for your current project venv the following two commands should be run in your project root. The first will install pylint and the second will create an rc file which you can then adjust for your current project.

@uuklanger
uuklanger / howto_generate_access_constants_case_with_bash.md
Last active November 15, 2019 06:24
HOWTO - Generate C# Accessors - Constants - Case From a Text file using Bash

Overview

In some cases, you need to create a bunch of repeating code based on some data you intended on processing. In the following examples, I had all the field names listed in a powershell script but I just needed to translate it to C#.

I pasted the data in needed onto a linux box into a file called t.txt. This is the general format of the file where this is just a small piece of the 50 or so fields this script was displaying.

Input File

~/tmp % head t.txt
@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.
@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 / 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 / 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 / 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