Skip to content

Instantly share code, notes, and snippets.

View Kievkao's full-sized avatar

Andrii Kravchenko Kievkao

View GitHub Profile
@FWEugene
FWEugene / String+LanguageDetector.swift
Last active August 3, 2021 11:36
Detecting Language
// The result is not guaranteed to be accurate. Typically, the function requires 200-400 characters to reliably guess the language of a string.
// Reference: [CFStringTokenizerCopyBestStringLanguage(_:_:)](https://developer.apple.com/reference/corefoundation/1542136-cfstringtokenizercopybeststringl)
//
import Foundation
extension String {
func guessLanguage() -> String {
let length = self.utf16.count
let languageCode = CFStringTokenizerCopyBestStringLanguage(self as CFString, CFRange(location: 0, length: length)) as String? ?? ""
protocol Copyable {
associatedtype V
func copy() -> V
func setup(v: V) -> V
}
class One: Copyable {
typealias V = One
var name: String?
@phucnm
phucnm / gist:77a4ba13f30efff0c475b2c7e56c2d1a
Created April 14, 2016 08:14
Detect current page number in paging enabled Collection view
// Scrollview.tag will equal to your collection view's tag
// Use page to update page control or whatever
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
print("tag = \(scrollView.tag)")
let pageWidth = scrollView.frame.size.width
let page = Int(floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1)
print("page = \(page)")
}
//
// ViewController.m
// AVPlayerCaching
//
// Created by Anurag Mishra on 5/19/14.
// Sample code to demonstrate how to cache a remote audio file while streaming it with AVPlayer
//
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@nuthinking
nuthinking / UIView+CustomTimingFunction.h
Created November 11, 2013 15:59
UIView Custom Timing Functions
//
// UIView+CustomTimingFunction.h
// Instants
//
// Created by Christian Giordano on 16/10/2013.
// Copyright (c) 2013 Christian Giordano. All rights reserved.
//
#import <UIKit/UIKit.h>
@rsaunders100
rsaunders100 / UIImage+ImageSplitting.h
Created February 3, 2012 15:02
(iOS) Split an image into an array of evenly sized CALayers
//
// UIImage+ImageSplitting.h
// Test
//
// Created by Robert Saunders on 03/02/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>