Skip to content

Instantly share code, notes, and snippets.

View walquis's full-sized avatar

Chris Walquist walquis

View GitHub Profile
@walquis
walquis / bumpme
Last active January 25, 2023 20:55
Wed Jan 25 20:55:43 UTC 2023
https://stackoverflow.com/questions/24698188/flatten-a-json-document-using-jq
I want to transform this...
{
"Research Data Management": [
{
"id": 2597547,
"title": "Data Engineer, Research Data Management"
},
{
@walquis
walquis / repos_for_org.rb
Last active December 21, 2021 21:54
Retrieve list of repos for org - demonstrates basic-auth and request pagination
#
# $ token=my-personal-access-token bundle exec ruby repos_for_org.rb my-username some-org
#
require 'httparty' # Probly want a Gemfile for these
require 'json'
token = ENV['token']
repo_fullnames = []
@walquis
walquis / open_weather.rb
Created September 20, 2020 00:22
Simple open_weather implementation - used to collect temperature data for Nest stats website until sep 2019 when Lennox system installed
require 'httparty'
def outside_temp_f zip
# Only read the temp every ten minutes, or if no current-temperature-file established.
#
curr_temperature_fname = 'current-temperature-file'
if File.exists? curr_temperature_fname
age_in_seconds = DateTime.now.to_time.to_i - File.stat(curr_temperature_fname).mtime.to_time.to_i
# Is file less than ten minutes old?
@walquis
walquis / cronic
Created May 31, 2016 14:59
A variation of Chuck Houpt's 2007 cronic script
#!/bin/bash
# Cronic v2 - cron job report wrapper
# Copyright 2007 Chuck Houpt
CRONIC_LOG=${CRONIC_LOG:-/sitelogs/cronic/cronic.$LOGNAME.log}
CRONIC_LOCK=${CRONIC_LOCK:-/tmp/cronic.$LOGNAME.lock}
trim() { echo $1; }
@walquis
walquis / report-top-X-instances-of-pattern-Y-in-logfile.sh
Last active May 10, 2016 15:10
Linux one-liner: Report top X instances of pattern Y in a file.
# For instance, which users had the most occurrences of their name in logfile auth.log?
$ date; grep --only-matching "member=[^ ]*" auth.log | sort | uniq --count | sort -rn| head -8
# grep -o, --only-matching -- Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.
# uniq -c, --count -- Prefix lines by number of occurrences
# sort -rn, --reverse ... -n, --numeric-sort
Mon May 9 22:09:34 UTC 2016
223163 member=some-user
@walquis
walquis / Gemfile
Last active December 4, 2021 20:53
Ruby examples of sorting, including overriding spaceship operator
source 'http://rubygems.org'
gem 'rspec'
@walquis
walquis / ldapsearch.sh
Last active May 4, 2020 20:09
Retrieve a photo from Active Directory with ldapsearch (Linux).
SERVER="dc1.us.yourcompany.com"
DN="CN=aUserLogin,OU=SomeOrgUnit,OU=AnotherOrgUnit,DC=dc1,DC=us,DC=yourcompany,DC=com"
PASSWORD="aUserLoginsPassword"
OU="ou=AnotherOrgUnit,dc=us,dc=yourcompany,dc=com"
ldapsearch -h "$SERVER" -p 389 \
-x -D "$DN" -w "$PASSWORD" \
-t -s sub -b "$OU" "(&(objectClass=user)(sAMAccountName=anotherUserLogin))" "thumbnailPhoto"