Skip to content

Instantly share code, notes, and snippets.

Avatar

Scott McMillin scottymac

View GitHub Profile
@scottymac
scottymac / UnixTimeCodedDate.swift
Created Dec 16, 2021
Decodable Property Wrapper
View UnixTimeCodedDate.swift
import Foundation
@propertyWrapper
struct UnixTimeCodedDate {
var wrappedValue: Date?
init(wrappedValue: Date?) {
self.wrappedValue = wrappedValue
}
}
View SimpleStateMachine.swift
// The MIT License
//
// Copyright (c) 2015-2021 Scott McMillin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@scottymac
scottymac / Toggleable.swift
Created Feb 19, 2021
Swift Toggleable Enum protocol extension
View Toggleable.swift
import Foundation
protocol Toggleable: CaseIterable, Equatable {
mutating func toggle()
}
extension Toggleable {
mutating func toggle() {
guard Self.allCases.count == 2, let firstCase = Self.allCases.first else {
fatalError("Enum must have only two elements")
@scottymac
scottymac / lucky_crud.cr
Created Nov 20, 2018
Lucky Framework (Crystal) Basic CRUD setup
View lucky_crud.cr
# MODEL
class Foo < BaseModel
table :foos do
column name : String
end
end
# FORM
class FooForm < Foo::BaseForm
fillable name
View Instagram to Feedbin using RSSHub bookmarklet
var current_url = window.location.href;
var feedbin_url = "https://feedbin.me/?subscribe="
var inst_regex = new RegExp("https:\/\/www\.instagram\.com\/(.*)\/");
var inst_username = inst_regex.exec(current_url)[1];
if (inst_username !== "" || inst_username !== undefined) {
var feed_url = "https://rsshub.app/instagram/user/" + inst_username;
window.location = feedbin_url + feed_url;
}
// The bookmarklet
View gist:d155fb0d1cafb14fa397ca8f4e29c4ad
Verifying my Blockstack ID is secured with the address 1C6zqdybJmBASXyRvxUeTpDWjeEodyHykQ https://explorer.blockstack.org/address/1C6zqdybJmBASXyRvxUeTpDWjeEodyHykQ
View IconServiceAgent.md

I was chasing down another issue (slow "Save As") and thought these two issues may have been related (with QuickLook being the common broken link). Unfortunately, my "Save As" dialog is still miserably slow on the initial load; but IconServicesAgent hasn't gone above 30MB and he rarely makes an appearance in the Console!

Some of these steps may not be necessary, but here are all of the steps I took that inadverdently put IconServicesAgent back in its place. Note: all commands are a single-line, if they appear to be multiple that's just the forum formatting.

  1. Check for any QuickLooks related .plist files. In a terminal: mdfind com.apple.quicklook. -name .plist

  2. I only had files at the system level (specifically within /System/Library/LaunchAgents/). If you have others, modify the directions below to take that into account (re-introducing plist files from the system level back up to the user).

  3. Make some temporary directories to store these plist files, just in case: mkdir ~/tmp-quicklook

View MediatorStatePattern.swift
// The MIT License
//
// Copyright (c) 2015-2017 Scott McMillin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
View Events.cs
using System.Collections;
using System.Collections.Generic;
public class GameEvent
{
}
public class Events
{
static Events instanceInternal = null;
@scottymac
scottymac / Postgres Cast an Array Column for Comparison
Last active Aug 29, 2015
Postgres Cast an Array Column for Comparison
View Postgres Cast an Array Column for Comparison
-- datetimes is an array column of strings (b/c ActiveRecord doesn't support arrays of datetimes just yet (but soon))
-- This is doing a date comparison
SELECT * FROM table WHERE now() ANY (CAST(datetimes as timestamp[]))
in ActiveRecord:
scope :past, lambda {
where(":now > ALL (CAST(datetimes as timestamp[]))", { now: Time.zone.now })
}