Updated: 20240917
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array { | |
func chopped() -> (Element, [Element])? { | |
guard let x = self.first else { return nil } | |
return (x, Array(self.suffix(from: 1))) | |
} | |
} | |
print([1, 2, 3].chopped()) | |
// Optional((1, [2, 3])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A list is either empty or it is composed of a first element (head) | |
/// and a tail, which is a list itself. | |
/// | |
/// See http://www.enekoalonso.com/projects/99-swift-problems/#linked-lists | |
class List<T> { | |
var value: T | |
var nextItem: List<T>? | |
convenience init?(_ values: T...) { | |
self.init(Array(values)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import requests | |
from time import sleep | |
from datetime import datetime | |
import json | |
import sys | |
database = {"admins":[], | |
"suggestions":{} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// HideableUIView.swift | |
// Albert Bori | |
// | |
// Created by Albert Bori on 5/19/15. | |
// Copyright (c) 2015 Albert Bori under the MIT license. | |
// 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: | |
// | |
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Layout.swift | |
// | |
// Created by Justin Driscoll on 2/22/15. | |
// | |
import UIKit | |
struct Inset { | |
let value: CGFloat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
function print_example() { | |
echo "Example" | |
echo " icons ios ~/AppIcon.pdf ~/Icons/" | |
} | |
function print_usage() { | |
echo "Usage" | |
echo " icons <ios|watch|complication|macos> in-file.pdf (out-dir)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Playground - noun: a place where people can play | |
import Cocoa | |
struct Regex { | |
let pattern: String | |
let expressionOptions: NSRegularExpressionOptions | |
let matchingOptions: NSMatchingOptions | |
init(pattern: String, expressionOptions: NSRegularExpressionOptions, matchingOptions: NSMatchingOptions) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array { | |
func first() -> Element? { | |
if isEmpty { | |
return nil | |
} | |
return self[0] | |
} | |
func last() -> Element? { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Swift Monads -- Maybe | |
// Juan C. Montemayor (@norsemelon) | |
// This operator can be used to chain Optional types like so: | |
// optionalVal >>= f1 >>= f2 | |
// where f1 and f2 have type `Any -> Any?` | |
// | |
// If a value is ever nil, the chain short-circuits and will result in nil. | |
// This is a much neater way to do this than using the if syntax specified in | |
// the Swift iBook. |
NewerOlder