Skip to content

Instantly share code, notes, and snippets.

@mjhassan
mjhassan / Animation Fade
Created February 17, 2016 07:26 — forked from aloisdeniel/Animation Fade
Xamarin.iOS view common animations
public static void Fade (this UIView view, bool isIn, double duration = 0.3, Action onFinished = null)
{
var minAlpha = (nfloat)0.0f;
var maxAlpha = (nfloat)1.0f;
view.Alpha = isIn ? minAlpha : maxAlpha;
view.Transform = CGAffineTransform.MakeIdentity ();
UIView.Animate (duration, 0, UIViewAnimationOptions.CurveEaseInOut,
() => {
view.Alpha = isIn ? maxAlpha : minAlpha;
@mjhassan
mjhassan / makeAnimatedGif.m
Created September 1, 2016 06:34 — forked from mayoff/makeAnimatedGif.m
Example of creating an animated GIF on iOS, with no 3rd-party code required. This should also be easy to port to OS X.
#import <UIKit/UIKit.h>
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/MobileCoreServices.h>
static UIImage *frameImage(CGSize size, CGFloat radians) {
UIGraphicsBeginImageContextWithOptions(size, YES, 1); {
[[UIColor whiteColor] setFill];
UIRectFill(CGRectInfinite);
CGContextRef gc = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(gc, size.width / 2, size.height / 2);
https://spring.io/blog/2015/07/14/microservices-with-spring
http://www.adeveloperdiary.com/java/spring-boot/create-restful-webservices-using-spring-boot/
https://www.infoq.com/articles/microframeworks1-spring-boot
http://stytex.de/blog/2016/02/01/spring-cloud-security-with-oauth2/
https://bitbucket.org/ikryvorotenko/microservises-demo/src
@mjhassan
mjhassan / UIStoryboard+GenericViewController.swift
Last active October 11, 2017 18:47
Generic Swift methods to load ViewControllers from UIStoryboard
import UIKit
fileprivate enum Storyboard : String {
case main = "Main" // storyboard name
}
fileprivate extension UIStoryboard {
static func loadFromMain<T>(_ identifier: String) -> T {
return load(from: .main, identifier: identifier)
@mjhassan
mjhassan / ios_http_ssl_bypass.plist
Last active January 18, 2018 08:31
iOS http security bypass
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
@mjhassan
mjhassan / react-native-issues.md
Last active May 23, 2019 06:35
React Native issues and solution

"No bundle url present” Error

  • Open a terminal window
  • cd into YOUR_PROJECT/ios
  • Remove the build folder with rm -r build
  • Run react-native run-ios again

Alternatively, run

@mjhassan
mjhassan / SOLID for dummies in Swift.md
Last active October 29, 2025 02:04
An easy and simple explanation of SOLID principles with Swift examples

Overview

SOLID represents 5 principles of object-oriented programming: Single responsibility, Open-closed, Liskov Substitution, Interface Segregation and Dependency Inversion.

These principles is to solve the main problems of a bad architecture:

  • Fragility: Unable to change.
  • Immobility: Unable to reuse, because of tightly coupled dependencies.
  • Rigidity: Single change affects several parts of the project.

Principles

To NSCache or not to NSCache, what is the URLCache

Almost every mobile app now-a-days rely on networking, either for JSON, image or advertisement. It's rare to find an app in the AppStore that doesn't manage data. To make the app fast and responsive sometimes app developer uses caching mechanism. Though caching is not just about improving UX by making the interface fast and responsive, it's about efficiently managing data that will be used frequently. Not to say, it will effectively strip down repetitive tasks.

There are a lot of great third-party caching libraries available. Haneke, PINCache, Cache, Awesome Cache are some of the popular third-parties out there. Even image libraries, like SDWebImage, Kingfisher or Nuke provi

@mjhassan
mjhassan / APIService-NSCache.swift
Last active September 3, 2019 04:39
Simple service class template for NSCache example
class APIService: ServiceProtocol {
func get( url: URL, callback: @escaping (_ data: Data?, _ error: Error?) -> Void ) {
URLSession.shared.dataTask(with: url) { (data, _, error) in
callback(data, error)
}.resume()
}
}
@mjhassan
mjhassan / APIService-URLCache.swift
Created September 3, 2019 04:41
Simple service class template for URLCache example
class APIService: ServiceProtocol {
func get( url: URL, callback: @escaping (_ data: Data?, _ error: Error?) -> Void ) {
let request = URLRequest(url: url, cachePolicy: .returnCacheDataElseLoad, timeoutInterval: 30)
URLSession.shared.dataTask(with: request) { (data, _, error) in
callback(data, error)
}.resume()
}
}