Skip to content

Instantly share code, notes, and snippets.

View hossamghareeb's full-sized avatar

Hossam Ghareeb hossamghareeb

View GitHub Profile
@hossamghareeb
hossamghareeb / optionals.swift
Created April 2, 2018 15:50
Uncommon ways to handle optionals in Swift
var dic = [String: Int]()
dic["hello", default: 0] += 1
dic // ["hello": 1]
func parse(_ string: String) -> String {
switch Int(string) {
case .some(7): return "SEVEN"
case 5?: return "FIVE"
case let x? where x < 10: return "1-9"
default: return "Not valid INT"
@hossamghareeb
hossamghareeb / digitAt.swift
Created March 29, 2018 09:45
Get digit at index in Int in Swift
extension Decimal {
var intValue: Int {
return NSDecimalNumber(decimal: self).intValue
}
}
extension Int {
func digitAt(i: Int) -> Int {
let div = pow(10, i).intValue
let x = self / div
@hossamghareeb
hossamghareeb / ascii.swift
Last active January 19, 2020 14:10
ASCII value from one character String in Swift
extension String {
var ascii: Int {
guard let u = UnicodeScalar(self) else { return -1 }
return Int(u.value)
}
}
"a".ascii // 97
"A".ascii // 65
@hossamghareeb
hossamghareeb / gist:7de379d2131831cc10f1
Created February 12, 2016 05:26
Convert video to GIF in mac
Converting your screencast/screen recording to Gif is not a big deal. All you need:
1. QuickTime Player to record your screen OR video file if you already have the video that you wanna convert
2. ffmpeg installed in mac
First of all, install HomeBrew using the following command
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then install ffmpeg using the following commmand:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//.. do other setup
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
// Transition neatly from splash screen
// Very odd, on iPhone 5 you need to position the splash screen differently..