Skip to content

Instantly share code, notes, and snippets.

View thepacketgeek's full-sized avatar

Mat Wood thepacketgeek

View GitHub Profile
#!/bin/bash
# This script will migrate schema and data from a SQLite3 database to PostgreSQL.
# Schema translation based on http://stackoverflow.com/a/4581921/1303625.
# Some column types are not handled (e.g blobs).
#
# See also:
# - http://stackoverflow.com/questions/4581727/convert-sqlite-sql-dump-file-to-postgresql
# - https://gist.github.com/bittner/7368128
from extensions import db
from celery import Celery
from flask import Flask
from config import config, SELECTED_CONFIG
def create_celery_app(app=None):
app = app or create_app()
celery = Celery(__name__, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
TaskBase = celery.Task
#!/usr/bin/env python
"""
Very simple HTTP server in python.
Usage::
./dummy-web-server.py [<port>]
Send a GET request::
curl http://localhost
import paramiko
import re
from time import sleep
# Router connection details (could be read in from file or argparse)
peer = '172.16.2.10'
username = 'admin'
password = 'admin'
def collect_output(shell, command):
#!/usr/bin/env python
## Tiny Syslog Server in Python.
##
## This is a tiny syslog server that is able to receive UDP based syslog
## entries on a specified port and save them to a file.
## That's it... it does nothing else...
## There are a few configuration parameters.
LOG_FILE = 'youlogfile.log'
@thepacketgeek
thepacketgeek / calc_mask_length.py
Created July 24, 2015 15:19
Convert Subnet Mask to CIDR length
def calc_mask_length(mask):
""" Convert subnet mask (255.255.255.0) to CIDR mask length (/24) """
return sum([bin(int(x)).count('1') for x in mask.split('.')])
print calc_mask_length('255.255.255.0')
# 24
Update {
withdrawn_routes: [],
attributes: [
ORIGIN(
IGP
),
AS_PATH(
ASPath {
segments: []
}
extern crate pcarp;
use std::fs::File;
use std::io::{Cursor, Read};
use std::net::IpAddr;
use std::path::Path;
use std::result::Result;
use bgp_rs::{Header, Message, Reader};
use byteorder::{NetworkEndian, ReadBytesExt};
@thepacketgeek
thepacketgeek / rust_getting_started.md
Last active December 3, 2025 12:22
Diving into Rust

Diving into Rust

If you're wanting to get involved with Rust projects and see what the magic is all about, here are some great starting points!

Read

  • A Gentle Introduction
    • A little more focused on the main concepts, only takes an hour or so
  • The Book
    • This is the first and foremost (albiet most time consuming) way to get familiar
  • Py2Rs
@thepacketgeek
thepacketgeek / gist:24dc4665cc4045d730ca032ed4b8aaa1
Created November 24, 2020 14:28
Influx Query for showing delta of cumulative iface counts
SELECT
non_negative_derivative(mean("ifHCInOctets"), 1s) * 8 AS "Rx",
non_negative_derivative(mean("ifHCOutOctets"), 1s) * 8 AS "Tx"
FROM "interface"
WHERE ("ifAlias" = 'Some if here')
AND $timeFilter GROUP BY time($__interval) fill(null)