Skip to content

Instantly share code, notes, and snippets.

View cwagdev's full-sized avatar

Chris Wagner cwagdev

View GitHub Profile
services:
mc:
image: itzg/minecraft-server
tty: true
stdin_open: true
ports:
- "25565:25565"
environment:
INIT_MEMORY: 1G
MAX_MEMORY: 4G
@cwagdev
cwagdev / Scrydget.js
Last active June 1, 2021 21:06
Scrydget - Random MTG Card Widget for Scriptable
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: brown; icon-glyph: magic;
// Show a random MTG Card
const { transparent } = importModule('no-background')
let card = await randomCard()
let widget = await createWidget(card)
import UIKit
import CoreData
class BasicFetchedResultsControllerDelegate: NSObject, NSFetchedResultsControllerDelegate {
let tableView: UITableView
var controllerDidChangeContentCallback: (() -> Void)?
/// The threshold for the number of inserts, deletes, and reloads to peform using animations. If the threshold is exceeded, the table will be reloaded using `reloadData()`. The default value is `50`.
var numberOfRowOperationsThresholdBeforeFullReloadOccurs = 50
// Swift 2.2
let queue = dispatch_queue_create("myqueue", nil)
dispatch_async(queue) {
// do stuff
}
// Swift 3
let queue = DispatchQueue(label: "myqueue")
queue.async {
// do stuff
@cwagdev
cwagdev / UIImageExt.swift
Created August 17, 2015 23:18
UIImage?(color: UIColor) initializer
extension UIImage {
convenience init!(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) {
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext()
CGContextSetFillColorWithColor(context, color.CGColor)
CGContextFillRect(context, rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
@cwagdev
cwagdev / CreditCard.swift
Last active June 27, 2019 10:04
Credit Cards represented in Swift
/// Describes a type of credit card for a subset of known types.
enum CreditCardType: Printable {
case Amex, DinersClub, Discover, JCB, MasterCard, Visa, Unknown
var description: String {
switch self {
case .Amex:
return "Amex"
case .DinersClub:
return "Diners Club"
@cwagdev
cwagdev / Luhn.swift
Created July 17, 2015 19:40
Luhn Algorithm in Swift
func luhnCheck(number: String) -> Bool {
var sum = 0
let digitStrings = reverse(number).map { String($0) }
for tuple in enumerate(digitStrings) {
if let digit = tuple.element.toInt() {
let odd = tuple.index % 2 == 1
switch (odd, digit) {
case (true, 9):
protocol ValueForKeyLookupable {
func valueForKey(key: String) -> Any?
}
extension ValueForKeyLookupable {
func valueForKey(key: String) -> Any? {
let mirror = reflect(self)
for index in 0..<mirror.count {
let child = mirror[index]
if key == child.0 {return child.1.value}
func loginUserWithUsername(username: String, password: String) throws -> String {
guard username.characters.count != 0 else {
throw LoginError.EmptyUsername
}
guard password.characters.count != 0 else {
throw LoginError.EmptyPassword
}
///Handle all the other,
@cwagdev
cwagdev / UIApplicationExt.swift
Created March 13, 2015 22:06
UIApplication Extension for Version and App Name
extension UIApplication {
class var versionString: String {
get {
if let bundleInfoDictionary = NSBundle.mainBundle().infoDictionary {
let buildVersionString = bundleInfoDictionary["CFBundleVersion"] as String
let marketingVersionString = bundleInfoDictionary["CFBundleShortVersionString"] as String
return marketingVersionString + " (\(buildVersionString))"
} else {
return "Unknown"
}