Skip to content

Instantly share code, notes, and snippets.

View jamesmartin's full-sized avatar
🤫
Shhh

James Martin jamesmartin

🤫
Shhh
View GitHub Profile
@jamesmartin
jamesmartin / query.graphql
Created July 18, 2018 21:17
Listing all External Identities of a SAML enabled GitHub Organization
query($login: String!) {
organization(login: $login) {
... on Organization {
samlIdentityProvider {
externalIdentities(first: 30) {
edges {
node {
samlIdentity {
nameId
}
@jamesmartin
jamesmartin / bt.swift
Created March 31, 2017 01:53
Swift example of iterating over all known Bluetooth devices on macOS
import IOBluetooth
// See https://developer.apple.com/reference/iobluetooth/iobluetoothdevice
// for API details.
class BluetoothDevices {
func pairedDevices() {
print("Bluetooth devices:")
guard let devices = IOBluetoothDevice.pairedDevices() else {
print("No devices")
return
@jamesmartin
jamesmartin / tesla-api-token.sh
Created January 12, 2021 06:17
Fetches a new OAuth 2.0 token from the Tesla API using the email and password of a Tesla account
#!/bin/sh
# Fetches a new OAuth 2.0 token from the Tesla API using email and password of
# a Tesla account.
CLIENT_ID=81527cff06843c8634fdc09e8ac0abefb46ac849f38fe1e431c2ef2106796384
CLIENT_SECRET=c7257eb71a564034f9419ee651c7d0e5f7aa6bfbd18bafb5c5c033b093bb2fa3
GRANT_TYPE=password
while getopts e:p: option
do
@jamesmartin
jamesmartin / jwtencoder.sh
Created June 1, 2021 22:24
Bash JWT Encoder
#!/usr/bin/env bash
#
# JWT Encoder Bash Script
#
secret='SOME SECRET'
# Static header fields.
header='{
@jamesmartin
jamesmartin / application_controller.rb
Created May 25, 2015 01:47
Testing ApplicationController before_filter methods using RSpec's "anonymous" controller instance
class ApplicationController < ActionControllerBase
helper :do_something
def do_something
@from_do_something = params[:for_do_something]
end
end
@jamesmartin
jamesmartin / gist:a648b6ca27017c7d888b
Last active November 6, 2020 06:10
Timezone Problems with Timecop and Circle CI
# System time zone is set to 'Australia/Sydney'
#
Time.zone = "Europe/Madrid"
=> "Europe/Madrid"
Timecop.freeze(Time.zone.now)
=> 2015-02-06 23:36:46 +1100 # The "frozen" time. +1100 is Australia/Sydney. Oh dear.
Time.zone.now
=> Fri, 06 Feb 2015 13:36:46 CET +01:00 # The time here is for the configured Time.zone; Europe/Madrid +01:00
@jamesmartin
jamesmartin / writing_custom_rubocop_cops.md
Last active July 6, 2020 02:01
Notes on writing custom RuboCop Cops

To match on string interpolation:

module MyCops
  class MyGreatCop < Cop
  include Interpolation # <- required when attempting to match on_interpolation
  
  def on_interpolation(node)
    # Using node.parent gets you the String rather than the interpolation
    if /foo/.match(begin_node.parent.source)
@jamesmartin
jamesmartin / gist:b1bbbcdf2d160d9c2142c103c7897b19
Created June 9, 2020 07:29
Curl a bunch of URLs out of a file 🤷‍♂️
cat urls
http://www.fillmurray.com/200/300
http://www.fillmurray.com/g/200/300
http://www.fillmurray.com/400/600
while read url; do curl -O "$url"; done <urls
@jamesmartin
jamesmartin / userscript.js
Last active April 28, 2020 05:40
Safari Userscript for GitHub Notifications v2
// For use with https://github.com/quoid/userscripts
// and https://github.com/notifications
function removeNotificationShelf() {
if (window.location.href.match(/github\.com\/.*/)) {
const notificationShelf = document.querySelector('.js-notification-shelf')
if (notificationShelf) {
console.log("Removing the notifications shelf!")
notificationShelf.parentNode.removeChild(notificationShelf)
}
@jamesmartin
jamesmartin / test.md
Created February 27, 2020 00:18
Test gist

This is a test.