Skip to content

Instantly share code, notes, and snippets.

@gesquive
gesquive / self-update-script.py
Last active February 18, 2024 20:36
Stick this in a python script to self update the script from an online source
def update(dl_url, force_update=False):
"""
Attempts to download the update url in order to find if an update is needed.
If an update is needed, the current script is backed up and the update is
saved in its place.
"""
import urllib
import re
from subprocess import call
def compare_versions(vA, vB):
package main
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func main() {
@gesquive
gesquive / get_keypress.py
Last active October 29, 2022 09:02
Get keypress for different platforms
#!/usr/bin/env python3
# get_keypress.py
import sys
import os
def main():
try:
print("press ctrl+c to exit")
@gesquive
gesquive / print-program-options.cc
Last active June 12, 2022 11:55
Methods to print out boost::program_options objects
#include <string.h>
#include <iostream>
#include "boost/program_options.hpp"
#include "boost/filesystem.hpp"
#include "boost/any.hpp"
namespace po = boost::program_options;
inline void PrintUsage(const boost::program_options::options_description desc) {
std::cout << "Usage: " << app_name << " [options]" << std::endl;
@gesquive
gesquive / zero.zsh-theme
Created June 4, 2022 22:13
zero zsh theme
# zero.zsh-theme
# forked from af-magic
# https://github.com/andyfleming/oh-my-zsh/blob/master/themes/af-magic.zsh-theme
# color vars
eval sys_color='$FG[240]'
eval dirty_color='$FG[214]'
eval virt_color='$FG[023]'
eval git_color='$FG[064]'
eval prompt_color='$FG[032]'
@gesquive
gesquive / vscode_golang_launch.json
Last active March 27, 2022 23:15
vs code golang debug launch examples file
{
"version": "0.2.0",
"configurations": [
{
"name": "Golang: App",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}",
"args": [
@gesquive
gesquive / vscode_python_launch.json
Last active March 27, 2022 18:23
vs code python debug launch examples file
"configurations": [
{
"name": "Python: Server",
"type": "python",
"request": "launch",
"envFile": "${workspaceFolder}/.env",
"program": "${workspaceFolder}/server.py"
},
{
"name": "Python: run file",
@gesquive
gesquive / python-logger-snippet.py
Last active March 26, 2022 23:30
Code snippet to setup logger in python
import logging
import logging.handlers
LOG_FILE = 'path/to/logfile'
LOG_SIZE = 1024*1024*200
LOG_COUNT = 9
log_file = LOG_FILE
dir_path = os.path.dirname(log_file)
if os.access(dir_path, os.W_OK):
@gesquive
gesquive / python-less-pager.py
Last active January 17, 2021 19:53
Use less to page output
import subprocess
import sys
import os
def output_to_pager(text):
try:
# args stolen fron git source, see `man less`
pager = subprocess.Popen(['less', '-F', '-R', '-S', '-X', '-K'],
stdin=subprocess.PIPE,
stdout=sys.stdout)
@gesquive
gesquive / cmd.go
Created April 27, 2017 21:48
Run an external command with golang
// run a command using the shell; no need to split args
// from https://stackoverflow.com/questions/6182369/exec-a-shell-command-in-go
func runcmd(cmd string, shell bool) []byte {
if shell {
out, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
log.Fatal(err)
panic("some error found")
}
return out