Skip to content

Instantly share code, notes, and snippets.

View eshwartm's full-sized avatar
🙂

Eshwar Ramesh eshwartm

🙂
  • Bangalore, India
View GitHub Profile
@eshwartm
eshwartm / Spinner.swift
Last active January 5, 2018 12:08
Simple infinite spinner or loader in Swift
func drawAndRotateHollowCircle() {
// draw
let circlePath = UIBezierPath(arcCenter: CGPoint(x: 50, y: 50) , radius: CGFloat(10), startAngle: CGFloat(0), endAngle: CGFloat(Double.pi * 2 * 0.75), clockwise: true)
let shapeLayer = CAShapeLayer()
shapeLayer.path = circlePath.cgPath
if let rect = shapeLayer.path?.boundingBoxOfPath {
shapeLayer.frame = rect
shapeLayer.bounds = rect
}
shapeLayer.fillColor = UIColor.clear.cgColor
func loadJson(forFilename fileName: String) -> NSDictionary? {
if let url = Bundle.main.url(forResource: fileName, withExtension: "json") {
if let data = NSData(contentsOf: url) {
do {
let dictionary = try JSONSerialization.jsonObject(with: data as Data, options: .allowFragments) as? NSDictionary
return dictionary
} catch {
print("Error!! Unable to parse \(fileName).json")
@eshwartm
eshwartm / gist:ceb05e9af2217f6554ab74aa00f5fa71
Created May 16, 2017 07:36
Check for empty object JavaScript
Object.keys(obj).length === 0 && obj.constructor === Object
@eshwartm
eshwartm / gist:6668540
Created September 23, 2013 10:00
ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor redColor];
NSLog(@"self.view.frame : %@", NSStringFromCGRect(self.view.frame));
NSLog(@"self.view.bounds : %@", NSStringFromCGRect(self.view.bounds));
}
- (void)didReceiveMemoryWarning