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
@norsez
norsez / isPalindrome
Last active February 28, 2019 09:38
isPalindrome in Swift 4.2
extension String {
var isPalindrome: Bool {
let reversed = String( self.reversed() )
for index in self.indices {
if self.lowercased()[index] != reversed.lowercased()[index] {
return false
}
}
@norsez
norsez / TableSearchSampleiOS11.swift
Created May 24, 2018 09:43
Programmatically configure UISearchController and its result table in iOS 11 for an expensive search loop
// Created by Norsez Orankijanan on 17/5/2561 BE.
import UIKit
//MARK: a separate view controller for showing the search results works better with a storyboard or xib.
class ResultsTableViewController: UITableViewController {
var items = [String] ()
let CELLID = "CELLID"
override func viewDidLoad() {
super.viewDidLoad()
@norsez
norsez / JSONSaveLoad.swift
Created May 7, 2018 04:47
Load and Save JSON objects into a local file (written in Swift)
import Foundation
/**
Extension to save/load a JSON object by filename. (".json" extension is assumed and automatically added.)
*/
extension JSONSerialization {
static func loadJSON(withFilename filename: String) throws -> Any? {
let fm = FileManager.default
@norsez
norsez / MediumRSSXMLParser.swift
Last active April 30, 2018 02:38
Medium.com RSS XML parser written in Swift
// Created by norsez on 30/4/18.
import Foundation
struct RssItem {
var title = "unknown"
var categories: [String] = []
var pubDate = "unknown"
var link = "http://"
var content = "<h1>Hello World</h1>"
var creator = "n.a."
@norsez
norsez / comments_and_likes.py
Last active August 25, 2017 06:48
Dumping a Facebook post's comments and likes into CSV files
# Loading post comments and likes by Norsez Orankijanan nor@telenordigital.com
# based on example 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...
@norsez
norsez / Date+ISO8601.swift
Created June 21, 2017 05:18
Swift 3: Date <-> ISO 8601 String conversion
extension Date {
static func ISOStringFromDate(date: Date) -> String {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.timeZone = TimeZone(abbreviation: "GMT")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"
return dateFormatter.string(from: date).appending("Z")
}
@norsez
norsez / MovieWriter.swift
Created May 11, 2017 04:13 — forked from isthisjoe/MovieWriter.swift
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
}
@norsez
norsez / UIImage+Rotation.swift
Last active February 19, 2023 04:54
Rotate UIImage by radians in Swift 3
extension UIImage {
func image(withRotation radians: CGFloat) -> UIImage {
let cgImage = self.cgImage!
let LARGEST_SIZE = CGFloat(max(self.size.width, self.size.height))
let context = CGContext.init(data: nil, width:Int(LARGEST_SIZE), height:Int(LARGEST_SIZE), bitsPerComponent: cgImage.bitsPerComponent, bytesPerRow: 0, space: cgImage.colorSpace!, bitmapInfo: cgImage.bitmapInfo.rawValue)!
var drawRect = CGRect.zero
drawRect.size = self.size
let drawOrigin = CGPoint(x: (LARGEST_SIZE - self.size.width) * 0.5,y: (LARGEST_SIZE - self.size.height) * 0.5)
@norsez
norsez / gist:4129399
Created November 22, 2012 04:08
UNIX command line image Resizing
sips -Z 640 *JPG
@norsez
norsez / BDDimGlassView.podspec
Created September 11, 2012 07:21
How to write custom pod spec to include another lib or even an app for internal use with svn
Pod::Spec.new do |s|
s.name = 'BDDimGlassView'
s.version = '0.0.1'
s.license = 'BSD'
s.summary = 'Dim Glass bordered container for UIViews.'
s.description = 'description here.'
s.homepage = 'https://github.com/norsez'
s.author = {'Norsez Orankijanan' => 'norsez.github@gmail.com'}
#This is the revision of BitApp this app uses