Skip to content

Instantly share code, notes, and snippets.

@brianpursley
brianpursley / quickperm.py
Last active December 18, 2022 07:38
This is a Python implementation of the QuickPerm algorithm described by Phillip Paul Fuchs at http://www.quickperm.org that generates all permutations of a list without using recursion
#!/usr/bin/env python
#
# This is a Python implementation of the QuickPerm algorithm described by Phillip Paul Fuchs at http://www.quickperm.org
# that generates all permutations of a list without using recursion.
#
a = ['a', 'b', 'c', 'd']
N = len(a)
@brianpursley
brianpursley / scrape.py
Last active April 30, 2021 20:57
Python script to extract a price from a product web page
from bs4 import BeautifulSoup
from urllib2 import Request, urlopen
import decimal
def findPrice(url, selector):
userAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36"
req = Request(url, None, {'User-Agent': userAgent})
html = urlopen(req).read()
soup = BeautifulSoup(html, "lxml")
return decimal.Decimal(soup.select(selector)[0].contents[0].strip().strip("$"))
@brianpursley
brianpursley / example-scrape-target.html
Created November 20, 2015 15:35
Example HTML file for scraping
<html>
<head>
<title>Example Web Page</title>
<style>
.container {
display: table;
}
.row {
display: table-row;
}
@brianpursley
brianpursley / iBeacon-Windows10-C#-Program.cs
Created February 2, 2017 13:50
iBeacon Windows 10 Console Application using C#
using System;
using System.Linq;
using Windows.Devices.Bluetooth.Advertisement;
using Windows.Storage.Streams;
namespace BeaconExample
{
class Program
{
private class BeaconData
@brianpursley
brianpursley / Example.pubxml
Created March 9, 2017 15:08
An example Visual Studio pubxml file to zip the output when publishing an ASP.NET web application to file system
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>C:\Publish\SimpleExample</publishUrl>
@brianpursley
brianpursley / lambda.js
Last active March 11, 2017 02:53
AWS Lambda function that publishes to SNS
var AWS = require("aws-sdk");
exports.handler = (event, context, callback) => {
var sns = new AWS.SNS();
sns.publish({
Message: 'YOUR MESSAGE HERE',
Subject: 'YOUR SUBJECT HERE',
TopicArn: 'YOUR SNS TOPIC ARN HERE'
}, function() {
callback(null, {
@brianpursley
brianpursley / backup.sh
Created April 10, 2017 19:54
Script to backup a folder (/share) and capture incremental changes since the last backup in a timestamp-named folder
#!/bin/bash
ts=`date +%Y%m%d_%H%M%S`
rsync -rtm --compare-dest=/mnt/usb1/backups/snapshot --modify-window=2 /share /mnt/usb1/backups/$ts
find /mnt/usb1/backups/$ts -type d -empty -delete
rsync -rt --delete --modify-window=2 /share /mnt/usb1/backups/snapshot
@brianpursley
brianpursley / docker-compose.yml
Created August 30, 2018 02:18
Docker compose config for running Elastic Search and Kibana locally in docker containers
version: '3'
services:
elasticsearch:
container_name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:6.4.0
volumes:
- esdata:/usr/share/elasticsearch/data
ports:
@brianpursley
brianpursley / get-nodeport-url.sh
Last active February 6, 2020 02:06
Script to get address of kubernetes nodeport service when running locally using (using kind for example)
#!/bin/sh
nodeport=$(kubectl get services -o jsonpath="{..nodePort}") && kubectl get node -o jsonpath="{..addresses[0].address}" | xargs -n1 printf -- "http://%s:$nodeport\n"
@brianpursley
brianpursley / install-metrics-server.sh
Last active January 23, 2020 22:48
Download and install metrics-server into a kind kubernetes cluster
wget -O /tmp/metrics-server-master.zip https://github.com/kubernetes-sigs/metrics-server/archive/master.zip
unzip -u /tmp/metrics-server-master.zip -d /tmp
rm /tmp/metrics-server-master.zip
kubectl apply -f /tmp/metrics-server-master/deploy/1.8+/
rm -rf /tmp/metrics-server-master
kubectl patch deploy metrics-server -n kube-system --type json --patch '[{"op":"add","path":"/spec/template/spec/containers/0/args/-","value":"--kubelet-insecure-tls"},{"op":"add","path":"/spec/template/spec/containers/0/args/-","value":"--kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname"}]'