Skip to content

Instantly share code, notes, and snippets.

@tedchoward
tedchoward / Play_SomaFM.scpt
Last active March 26, 2018 16:47
AppleScript (JXA) that fetches a list of channels from SomaFM and plays the selected channel.
class SomaFM {
constructor(app) {
const jsonStr = app.doShellScript('curl https://somafm.com/channels.json');
const { channels } = JSON.parse(jsonStr);
this._opts = channels.map(c => ({ name: c.title, url: c.playlists[0].url}));
this._names = this._opts.map(opt => opt.name);
}
get names() { return [ ...this._names]; }
@tedchoward
tedchoward / flickrExport.js
Created July 20, 2017 22:27
Download all your images from Flickr. (Does not work for videos)
const Flickr = require('flickrapi');
const Bluebird = require('bluebird');
const request = require('request');
const fs = require('fs');
const path = require('path');
const DOWNLOAD_PATH = path.resolve(process.env.HOME, 'Downloads/flickr');
const flickrOptions = {
api_key: process.env.FLICKR_API_KEY,
@tedchoward
tedchoward / ExceptionUtils.java
Created August 10, 2016 14:07
ExceptionUtils provides a static method that will throw a checked exception as if it were a runtime exception. You can use this to catch and re-throw a checked exception without wrapping it in a RuntimeException and muddying up the stack trace.
public class ExceptionUtils {
public static void throwException(Exception ex) {
if (ex instanceof RuntimeException) throw (RuntimeException)ex;
try {
synchronized (CheckedExceptionThrower.class) {
CheckedExceptionThrower.exception = ex;
CheckedExceptionThrower.class.newInstance();
}
} catch (InstantiationException | IllegalAccessException e) {
@tedchoward
tedchoward / example.js
Last active July 12, 2016 15:32 — forked from scripting/example.js
Question about best practice with JS objects and internal method calls
// Capitalize the name of the constructor function
var MessageOfTheDay = function (appName) {
this._readHttpCallback = this._readHttpCallback.bind(this);
this.appName = appName;
if (this.lastMessageText === undefined) {
this.lastMessageText = "";
}
};
messageOfTheDay.prototype = {
@tedchoward
tedchoward / bumpme
Last active November 23, 2016 23:04
Wed Nov 23 23:04:51 UTC 2016
@tedchoward
tedchoward / Readme.md
Last active May 10, 2024 15:39
launchd script to keep OPML editor running

Copy the plist to ~/Library/LaunchAgents then run

launchctl load ~/Library/LaunchAgents/com.scripting.opml.plist

This plist assumes that OPML Editor is installed in /Applications/OPML. If you have it installed in a different location, you will need to modify line 13 of the plist.

The OPML Editor should launch. It will re-launch within 10 seconds if it quits for whatever reason.

killall OPML