Skip to content

Instantly share code, notes, and snippets.

View alekseypotapov-dev's full-sized avatar

Aleksey Potapov alekseypotapov-dev

View GitHub Profile
@alekseypotapov-dev
alekseypotapov-dev / SwiftC.swift
Created December 4, 2015 15:51
Swift with C example
//original video https://realm.io/news/pragma-chris-eidhof-swift-c/
import Foundation
extension Comparable {
static func compare (l: UnsafePointer<Void>, _ r: UnsafePointer<Void>) -> Int32 {
let left: Self = UnsafePointer(l).memory
let right: Self = UnsafePointer(r).memory
if left < right { return -1 }
if left == right { return 0 }
@alekseypotapov-dev
alekseypotapov-dev / bash.txt
Last active December 11, 2015 15:01
bash usefult commands
#copy directory hierarchy without files
pathFrom$ find . -type d -exec mkdir -p /pathTo/{} \;
@alekseypotapov-dev
alekseypotapov-dev / String.swift
Created December 16, 2015 23:01 — forked from kharrison/String.swift
Swift String Playground Examples
// Swift Standard Librray - String
// Keith Harrison http://useyourloaf.com
// Import Foundation if you want to bridge to NSString
import Foundation
// ====
// Initializing a String
// ====
@alekseypotapov-dev
alekseypotapov-dev / .xvimrc
Last active March 29, 2016 20:13
handy .xvimrc configurator for Xcode, see this repo: github.com/XVimProject/XVim
"Author: Zoltán Bognár
"put into ~/
syntax enable
set hls
highlight Search guibg=#7D2F52
set bg=light
set tabstop=4
set softtabstop=4
set shiftwidth=4
set scrolloff=2
@alekseypotapov-dev
alekseypotapov-dev / Macros.swift
Created April 14, 2016 11:59 — forked from xmzio/Macros.swift
My aLog and dLog macros in Swift (to abbreviate NSLog)
//
// Macros.swift
//
// Created by Xavier Muñiz on 6/12/14.
import Foundation
// dLog and aLog macros to abbreviate NSLog.
// Use like this:
@alekseypotapov-dev
alekseypotapov-dev / ArrayExtension.swift
Created September 20, 2016 10:31
Group Array of Arrays by parameter
extension Array {
func groupBy<G: Hashable>(groupClosure: (Element) -> G) -> [[Element]] {
var groups = [[Element]]()
for element in self {
let key = groupClosure(element)
var active = Int()
var isNewGroup = true
var array = [Element]()
@alekseypotapov-dev
alekseypotapov-dev / UniqueValues.swift
Created September 20, 2016 12:39
Unique Sequence
func uniq<S: SequenceType, E: Hashable where E==S.Generator.Element>(source: S) -> [E] {
var seen: [E:Bool] = [:]
return source.filter { seen.updateValue(true, forKey: $0) == nil }
}
@alekseypotapov-dev
alekseypotapov-dev / my.zshrc
Created September 21, 2016 15:03
Configured regarding needs
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=/Users/alex-potapov/.oh-my-zsh
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"
@alekseypotapov-dev
alekseypotapov-dev / CoreGraphicsExtension.swift
Last active September 29, 2016 16:56
CoreGraphics methods override
//Copyright
//https://habrahabr.ru/post/271647/
import Foundation
// Summ and Substraction of Vectors
func +(left: CGPoint, right: CGPoint)->CGPoint{
return CGPoint(x: left.x+right.x, y: left.y+right.y)
}
prefix func -(right: CGPoint)->CGPoint{
/// Wraps the observer token received from
/// NotificationCenter.addObserver(forName:object:queue:using:)
/// and unregisters it in deinit.
final class NotificationToken: NSObject {
let notificationCenter: NotificationCenter
let token: Any
init(notificationCenter: NotificationCenter = .default, token: Any) {
self.notificationCenter = notificationCenter
self.token = token