Skip to content

Instantly share code, notes, and snippets.

@Xiol
Xiol / bacula_b64decode.py
Created May 28, 2014 08:42
Bacula Base64 decode implementation in Python
# This is a Python implementation of the Perl code from the following link
# http://bacula.10910.n7.nabble.com/The-File-LStat-field-td3960.html
# Bacula uses a custom base64 implementation to encode file stats
# This should allow us to decode the values in the lstat field in the Bacula DB
B64_VALS = {
'+': 62, '/': 63, '1': 53, '0': 52, '3': 55, '2': 54, '5': 57,
'4': 56, '7': 59, '6': 58, '9': 61, '8': 60, 'A': 0, 'C': 2,
'B': 1, 'E': 4, 'D': 3, 'G': 6, 'F': 5, 'I': 8, 'H': 7, 'K': 10,
'J': 9, 'M': 12, 'L': 11, 'O': 14, 'N': 13, 'Q': 16, 'P': 15,
@Xiol
Xiol / primary_ip.py
Created October 8, 2015 11:18
Salt grain for discovering primary IP address on a Linux machine.
#!/usr/bin/env python
import subprocess
def linux_get_primary_ip4():
grains = {}
try:
defroute_device = subprocess.check_output("ip route | grep default | grep -Eo 'dev\s+\w+' | awk '{print $2}'", shell=True).strip()
devip = subprocess.check_output("ip a s {0} | grep -E 'inet\s' | cut -d'/' -f1 | awk '{{print $2}}'".format(defroute_device), shell=True).strip()
except subprocess.CalledProcessError as e:
#!/usr/bin/env python3
# Given a load of HTML pages from the BBC Food website, this script will
# scrape the recipes from the HTML and output them in structured JSON format.
import argparse
import sys
import os
import json
import base64
from bs4 import BeautifulSoup
@Xiol
Xiol / git2go-checkout-branch.go
Created March 1, 2017 08:37 — forked from danielfbm/git2go-checkout-branch.go
How to do a git checkout branch using git2go
package main
import (
"errors"
"log"
"github.com/libgit2/git2go"
)
func checkoutBranch(repo *git.Repository, branchName string) error {
checkoutOpts := &git.CheckoutOpts{