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 / 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 / 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 / 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.

@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 / test.erb
Last active July 18, 2017 07:13
radio buttons and checkboxes
<h1>Test</h1>
<% if !@p.nil? %>
<%= @p.inspect %>
<% end %>
<form method="post" action="/">
<h2>Have you ever smoked?</h2>
<p>
<input type="radio" name="smoker" value="Yes"> Yes<br>
@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
# Gives an accurate balance for 28degrees credit card including pending transactions.
# Copy pasta the transactions from the 28degrees website into a plain text
# file and then feed it into this script.
#
# $> ruby 28degrees.rb some-text-file.txt
#
if $0 == __FILE__
unless ARGV[0]
puts "Usage: #{__FILE__} filename"
exit 1