Skip to content

Instantly share code, notes, and snippets.

View flyte's full-sized avatar
😎
Open for project work

Ellis Percival flyte

😎
Open for project work
  • London
View GitHub Profile
@flyte
flyte / qr.py
Created December 18, 2013 12:46
Generate/validate a QR code value.
"""
Easy version...
def qr_hash(prefix, data_to_hash):
qr = ""
for char in prefix:
qr += hex(ord(char))[2:]
qr += md5(data_to_hash).hexdigest()
return qr
@flyte
flyte / ord_hex_string.js
Created January 9, 2014 13:46
Return a string of the hex ASCII ordinal values of a string.
function toOrdinalHexString(str) {
ret = "";
for (i=0; i < str.length; i++) {
c = str.charAt(i);
ret = ret.concat(c.charCodeAt(0).toString(16));
}
return ret;
}
@flyte
flyte / qr.php
Created January 10, 2014 12:37
Generate QR code contents in PHP.
<?php
function toQRCode($prefix, $str) {
$prefixOrd = "";
for ($i = 0; $i < strlen($prefix); $i++) {
$c = substr($prefix, $i, 1);
$prefixOrd.= dechex(ord($c));
}
return $prefixOrd.md5($str);
}
@flyte
flyte / star_url.py
Created January 24, 2014 15:53
Rebuild a URL with stars covering the password.
def star_url(url):
"""
Rebuild a URL with stars covering the password.
"""
url = urlparse(url)
ret = ""
# Scheme (http/https)
if url.scheme:
ret += "%s://" % url.scheme
# Username/password
import serial
import socket
import argparse
import sys
from time import sleep
NEWLINE = "\r\n"
def connect_tcp(sock, target):
@flyte
flyte / pluralise.py
Last active June 12, 2017 19:24
Pluralise word (add 's') when i != 1
In [1]: s = lambda i: "s"[i==1:]
In [2]: for i in range(0, 5):
...: print "I have %d apple%s" % (i, s(i))
...:
I have 0 apples
I have 1 apple
I have 2 apples
I have 3 apples
I have 4 apples
@flyte
flyte / cb_versions.py
Created April 3, 2014 16:19
Loop through cookbook directories and find out which versions you've got.
import os
from distutils.version import LooseVersion as Version
if __name__ == "__main__":
cb_versions = {}
for cb_dir in os.listdir("."):
if cb_dir.startswith("cookbooks"):
print "Scanning %s" % cb_dir
for cb in os.listdir(cb_dir):
if not os.path.isdir(os.path.join(cb_dir, cb)):
@flyte
flyte / repocheck.py
Created April 17, 2014 19:51
Check all git repositories in a directory to see if they're clean or dirty.. Tested on: GitPython==0.1.7 argparse==1.2.1 prettytable==0.7.2
import argparse
import os
import git
from prettytable import PrettyTable
if __name__ == "__main__":
p = argparse.ArgumentParser()
p.add_argument("base_dir")
args = p.parse_args()
@flyte
flyte / publish_input.py
Created August 14, 2014 14:16
Publish the changes of an input from a Raspberry Pi with PiFace digital IO board over ZeroMQ
import zmq
import pifacedigitalio
import argparse
from time import sleep
if __name__ == "__main__":
p = argparse.ArgumentParser()
p.add_argument("input", type=int)
p.add_argument("prefix", type=str)
p.add_argument("port", type=int)
@flyte
flyte / vagrant_status.py
Created November 11, 2014 12:38
Find all Vagrantfiles and check their status
from subprocess import check_output
import argparse
import os
import re
BASE_DIR = os.path.abspath(".")
STATUS_LINE_RE = r"^(\w+?)\s+?(\w.+?)\s\((.+?)\)$"
if __name__ == "__main__":
p = argparse.ArgumentParser()