Skip to content

Instantly share code, notes, and snippets.

View alexmacniven's full-sized avatar
🍪

Alex Macniven alexmacniven

🍪
View GitHub Profile

Zsh and Oh-My-Zsh on Ubuntu WSL

Bash on WSL is great.

But if you want a little extra from your terminal you can install zsh and oh-my-zsh pretty easily.

Prequisites

  • Ubuntu WSL

Install Zsh

@alexmacniven
alexmacniven / passenger_occupancy.py
Created May 22, 2019 13:04
Find all passenger combinations for a hotel room with the restrictive criteria; minimum occupancy, maximum occupancy, minimum adults, maximum adults, minimum childs, maximum childs
# Constant declarations.
min_occ = 1
max_occ = 4
min_adl = 1
max_adl = 4
min_chl = 0
max_chl = 2
results = []
adult = min_adl
@alexmacniven
alexmacniven / gather_hostkeys.md
Last active May 1, 2019 09:07
How to gather ssh host keys

Requirments

  • Bash (Git Bash on windows)
  • Host address

Usage

Use ssh-keyscan to gather the host key.

$ ssh-keyscan [host]
@alexmacniven
alexmacniven / unittest_mock_patch_example.py
Created April 17, 2019 14:43
This gist describes using mock.patch from the python module unittest
import unittest
from datetime import datetime, timedelta
from unittest.mock import patch
# Mocking describes replacing objects or functions
# in a piece of logic with another. A prime example
# is when we want to test a function returning a result
# based on datetime.now(). As it is always changing, it's
@alexmacniven
alexmacniven / remove_files.md
Created March 4, 2019 09:18
Removing files under a certain size with Powershell

We can use a simple command to remove files under x size

> Get-ChildItem . -Filter *.xml -recurse -file | ? {$_.length -lt 105} | % {Remove-Item $_.fullname}

Let's break this down at the pipes and look at each section;

Get-ChildItem . -Filter *.xml -recurse -file
@alexmacniven
alexmacniven / CSharpRounding.cs
Created February 26, 2019 20:50
Examples of how to round in CSharp
class Rounding
{
static void Main(String[] args)
{
// Round up = 1
Math.Ceiling(0.5);
// Round down = 0
Math.Floor(0.5);
@alexmacniven
alexmacniven / DateConvert.pas
Created February 26, 2019 11:29
Demonstrates converting non-standard dates in Delphi
var
FormatSettings: TFormatSettings;
DateString: String;
DateTime: TDateTime;
begin
FormatSettings := TFormatSettings.Create;
with FormatSettings do
begin
DateSeparator := '-';
@alexmacniven
alexmacniven / iterparse_example.py
Created February 21, 2019 13:29
Use xml.etree.ElementTree.iterparse for *very* large xml data
"""
iterparse(source, events=None, parser=None)
Incrementally parse XML document into ElementTree.
This class also reports what's going on to the user based on the
*events* it is initialized with. The supported events are the strings
"start", "end", "start-ns" and "end-ns" (the "ns" events are used to get
detailed namespace information). If *events* is omitted, only
"end" events are reported.
@alexmacniven
alexmacniven / guardian_reader.py
Last active February 21, 2019 08:56
A (quickly) mocked up script to parse a Guardian RSS feed
# guardian_reader.py
# Excellent package for doing HTTP Post and Gets etc.
import requests
# Out of the box XML parsing.
from xml.etree import ElementTree
URL = 'https://www.theguardian.com/society/deafness/rss'
@alexmacniven
alexmacniven / version_is_new.py
Last active August 2, 2018 14:13
Compare two version numbers in the format 'major.minor.patch'
def version_is_new(a, b):
"""Returns True if version `a` is newer than `b`
Args:
a: String version number to compare
b: String version number to compare against
Returns:
True if `a` is newer than `b`
"""