Skip to content

Instantly share code, notes, and snippets.

View gmertk's full-sized avatar

Günay Mert Karadoğan gmertk

View GitHub Profile
@gmertk
gmertk / RangeWhileMonitorPart05.swift
Created May 27, 2015 10:00
Use sets for regions in didRangeBeacons
func locationManager(manager: CLLocationManager!, didRangeBeacons beacons: [AnyObject]!, inRegion region: CLBeaconRegion!) {
var latestRegions = Set<CLBeaconRegion>()
// Create CLBeaconRegions from CLBeacons
if let beacons = beacons as? [CLBeacon] {
for beacon in beacons {
latestRegions.insert(regionFromBeacon(beacon))
}
}
@gmertk
gmertk / RangeWhileMonitorPart04.swift
Created May 26, 2015 21:48
Move ranging into didDetermineSate
func locationManager(manager: CLLocationManager!, didDetermineState state: CLRegionState, forRegion region: CLRegion!) {
if let region = region as? CLBeaconRegion {
switch state {
case .Inside:
manager.startRangingBeaconsInRegion(region)
case .Outside:
manager.stopRangingBeaconsInRegion(region)
case .Unknown:
break
}
@gmertk
gmertk / RangeWhileMonitorPart03.swift
Created May 26, 2015 21:21
Stop ranging when exiting a CLBeaconRegion
func locationManager(manager: CLLocationManager!, didExitRegion region: CLRegion!) {
if let region = region as? CLBeaconRegion {
manager.stopRangingBeaconsInRegion(region)
}
}
@gmertk
gmertk / RangeWhileMonitorPart02.swift
Created May 26, 2015 21:20
Start ranging when entering a CLBeaconRegion
func locationManager(manager: CLLocationManager!, didEnterRegion region: CLRegion!) {
if let region = region as? CLBeaconRegion {
manager.startRangingBeaconsInRegion(region)
}
}
@gmertk
gmertk / RangeWhileMonitorPart01.swift
Created May 26, 2015 21:07
When you monitor a region initialized with only UUID, didEnterRegion won't give you major and minor.
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
var manager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrolledToBottomWithBuffer(scrollView.contentOffset, scrollView.contentSize, scrollView.contentInset, scrollView.bounds)) {
[self _enqueuePage:[_quoteModelController fetchNewQuotesPageWithCount:8]];
}
}
static BOOL scrolledToBottomWithBuffer(CGPoint contentOffset, CGSize contentSize, UIEdgeInsets contentInset, CGRect bounds)
{
CGFloat buffer = CGRectGetHeight(bounds) - contentInset.top - contentInset.bottom;
@gmertk
gmertk / AppDelegate.swift
Created April 29, 2015 18:30
AppDelegate.swift
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
import Foundation
struct Constants {
struct Parse {
static let ApplicationId = "dv7TEqTCbTshbH6cuVpHiVYOZ1GqFxFhbOB64kfX"
static let ClientKey = "fsx6YsirINZHPCwXse6IlQFIzfXYuLVms4cVjcgb"
}
}

Whether you use 2 spaces or 4 spaces, there are a few simple things that can make your node.js code easier to read. We've been using them in all the hapi modules for over 4 years now to great results. This list is by no means complete but it highlights the most useful elements that will give you immediate value in reducing bugs.

Required modules

JavaScript makes it harder than most languages to know where variables are coming from. Variables assigned required modules are particularly important because they represent a singleton object shared with the entire application. There are also globals and module globals, along with function variables and arguments.

Traditionally, variables starting with an uppercase letter represent a class that must be instantiated using new. This was an important semantic in the early days of JavaScript but at this point, if you don't know Date requires new Date() you are probably very new. We have adopted Upper Camel Case variable names for all module global variables

@gmertk
gmertk / 0_reuse_code.js
Created January 16, 2014 10:23
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console