Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Walquist walquis

View GitHub Profile
@walquis
walquis / open_weather.rb
Created Sep 20, 2020
Simple open_weather implementation - used to collect temperature data for Nest stats website until sep 2019 when Lennox system installed
View open_weather.rb
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 / notes-on-large-commit-handling.txt
Last active Mar 30, 2017
Investigate & clean large commits in Github repos
View notes-on-large-commit-handling.txt
git verify-pack -v .git/objects/pack/*.idx | sort -r -k 3 -n | head -10
For active repositories, you can search by id in http(s)://[your-hostname]/stafftools . For deleted ("archived") repositories, you have to use the console. For example:
$ echo 'Archived::Repository.find(1496).name_with_owner' | ghe-console -y
Deleted repositories are automatically purged from disk after three months, but you can delete an archived repository immediately in the console by running:
$ echo 'Archived::Repository.find(1496).purge' | ghe-console -y
@walquis
walquis / git_commands_notes.txt
Last active Mar 30, 2017
Git commands I use a lot, and when I use them; some I should use more; Etc.
View git_commands_notes.txt
Repo status
$ git status
$ git diff
$ git diff --staged
$ git
$ git rev-parse HEAD
My bash aliases (kept in .bashrc)
alias ga='git add'
@walquis
walquis / cronic
Created May 31, 2016
A variation of Chuck Houpt's 2007 cronic script
View cronic
#!/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
Linux one-liner: Report top X instances of pattern Y in a file.
View report-top-X-instances-of-pattern-Y-in-logfile.sh
# 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 / print_commits_with_git_tags.rb
Last active Feb 22, 2016
Print shell commands to delete git tags older than a year
View print_commits_with_git_tags.rb
# Before deleting all those tags, you may want to record which commits they tagged...just in case...
# This is slightly tricky, because annotated tags have at least *two* SHAS: one that constitutes tag
# itself, and one that is the SHA being tagged. The rev-list command gets at the latter.
# See EXAMPLES section of https://git-scm.com/docs/git-for-each-ref for more on making format a full-fledged script.
$ fmt='sha=`git rev-list -n 1 %(tag)`; echo %(tag)#$sha#%(taggerdate:raw)'
$ git for-each-ref --shell --format="$fmt" refs/tags | while read entry; do eval "$entry"; done > tags-with-commits.txt
@walquis
walquis / unix-date-commands.txt
Last active Sep 19, 2020
Converting between seconds-since-epoch and human-readable formats with the Unix date command
View unix-date-commands.txt
$ date +%s
1447428499
$ date -d @1447428499 # Or on Mac, date -r 1447428499
Fri Nov 13 09:28:19 CST 2015
$ date
Fri Nov 13 09:28:35 CST 2015
$ date -d "Thu Nov 12 17:30:00 CST 2015" # On Mac, something else
Thu Nov 12 17:30:00 CST 2015
$ date -d "Thu Nov 12 17:30:00 CST 2015" +%s
1447371000
@walquis
walquis / Gemfile
Last active Oct 27, 2015
Ruby examples of sorting, including overriding spaceship operator
View Gemfile
source 'http://rubygems.org'
gem 'rspec'
@walquis
walquis / git copy-merge
Created Jan 30, 2014
A procedure for turning a non-master branch into master, without forcing a push and possibly hurting collaborators
View git copy-merge
$ git clone git@git:org/repo repo-master
$ git clone git@git:org/repo repo-newerbranch
$ cd repo-newerbranch
$ git checkout newerbranch
$ cd ../repo-master
$ git checkout newerbranch # To pull down newerbranch branch for merging from, otherwise you get a “fatal: newerbranch – not something we can merge” error
$ git checkout master
$ git merge -s recursive --strategy-option theirs newerbranch
$ cd ..
$ diff -rq repo-newerbranch/ repo-master/ --exclude=.git
View query-teamcity-vcs-roots-via-rest.rb
require 'json'
host = 'https://builds.company.com'
# /tmp/tmp/txt was created like this:
# $ curl --netrc --header 'Accept: application/json' #{host}/httpAuth/app/rest/vcs-roots`
j = JSON.parse File.read('/tmp/tmp.txt')
details = []
not_monitored = 0
j["vcs-root"].each do |v|
You can’t perform that action at this time.