Skip to content

Instantly share code, notes, and snippets.

View Exey's full-sized avatar

Exey Panteleev Exey

View GitHub Profile
@ryansobol
ryansobol / Array+Permutations.swift
Last active August 12, 2021 15:38
Generate the permutations of a Swift array
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]))
@jcamp
jcamp / video-editors-opensource.md
Last active March 26, 2024 22:07
OpenSource Video Editors
@eneko
eneko / List.swift
Last active July 29, 2018 12:21
Linked List in Swift
/// 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))
# -*- coding: utf-8 -*-
import requests
from time import sleep
from datetime import datetime
import json
import sys
database = {"admins":[],
"suggestions":{}
}
@albertbori
albertbori / HideableUIView.swift
Last active August 9, 2018 10:14
iOS Swift Extension for easily hiding/showing UIViews constrained using Auto Layout
//
// 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.
//
@jdriscoll
jdriscoll / Layout.swift
Last active October 28, 2016 14:19
Simple Swift Auto Layout Extensions
//
// Layout.swift
//
// Created by Justin Driscoll on 2/22/15.
//
import UIKit
struct Inset {
let value: CGFloat
@brutella
brutella / icons
Last active August 29, 2023 15:10
Generate iOS, watchOS, and macOS app icons from one image
#! /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)"
// 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) {
@calebd
calebd / ArrayHelpers.swift
Last active November 4, 2022 15:17
Swift Helpers
extension Array {
func first() -> Element? {
if isEmpty {
return nil
}
return self[0]
}
func last() -> Element? {
@jmont
jmont / maybe.m
Last active March 30, 2016 16:27
Swift Monads
// 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.