Skip to content

Instantly share code, notes, and snippets.

View joedborg's full-sized avatar
🏠
Working from home

Joe Borg joedborg

🏠
Working from home
View GitHub Profile
@joedborg
joedborg / launch_vm.sh
Last active April 18, 2024 07:54
LXD Ubuntu VM launch and disk resize
#!/bin/env bash
set -e
readonly VM="banana"
readonly CPU="8"
readonly MEM="8GB"
readonly DSK="120GB"
lxc init images:ubuntu/focal ${VM} -p default -p vm --vm
@joedborg
joedborg / gist:d9aa478c72c9f374bdf5217854419da2
Last active March 24, 2020 14:52
Getting AutoRun registry key
import winreg
cmd = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Command Processor', access=winreg.KEY_WRITE)
winreg.SetValueEx(cmd, 'AutoRun', 0, winreg.REG_SZ, 'myscript.bat')
@joedborg
joedborg / crictl_install.py
Created April 24, 2019 15:01
crictl Charm Installation
@when('config.changed.crictl-version')
def crictl_version_changed():
"""
crictl version has changed.
:return: None
"""
remove_state('crictl.installed')
@joedborg
joedborg / multipass-charm.yaml
Last active April 15, 2019 15:48
cloud-init configuration for Charm development
# cloud-config
## launch multipass instance with `--cloud-init [this file]`
## then mount your charm workspace with `multipass mount "." "[instance name]:/project"`
write_files:
- path: /etc/profile.d/charm-dev.sh
permissions: "0644"
content: |
export CHARM_BUILD_DIR=/builds
export CHARM_LAYERS_DIR=/layers
import subprocess
from typing import List
def get_packages() -> List[str]:
out: str = subprocess.check_output(['pip', 'freeze']).decode()
packages: List[str] = out.split('\n')
return [x.split('==')[0] for x in packages]
git:
source: https://github.com/git/git
source-type: git
source-depth: 1
plugin: autotools
configflags:
- --with-curl
- --with-expat
build-packages:
- gettext
@joedborg
joedborg / is_seq_in_list.py
Created October 28, 2016 14:46
Look for a sequuence within a list
def is_seq_in_list(sequence, match):
for i, j in enumerate(sequence):
if sequence[i:len(match) + i] == match:
return True
return False
if __name__ == '__main__':
match = [1, 3, 4]
sequence = [2, 3, 6, 3, 8, 1, 3, 4, 8, 2]
is_seq_in_list(sequence, match)
@joedborg
joedborg / gist:c8613a671cd312aee505
Last active August 29, 2015 14:23
How old am I?
import math
from datetime import datetime
def how_old_am_i(year, month, day):
"""
Get how old you are in years.
:param year: Integer year born
:param month: Integer month born
:param day: Integer day born
:retuns: Integer years old
@joedborg
joedborg / post_to_sms.go
Created October 10, 2014 18:47
Example of a POST handle in Go that uses Twilio to SMS the form
package main
import (
"fmt"
twilio "github.com/carlosdp/twiliogo"
"net/http"
"strings"
)
var form = []string{
@joedborg
joedborg / post.go
Created October 10, 2014 17:48
Example of a POST handle in Go
package main
import (
"fmt"
"net/http"
)
var form = []string{
"Make",
"Model",