Skip to content

Instantly share code, notes, and snippets.

View shaulhameed's full-sized avatar
🎯
Focusing

Shaul Hameed shaulhameed

🎯
Focusing
View GitHub Profile
sfdx force:doc:commands:list
=== Commands
force:alias:list # list username aliases for sfdx
force:alias:set # set username aliases for sfdx
force:apex:class:create # create an apex class
force:apex:execute # execute anonymous apex code
force:apex:log:get # fetch a debug log
force:apex:log:list # list debug logs
force:apex:test:report # display test results
force:apex:test:run # invoke apex tests
@shaulhameed
shaulhameed / String.format
Last active July 26, 2019 05:54
C# like String.format in Javascript
String.format = function() {
var s = arguments[0];
for (var i = 0; i < arguments.length - 1; i++) {
var reg = new RegExp("\\{" + i + "\\}", "gm");
s = s.replace(reg, arguments[i + 1]);
}
return s;
}
@shaulhameed
shaulhameed / CountriesAndStatesTrimmed.json
Created October 27, 2017 07:21
Countries and Corresponding states
[
{
"name":"Afghanistan",
"states":[
"Badakhshan",
"Badgis",
"Baglan",
"Balkh",
"Bamiyan",
"Farah",
@shaulhameed
shaulhameed / CountriesAndStates.json
Last active October 27, 2017 07:08
Countries and States List
[
{
"id":"1",
"sortname":"AF",
"name":"Afghanistan",
"states":[
{
"id":"42",
"name":"Badakhshan",
"country_id":"1"
@shaulhameed
shaulhameed / CoreMLHelpers.swift
Created October 13, 2017 22:41
CoreMLHelpers
extension UIImage {
func resizeTo(size: CGSize) -> UIImage {
UIGraphicsBeginImageContextWithOptions(size, true, 0.0)
self.draw(in: CGRect(origin: CGPoint.zero, size: size))
let renderedImage = UIGraphicsGetImageFromCurrentImageContext()
@shaulhameed
shaulhameed / AutoCorrection.swift
Last active May 30, 2019 20:51
Auto correction implementation for swift based on http://norvig.com/spell-correct.html. Improved the search performance using "trie" data structure.
//
// Trie.swift
// AutoCorrect
//
// Created by Shaul Hameed on 30/07/17.
//
//
import Foundation
/**
* `MulticastDelegate` lets you easily create a "multicast delegate" for a given protocol or class.
*/
open class MulticastDelegate<T> {
/// The delegates hash table.
@shaulhameed
shaulhameed / filessizes.sh
Created May 11, 2017 03:22
Lists all the folder size.
function listfiles {
for f in *; do
echo $(du -hs $f)
done
}

Note

Apple will reject apps that are using private url schemes (Ugh, Apple....) if they are pretty much obvius. Some apps are rejected and others are not, so, be aware of this issue before implementing any of those URL's in your app as a feature.

[UPDATE 4] iOS 10 update: apparently settings now can be reached using App-Pref instead of prefs

[UPDATE 3: For now you just can use url schemes to open your apps's settings with Swift 3.0 (Xcode 8). I'll keep you informed when OS preferences can be reached]

[UPDATE 2:The openURL() method of UIApplication is now deprecated. You should use application(_:open:options:) instead]

[UPDATE : Not yet tested in iOS 10. It will fail because of policies changes in URL scheme handling.]

extension UIView {
var captureView: UIImage {
get {
let size = self.bounds.size
UIGraphicsBeginImageContextWithOptions(size, false, 0);
self.drawHierarchy(in: self.bounds, afterScreenUpdates: true)
let image:UIImage = UIGraphicsGetImageFromCurrentImageContext()!;
UIGraphicsEndImageContext();
return image