Skip to content

Instantly share code, notes, and snippets.

Tommie N. Carter, Jr., BSIT, MBA mingsai

View GitHub Profile
mingsai / RSSFeed.swift
Created Jan 15, 2019 — forked from kharrison/RSSFeed.swift
Swift Decodable With Multiple Custom Dates
View RSSFeed.swift
import Foundation
extension DateFormatter {
static let iso8601Full: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
formatter.calendar = Calendar(identifier: .iso8601)
formatter.timeZone = TimeZone(secondsFromGMT: 0)
formatter.locale = Locale(identifier: "en_US_POSIX")
return formatter
mingsai / MNGManagedObjectExtensions.swift
Last active Jan 1, 2019
My attempt at extracting/reconstructing NSManagedObjects from dictionaries recursively in Swift. With the eventual goal of serializing dictionaries to data somewhere.
View MNGManagedObjectExtensions.swift
// MNGManagedObjectExtensions.swift
// rtj
// Created by Tommie N. Carter, Jr., MBA on 1/1/19.
// Copyright © 2019 MING Technology. All rights reserved.
import UIKit
View UIImage+Color.swift
import UIKit
extension UIImage {
class func colorAsImage(from color:UIColor, for size:CGSize) -> UIImage? {
var img:UIImage?
let rect = CGRect(x:0.0, y:0.0, width: size.width, height: size.height)
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0)
guard let context = UIGraphicsGetCurrentContext() else { return nil }
mingsai / AsyncTask.swift
Created Dec 22, 2017
A simple background task class snippet (from:
View AsyncTask.swift
import Foundation
*AsyncTask v1.1 Updated: 2016-12-01
*Defines a task which executed asynchronously in background thread.
*Every AsyncTask instance has 3 life cycle events:
* 1. beforeTask execution (Optional) - executed on UI Main thread
* 2. bagkroundTask execution - executed in background thread
* 3. afterTask execution (Optional) - executed on UI Main thread
*When caller instantiates AsyncTask he\she can decide what data type to pass in and out, using
View sqlite-partial-struct.swift
//where Medicine is an encodable, decodable struct
fileprivate static let medicineTable = Table("medicine")
fileprivate static let counterTable = Table("counter")
fileprivate static let medicineColumn = Expression<Int>("medicine")
fileprivate static let idColumn = Expression<Int64>("id")
static func update(item: Medicine, onCompletion: (Bool, Error?) -> ()) {
guard let db = SQLiteDataEngine.shared.db else {
onCompletion(false, DataAccessError.Database_Connection_Error)
mingsai / Test4SQLiteOptions.txt
Created Dec 9, 2017
Swift to Query Apple's Compile time Options for SQLite
View Test4SQLiteOptions.txt
Stackoverflow Answer (
Highlights the useful code supplied by @Robert Hawkey
Shows full code and output for Xcode 9/Swift 4.0.3
Enables one to assess useful features of SQLite in iOS (eg. JSON SQL Functions)
Swift 4.0.3
func testSQLiteOptions(){
var db: OpaquePointer? = nil
var statement: OpaquePointer? = nil
sqlite3_open(self.dbPath, &db)
mingsai / Instructions.txt
Created Aug 18, 2017
How to use htpasswd to secure web folders
View Instructions.txt
put the htpaswd file outside of your root folder so it isn’t web accessible like:
In terminal one can generate a htaccess password
htpasswd -nb username password
Use a strong random number generator to create a salt of 16 bytes or longer.
Feed the salt and the password into the PBKDF2 algorithm.
Use HMAC-SHA-256 as the core hash inside PBKDF2.
mingsai / dicewarewordlist.txt
Created Aug 9, 2017
Diceware English Word List
View dicewarewordlist.txt Dice-Indexed Passphrase Word List
Page 1
11111 a
11112 a&p
11113 a's
11114 aa
11115 aaa
11116 aaaa
11121 aaron
11122 ab
mingsai / firebase_detect_data.js
Created Apr 18, 2017 — forked from anantn/firebase_detect_data.js
Firebase: Detecting if data exists. This snippet detects if a user ID is already taken
View firebase_detect_data.js
function go() {
var userId = prompt('Username?', 'Guest');
function userExistsCallback(userId, exists) {
if (exists) {
alert('user ' + userId + ' exists!');
mingsai / Instructions
Last active Apr 9, 2017
Manage Atom Packages on multiple machines
View Instructions
To manage atom packages on multiple machines
1 - Create a Makefile in the atom folder:
2 - Contents of Makefile:
cat packages.list | xargs apm install
packages.list: packages/*/
You can’t perform that action at this time.