Skip to content

Instantly share code, notes, and snippets.

View samkcarlile's full-sized avatar
👽

Sam Carlile samkcarlile

👽
View GitHub Profile
@samkcarlile
samkcarlile / template.webloc
Created November 12, 2019 16:24
macOS Template for URL shortcut files
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>URL</key>
<string>http://example.com</string>
</dict>
</plist>
@samkcarlile
samkcarlile / darkmode.sh
Created November 11, 2019 05:26
Toggle Dark Mode on macOS
#!/usr/local/bin/bash
osascript -e 'tell app "System Events" to tell appearance preferences to set dark mode to not dark mode'
@samkcarlile
samkcarlile / letter_grade_calc.js
Created November 4, 2019 20:52
Cool letter grade to point value conversion
/**
*
* @param {string} letter the string representation of the grade. Examples: ["a-", "A", "F", "b+"]
* @param {number} points the number of points that an perfect A represents on the scale
* @param {number} inc the number of points in between each full letter grade
*/
function grade(letter = "", points = 4, inc = 1) {
if (letter.length < 1 || letter.length > 2) {
throw 'the length of the letter grade string must be equal to 1 or 2'
}
@samkcarlile
samkcarlile / getFileLinks.js
Last active October 24, 2019 02:05
Get File Links on a Webpage
@samkcarlile
samkcarlile / CenteredJFrame.java
Last active June 25, 2019 16:14
[Center a JFrame] centers a jframe onscreen. #java #swing #jframe
public class CenteredJFrame {
public static void main(String[] args) {
JFrame frame = new JFrame();
center(frame, 800, 600);
frame.add(new JButton("Bananas"));
frame.add(new JButton("Oranges"));
frame.add(new JButton("Apples"));
frame.setVisible(true);
}
@samkcarlile
samkcarlile / get-running-apps.sh
Created February 1, 2019 00:20
Get's the name of all MacOS applications that are found in the ~/Applications or /Applications folder
#!/bin/bash
ps -u $(whoami) -x -o comm | egrep -o '/Applications/([A-z0-9 ]+/)?[A-z0-9 ]+\.app' | sort -u | egrep -o '[A-z0-9 ]+\.app' | awk '{if (NR!=0) {print substr($0, 1, length($0) - 4)}}'