Skip to content

Instantly share code, notes, and snippets.

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

Block or report user

Report or block mingsai

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mingsai
mingsai / utils.php
Last active Jul 17, 2019
Useful PHP snippets
View utils.php
<?php
//assoc array?
function has_string_keys(array $array) {
return count(array_filter(array_keys($array), 'is_string')) > 0;
}
//obj to array?
$array = json_decode(json_encode($nested_object), true);
@mingsai
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
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 }
context.setFillColor(color.cgColor)
context.fill(rect)
@mingsai
mingsai / AsyncTask.swift
Created Dec 22, 2017
A simple background task class snippet (from: https://pastebin.com/0HSd3jAE)
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
mingsai / Test4SQLiteOptions.txt
Created Dec 9, 2017
Swift to Query Apple's Compile time Options for SQLite
View Test4SQLiteOptions.txt
Stackoverflow Answer (https://stackoverflow.com/questions/2266584/iphone-app-with-sqlite-fts3-xcode-release-build-not-working/47729842#47729842)
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
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:
http://www.yourdomain.com/.htpasswd
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
mingsai / dicewarewordlist.txt
Created Aug 9, 2017
Diceware English Word List
View dicewarewordlist.txt
Diceware.com 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
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');
checkIfUserExists(userId);
}
var USERS_LOCATION = 'https://SampleChat.firebaseIO-demo.com/users';
function userExistsCallback(userId, exists) {
if (exists) {
alert('user ' + userId + ' exists!');
You can’t perform that action at this time.