Skip to content

Instantly share code, notes, and snippets.

View norsez's full-sized avatar
💭
busy coding

Norsez Orankijanan norsez

💭
busy coding
View GitHub Profile
@hamdan
hamdan / MultipleTapLabel.swift
Last active November 15, 2023 21:26
Create Multiple Tappable Links in a UILabel
extension UITapGestureRecognizer {
func didTapAttributedTextInLabel(label: UILabel, targetText: String) -> Bool {
guard let attributedString = label.attributedText, let lblText = label.text else { return false }
let targetRange = (lblText as NSString).range(of: targetText)
//IMPORTANT label correct font for NSTextStorage needed
let mutableAttribString = NSMutableAttributedString(attributedString: attributedString)
mutableAttribString.addAttributes(
[NSAttributedString.Key.font: label.font ?? UIFont.smallSystemFontSize],
range: NSRange(location: 0, length: attributedString.length)
@gf3
gf3 / iTunes.swift
Created August 29, 2017 18:50
iTunes ScriptingBridge from Swift
import AppKit
import ScriptingBridge
@objc public protocol SBObjectProtocol: NSObjectProtocol {
func get() -> Any!
}
@objc public protocol SBApplicationProtocol: SBObjectProtocol {
func activate()
var delegate: SBApplicationDelegate! { get set }
@jkuruzovich
jkuruzovich / fbme.py
Created February 3, 2017 18:28 — forked from espeed/fbme.py
Facebook Graph API Example in Python
# Facebook Graph API Example in Python
# by James Thornton, http://jamesthornton.com
# Facebook API Docs
# https://developers.facebook.com/docs/graph-api/using-graph-api#reading
# Get Your Facebook Access Token Here...
# https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=me
# Before running this script...
@MagnusNordin
MagnusNordin / Badge.swift
Last active December 22, 2022 09:38 — forked from yonat/Badge.swift
Rounded UILabel and UIButton, Badged UIBarButtonItem
//
// Badge.swift
// Extensions for Rounded UILabel and UIButton, Badged UIBarButtonItem.
//
// Usage:
// let label = UILabel(badgeText: "Rounded Label");
// let button = UIButton(type: .System); button.rounded = true
// let barButton = UIBarButtonItem(badge: "42", title: "How Many Roads", target: self, action: "answer")
//
// Created by Yonat Sharon on 06.04.2015.
@khorbushko
khorbushko / PHPhotoLibrary+SaveImage
Created December 29, 2016 09:27
PHPhotoLibrary+SaveImage - save image with Photos Framework swift 3
import UIKit
import Photos
extension PHPhotoLibrary {
// MARK: - PHPhotoLibrary+SaveImage
// MARK: - Public
func savePhoto(image:UIImage, albumName:String, completion:((PHAsset?)->())? = nil) {
func save() {
@Willib
Willib / export images to a video (async)
Last active May 28, 2023 13:24
export images(or one image) to a video in swift 3
//
// CXEImageToVideo.swift
// VideoAPPTest
//
// Created by Wulei on 16/12/14.
// Copyright © 2016年 wulei. All rights reserved.
//
import Foundation
import AVFoundation
@michaelevensen
michaelevensen / PagingCollectionViewController.swift
Last active April 10, 2024 08:46
An example of perfectly paging horizontal UICollectionViewController with overflowing cells. Works great with Storyboard — no need to set any specific attributes, just add this Class to the Controller and set your desired size for the cells like you would normally.
import UIKit
private let reuseIdentifier = "Cell"
class CollectionViewController: UICollectionViewController {
/* Custom scrollView for paging */
let pagingScrollView = UIScrollView()
/* Return item size */
@isthisjoe
isthisjoe / MovieWriter.swift
Last active July 8, 2020 07:28
Swift 3 | macOs | Write NSImage(s) to a movie file. Modified from http://stackoverflow.com/a/36297656/1275125
import AppKit
import AVFoundation
class MovieWriter: NSObject {
func writeImagesAsMovie(_ allImages: [NSImage], videoPath: String, videoSize: CGSize, videoFPS: Int32) {
// Create AVAssetWriter to write video
guard let assetWriter = createAssetWriter(videoPath, size: videoSize) else {
print("Error converting images to video: AVAssetWriter not created")
return
}
@mcxiaoke
mcxiaoke / StringExtensions.swift
Created August 24, 2016 06:27
replace for Swift String (include replaceFirst and replaceAll), in Swift 3
import Foundation
extension String {
public func replaceFirst(of pattern:String,
with replacement:String) -> String {
if let range = self.range(of: pattern){
return self.replacingCharacters(in: range, with: replacement)
}else{
return self
@cmoulton
cmoulton / BasicAuth.swift
Created June 29, 2016 16:46
Alamofire Basic Auth
func doGetWithBasicAuthCredential() -> Void {
let username = "myUsername"
let password = "myPassword"
let credential = NSURLCredential(user: username, password: password, persistence: NSURLCredentialPersistence.ForSession)
Alamofire.request(.GET, "https://httpbin.org/basic-auth/\(username)/\(password)")
.authenticate(usingCredential: credential)
.responseString { _, _, result in
if let receivedString = result.value