Skip to content

Instantly share code, notes, and snippets.

Aaron Luna a-luna

Block or report user

Report or block a-luna

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@a-luna
a-luna / datetime_util.py
Last active Sep 4, 2019
Helpful Python datetime functions I've curated over time: timezone conversion, formatting aware/naive objects as strings, custom "timespan" namedtuple that provides more data than timedelta object, and more!
View datetime_util.py
import time
from collections import namedtuple
from datetime import datetime, timedelta, timezone
from dateutil import tz
DT_AWARE = "%m/%d/%y %I:%M:%S %p %Z"
DT_NAIVE = "%m/%d/%y %I:%M:%S %p"
DATE_MONTH_NAME = "%b %d %Y"
DATE_ISO = "%Y-%m-%d"
@a-luna
a-luna / dotenv_parser.py
Last active Jul 29, 2019
Parse the text of a .env file to a dictionary of environment variables using only the Python standard library. IMUBVHCIO*, the list/dict comprehensions perfectly straddle the line between an elegant use of syntax and an infinitely dense mass of code (the dreaded "neutron star effect"). And extra bonus: Type hints!
View dotenv_parser.py
"""Parse .env file to a dictionary of environment variables."""
import errno
import os
from pathlib import Path
from typing import Dict, List
def parse_dotenv_file(filepath: Path) -> Dict[str, str]:
"""Parse .env file to a dictionary of environment variables."""
if not filepath.exists():
@a-luna
a-luna / ConsoleProgressBar.cs
Last active Apr 3, 2018 — forked from DanielSWolf/Program.cs
Progress bar for console applications, added the ability to customize the various components of the progress bar. Added the ability to display or hide the progress bar, percent complete and animation. And just for fun, I created a set of animation sequences which can be used instead of the default "|/-\-" progress indicator.
View ConsoleProgressBar.cs
namespace AaronLuna.Common.Console
{
using System;
using System.Linq;
using System.Text;
using System.Threading;
public class ConsoleProgressBar : IDisposable, IProgress<double>
{
readonly TimeSpan _animationInterval = TimeSpan.FromSeconds(1.0 / 8);
@a-luna
a-luna / NetworkUtilities.cs
Last active Mar 7, 2019
Helpful C# Network/IP functions. Parse IPs from any arbitrary block of text, retrieve private/public IP addresses and check if IP exists in any range defined by an address in CIDR notation.
View NetworkUtilities.cs
namespace NetworkUtilitiesTest
{
using AaronLuna.Common.Network;
using AaronLuna.Common.Extensions;
using System.Threading.Tasks;
class Program
{
// async Main is a C# 7.1 feature, change your project settings to the
// new version if this is flagged as an error
@a-luna
a-luna / TplSocketExample.cs
Last active Jun 27, 2019
C# Extension Methods which wrap Socket APM methods in awaitable TPL wrappers. All methods return Task<Result> or Task<Result<T>> objects, the code for the Result class is given as well.
View TplSocketExample.cs
namespace AaronLuna.TplSockets
{
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using AaronLuna.Common.Result;
public class TplSocketExample
@a-luna
a-luna / build_nginx_from_source.sh
Last active Sep 18, 2019
Shell Script: Build NGINX from Source with Third Party Modules (Cache Purge, GeoIP2), Completely Non-Interactive, No User Input Required
View build_nginx_from_source.sh
#!/bin/bash -e
# build_nginx_from_source.sh
# Author: Aaron Luna
# Website: alunablog.com
#
# This script downloads the source code for the latest version of NGINX
# (libraries required to build various NGINX modules are also downloaded)
# and builds NGINX according to the options specified in the ./configure
# command. Many of the possible configuration options are explained at
# the link below:
You can’t perform that action at this time.