Skip to content

Instantly share code, notes, and snippets.

View gmertk's full-sized avatar

Günay Mert Karadoğan gmertk

View GitHub Profile

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

@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

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

import Foundation
struct Constants {
struct Parse {
static let ApplicationId = "dv7TEqTCbTshbH6cuVpHiVYOZ1GqFxFhbOB64kfX"
static let ClientKey = "fsx6YsirINZHPCwXse6IlQFIzfXYuLVms4cVjcgb"
}
}
@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 {
- (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 / 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()
@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 / 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 / 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
}