Skip to content

Instantly share code, notes, and snippets.

View jamesridgway's full-sized avatar

James Ridgway jamesridgway

View GitHub Profile
@jamesridgway
jamesridgway / kms_crypto.rb
Created May 22, 2017 21:20
This is an example of how to use AWS KMS to encrypt and decrypt data.
=begin
----------
KMS Encyrption/Decryption Example
This is an example of how to use KMS to encrypt and decrypt data. This script will take the plaintext or ciphertext
via stdin (base 64 encoded).
Encrypt example:
@jamesridgway
jamesridgway / index-status.js
Created May 25, 2017 07:00
Mongo shell script for displaying status of in-progress index builds
var currentOps = db.currentOp();
print("Index Status:");
if(!currentOps.inprog || currentOps.inprog.length < 1) {
print("No operations in progress");
} else {
for(o in currentOps.inprog) {
var op = currentOps.inprog[o];
if(op.msg && op.msg.match(/Index Build/)) {
print(op.opid+' - '+op.msg);
@jamesridgway
jamesridgway / github-languages.rb
Created November 11, 2017 21:22
List language and byte count statistics for all GitHub repositories
require 'octokit'
client = Octokit::Client.new(:access_token => ENV['GITHUB_ACCESS_TOKEN'])
repos = client.repos({}, query: {type: 'owner', sort: 'asc'}).select { |repo| !repo.fork }
language_stats = {}
repos.each do |repo|
repo_id = "#{repo.owner.login}/#{repo.name}"
repo_languages = client.languages(repo_id).to_h
language_stats.merge!(repo_languages){ |k, a_value, b_value| a_value + b_value }
@jamesridgway
jamesridgway / date.js
Last active November 25, 2017 21:35
Javascript date functions
Date.prototype.asStartOfWeek = function(start) {
start = start || 0;
var today = new Date(this.setHours(0, 0, 0, 0));
var day = today.getDay() - start;
var date = today.getDate() - day + (day == 0 ? -6 : 1);
return new Date(today.setDate(date));
}
Date.prototype.asEndOfWeek = function(start) {
start = start || 0;

Keybase proof

I hereby claim:

  • I am jamesridgway on github.
  • I am jamesridgway (https://keybase.io/jamesridgway) on keybase.
  • I have a public key whose fingerprint is AD33 D275 C4EC C3EE 2600 B1F4 5B11 C8A3 F3BC C4EB

To claim this, I am signing this object:

@jamesridgway
jamesridgway / gtk.css
Created December 31, 2017 11:58
Reduce title bar size for applications in Gnome by creating ~/.config/gtk-3.0/gtk.css with the following contents
# Gnome 3 - based on https://blog.samalik.com/make-your-gnome-title-bars-smaller/
.header-bar.default-decoration {
padding-top: 3px;
padding-bottom: 3px;
font-size: 0.8em;
}
.header-bar.default-decoration .button.titlebutton {
padding: 0px;
}
import os
import re
import urllib
from argparse import ArgumentParser
from time import sleep
from selenium import webdriver
from selenium.webdriver import ActionChains
@jamesridgway
jamesridgway / installed-jenkins-plugins.groovy
Created July 15, 2018 08:54
List installed Jenkins plugins
def instance = Jenkins.getInstance()
def pluginManager = instance.getPluginManager()
def plugins = pluginManager.getPlugins()
def installedPlugins = []
plugins.each {
installedPlugins << it.getShortName()
}
@jamesridgway
jamesridgway / nested_dict.py
Created August 11, 2018 11:09
Use dot notation to recursively lookup data attributes in a dict
"""
NestedDict wrapper
"""
class NestedDict(dict):
def __getitem__(self, key_namespace):
if "." not in key_namespace:
return super(NestedDict, self).__getitem__(key_namespace)
keys = key_namespace.split('.')
val = self
for key in keys:
@jamesridgway
jamesridgway / normal_exposure.sh
Created September 7, 2018 06:03
Use exiftool to find CR2 files with a normal AEB Bracket Value
#!/bin/bash
# Can be used as follows to copy all files with a normal exposure to a 'normal_exposure' folder:
# ./normal_exposure.sh | xargs -I '{}' cp '{}' normal_exposure/
set -e pipefail
for file in *.CR2;
do
exiftool "$file" | grep -P "AEB Bracket Value\s+: 0" | true
if [ "${PIPESTATUS[1]}" -ne 1 ]; then