Skip to content

Instantly share code, notes, and snippets.

View MoathOthman's full-sized avatar
🎯
Focusing

Moath othman MoathOthman

🎯
Focusing
View GitHub Profile
@MoathOthman
MoathOthman / with uiview
Created January 13, 2019 12:00
for the lazy people
let view = UIView().with {$0.backgroundColor = .red}.with({$0.alpha = 0.3})
extension UIView {
func with(_ process: (UIView) -> ()) -> UIView {
process(self)
return self
}
}
@MoathOthman
MoathOthman / onviewdidload
Created March 11, 2018 15:34
On View did load (when u need to execute some code after view is loaded in uiviewcontroller)
class SuperViewController: UIViewController {
typealias VoidClosure = () -> Void
private var onViewDidLoad: [VoidClosure] = []
// public
func addOnViewdidLoad(block: @escaping VoidClosure) {
if isViewLoaded {
block()
} else {
self.onViewDidLoad.append(block)
@MoathOthman
MoathOthman / gist:d7adae3bc8d79699556ec74936175d43
Created December 4, 2016 09:44
Objectmapper Transform Dictionary to Array of dictionary of the same type
struct DictionaryToArrayTransform<T: Mappable>: TransformType {
init() {}
func transformFromJSON(_ value: Any?) -> [T]? {
guard let object = value as? [String: Any] else {
return nil
}
if let mapped = T(JSON: object) {
return [mapped]
} else {
return []
//
// DetectBlur.swift
//
// Created by Moath_Othman on 2/9/16.
//
import Foundation
//inpired by https://gist.github.com/mortenbekditlevsen/5a0ee16b73a084ba404d
extension UIDevice {
public func MO_isBlurAvailable() -> Bool {
@MoathOthman
MoathOthman / findXY
Created October 25, 2015 22:38
Find x point and y point of a UIView related to the main screen in swift
/** Find the Y point of a view related to the main screen
@pramater UIView the view to start
@return CGFloat the y point to the main screen
*/
func findOutTheYPointToTheScreen(view: UIView) -> CGFloat {
var ypointSummation: CGFloat = view.frame.origin.y
var tView = view
while let v = tView.superview {
ypointSummation += v.frame.origin.y
@MoathOthman
MoathOthman / gist:c6b0729f45edbac1a46f
Created March 22, 2015 17:08
Custom UINavigationController back button
Snippet From Apple sample Code
UIImage *backButtonBackgroundImage = [UIImage imageNamed:@"back"];
// The background should be pinned to the left and not stretch.
float margin = 12.0;
backButtonBackgroundImage = [backButtonBackgroundImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, backButtonBackgroundImage.size.width - margin, 0, 0)];
id appearance = [UIBarButtonItem appearanceWhenContainedIn:[
CustomBackButtonNavController class], nil];
@MoathOthman
MoathOthman / gist:5aca6cc64fedeaa137ce
Last active April 28, 2016 09:33
Snippet for sizing the collectionViewCell depending on the screen size
Collection View Cell Size
Snippet for sizing the collectionViewCell depending on the screen size
Given its original designed for 4.7" inches
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return CGSizeMake(<#currentWidthfor4.7inches#> *self.view.bounds.size.height/667.0, <#height#>*self.view.bounds.size.width/375.0);
}
@MoathOthman
MoathOthman / gist:b7b25f43220af52c4284
Created March 3, 2015 07:24
GET Number Of Lines of each file in a directory
find . -type f | xargs wc -l
For specific file extension
find . -name '*.m' | xargs wc -l
@MoathOthman
MoathOthman / gist:32ca1c352450e54615ed
Created March 3, 2015 07:22
GET Number Of Commits in git Repo
git rev-list HEAD --count
@MoathOthman
MoathOthman / gist:693de44543dd704a6c2e
Last active July 24, 2018 11:20
Commans to Close an application on some port on ubuntu/mac
fuser -v 8080/tcp -- give you list of pids using that port and that protocol
kill -s 15 pid -- kill //the process 15 could be 9 as well
or fuser -f ** not sure
- ps -aux |grep node
Close an application on some port on MAC
lsof | grep tcp
kill -9 ppid