Skip to content

Instantly share code, notes, and snippets.

View enigmatic7earth's full-sized avatar
🏢
available in office

Prashant enigmatic7earth

🏢
available in office
View GitHub Profile
@enigmatic7earth
enigmatic7earth / index.html
Last active January 17, 2019 13:15
Beginner Dartpad
<!DOCTYPE html>
<html>
<head>
<title>A Beginner Dartpad- enigmatic7earth</title>
<script defer src="main.dart.js"></script>
</head>
<body>
<p id="Sample">
Sample paragraph.
@enigmatic7earth
enigmatic7earth / Reachability.swift
Created October 12, 2018 13:14
Reachability in Swift 4
//
// Reachability.swift
//
//
// Created by NETBIZ on 12/10/18.
// Copyright © 2018 Netbiz.in. All rights reserved.
//
import Foundation
@enigmatic7earth
enigmatic7earth / Popup.swift
Last active July 26, 2018 10:46
Create popup using storyboards
@IBAction func aboutTapped(_ sender: UIBarButtonItem) {
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "aboutPopover")
vc.modalPresentationStyle = UIModalPresentationStyle.popover
let popvc = vc.popoverPresentationController
popvc?.delegate = self
popvc?.permittedArrowDirections = UIPopoverArrowDirection.any
popvc?.barButtonItem = sender
vc.preferredContentSize = CGSize.init(width: 300, height: 300)
// the alert view
let alert = UIAlertController(title: "", message: "alert disappears after 5 seconds", preferredStyle: .alert)
self.present(alert, animated: true, completion: nil)
// change to desired number of seconds (in this case 5 seconds)
let when = DispatchTime.now() + 5
DispatchQueue.main.asyncAfter(deadline: when){
// your code with delay
alert.dismiss(animated: true, completion: nil)
}
@enigmatic7earth
enigmatic7earth / errorHighlight.swift
Last active May 23, 2018 12:30
Display a red border around the textfield and shake it to indicate an error to user.
// Just call this funtion by passing to it the **required** view to which you wish to draw a user's attention.
func shake(viewToShake: UIView){
let colorAnimation = CABasicAnimation(keyPath: "borderColor")
colorAnimation.fromValue = UIColor.red.cgColor
colorAnimation.toValue = UIColor.lightGray.cgColor
viewToShake.layer.borderColor = UIColor.lightGray.cgColor
viewToShake.layer.borderWidth = 1
@enigmatic7earth
enigmatic7earth / appStoreUpdate.m
Last active April 12, 2018 08:47
Check AppStore if an update for app is available.
-(void) checkForAppUpdate{
BOOL updateAvailable = NO;
NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString* appID = infoDictionary[@"CFBundleIdentifier"];
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", appID]];
NSData* data = [NSData dataWithContentsOfURL:url];
NSDictionary* lookup = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if ([lookup[@"resultCount"] integerValue] == 1){
NSString* appStoreVersion = lookup[@"results"][0][@"version"];