Skip to content

Instantly share code, notes, and snippets.

View avdyushin's full-sized avatar

Grigory Avdyushin avdyushin

View GitHub Profile
@avdyushin
avdyushin / UIImageExtensions.swift
Last active May 31, 2016 11:33
UIImage missed resize method via Swift extensions
extension UIImage {
convenience init?(color: UIColor, size: CGSize = CGSizeMake(1, 1)) {
let rect = CGRectMake(0, 0, size.width, size.height)
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0)
let context = UIGraphicsGetCurrentContext()
CGContextSetFillColorWithColor(context, color.CGColor)
CGContextFillRect(context, rect)
self.init(CGImage: UIGraphicsGetImageFromCurrentImageContext().CGImage!)
UIGraphicsEndImageContext()
@avdyushin
avdyushin / string.swift
Last active May 27, 2016 09:23
Swift extension for string manipulation
//
// String 1.0
// Created by Caleb Hess on 2/22/16.
//
public extension String {
public var count: Int {
return self.characters.count
}
@avdyushin
avdyushin / swift-kvo-example.swift
Created June 21, 2016 14:37 — forked from correia/swift-kvo-example.swift
A quick example for how to use Foundation style KVO from Swift. (Official documentation from Apple is forthcoming.)
//
// Swift-KVO
//
// Created by Jim Correia on 6/5/14.
// Copyright (c) 2014-2015 Jim Correia. All rights reserved.
//
// Update: 6/17/2014
//
// KVOContext has gone away; use the same idiom you'd use from Objective-C for the context
//
@avdyushin
avdyushin / storage.swift
Last active August 28, 2023 14:35
CoreData stack for iOS 9 and iOS 10 using Swift 3
//
// Storage.swift
//
// Created by Grigory Avdyushin on 30.06.16.
// Copyright © 2016 Grigory Avdyushin. All rights reserved.
//
import UIKit
import CoreData
@avdyushin
avdyushin / convert.sh
Created July 11, 2016 13:51
Covert paymentfont.css to Swift cases
#!/bin/sh
if [ -z $1 ]; then
echo "Usage: ${0} file"
exit -1
fi
cat $1 | \
grep .pf- | \
sed -e 's/.pf-//g' | \
@avdyushin
avdyushin / XCTestCase+Expectation.swift
Last active December 1, 2016 10:59 — forked from cgoldsby/XCTestCase+Expectation.swift
XCTestCase extension with boilerplate code for unit testing async functions (waiting for expectations)
//
// AsyncTests.swift
//
import XCTest
// MARK: Async Helper Extension
extension XCTestCase {
@avdyushin
avdyushin / reorder_photos.py
Last active June 20, 2018 19:52
Reorder photos by Exif date
#!/usr/bin/python
# coding: utf8
import io
import re
import time
import shutil
import os.path
import hashlib
import argparse
@avdyushin
avdyushin / GIF-Screencast-OSX.md
Created September 19, 2018 08:08 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@avdyushin
avdyushin / hasPrefix.swift
Last active August 24, 2021 08:15
Swift 4 hasPrefix in switch
let string = "www."
func hasPrefix(_ prefix: String) -> (String) -> Bool {
return { value in value.hasPrefix(prefix) }
}
func ~=(block: (String) -> Bool, string: String) -> Bool {
return block(string)
}
@avdyushin
avdyushin / UnitTests.swift
Created February 5, 2019 10:44
Unit Tests in Swift Playground
class Tests: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
}