Skip to content

Instantly share code, notes, and snippets.

View JamesMcMahon's full-sized avatar

James F McMahon JamesMcMahon

View GitHub Profile
@JamesMcMahon
JamesMcMahon / headtail.rb
Last active September 2, 2016 20:02
Head and Tail in Ruby splats
# split head and tail
(head, *tail) = [1, 2, 3]
# head is 1
# tail is [2, 3]
@JamesMcMahon
JamesMcMahon / sieve_of_eratosthenes.rb
Last active September 24, 2016 20:44
Sieve of Eratosthenes in Ruby
#!/usr/bin/env ruby
def gen_primes(n)
sieve = Array.new(n) { |i| i > 1 }
(0...Math.sqrt(n)).each do |i|
next unless sieve[i]
(i * i...n).step(i) { |j| sieve[j] = false }
end
@JamesMcMahon
JamesMcMahon / tracker.highlighter.user.js
Created November 6, 2016 00:20
Tracker Blocked Highlighter
// ==UserScript==
// @name Tracker Blocked Highlighter
// @namespace http://tampermonkey.net/
// @version 0.1
// @author jmcmahon
// @match https://www.pivotaltracker.com/*
// @grant none
// ==/UserScript==
(function() {
@JamesMcMahon
JamesMcMahon / brew-deps.sh
Created September 10, 2017 22:19
Lists brew dependencies
#!/bin/zsh
brew list | while read cask; do echo -n $fg[blue] $cask $fg[white]; brew deps $cask | awk '{printf(" %s ", $0)}'; echo ""; done
@JamesMcMahon
JamesMcMahon / comparedirs.py
Created March 31, 2018 23:10
Script to compare just directory names
#!/usr/bin/env python
import os
import sys
def remove_prefix(text, prefix):
if text.startswith(prefix):
return text[len(prefix):]
return text
@JamesMcMahon
JamesMcMahon / exo-repl-notes.md
Last active October 23, 2022 00:31
Exo Fennel Encounter REPL in Spacemacs - notes

Some notes on getting this to work via Spacemacs,

You need to add the following

(defun dotspacemacs/user-config ()
  (autoload 'fennel-mode "~/.emacs.d/private/local/fennel-mode/fennel-mode" nil t)
  (add-to-list 'auto-mode-alist '("\\.fnl\\'" . fennel-mode))
  )
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'tracker_api'
require 'date'
require 'descriptive_statistics'
def calc_running_velocity(last_3_iterations)
if last_3_iterations.size != 3
return nil
@JamesMcMahon
JamesMcMahon / toolbox-fix.sh
Last active July 20, 2019 20:00
Fix issue with Jetbrains Toolbox apps
xattr -cr Applications/JetBrains\ Toolbox/
@JamesMcMahon
JamesMcMahon / comparedirs.py
Created February 3, 2020 01:01
Compare directories script I created for my NAS
#!/usr/bin/env python
import os
import sys
def remove_prefix(text, prefix):
if text.startswith(prefix):
return text[len(prefix):]
return text
@JamesMcMahon
JamesMcMahon / rsync-backup.sh
Last active November 1, 2021 15:27
Remote backup Rsync
#!/usr/bin/env bash
set -e
log_file=$1
local_path=$2
remote_path=$3
time rsync --archive --verbose --new-compress --human-readable --protect-args --progress --exclude=.DS_Store --log-file=rsync_${log_file}.log ${local_path} ${remote_path}
time rsync --checksum --archive --verbose --new-compress --human-readable --protect-args --progress --exclude=.DS_Store --log-file=rsync_${log_file}_checksum-verify.log ${local_path} ${remote_path}