Skip to content

Instantly share code, notes, and snippets.

@conorbuck
conorbuck / angle-between-points.js
Created May 5, 2012 22:51
JavaScript: Find the angle between two points
var p1 = {
x: 20,
y: 20
};
var p2 = {
x: 40,
y: 40
};
@mbinna
mbinna / podforceupdate.sh
Created December 4, 2012 09:43
Clear CocoaPods cache, re-download and re-install all pods
#!/usr/bin/env bash
rm -rf "${HOME}/Library/Caches/CocoaPods"
rm -rf "`pwd`/Pods/"
pod update
@neebz
neebz / convertToLatLongFromEastings
Last active December 16, 2015 18:59
An Objective-C method to convert British Grid Coordinates (Easting and Northings) to Longitude and Latitude. Converted from Hannah Fry's Python method: http://hannahfry.co.uk/2012/02/01/converting-british-national-grid-to-latitude-and-longitude-ii/
#include <math.h>
#include "CLLocation.h" //requires Core Location Framework
- (CLLocationCoordinate2D)convertToLatLongFromEastings:(double)E andNorthings:(double *)N {
//E, N are the British national grid coordinates - eastings and northings
double a = 6377563.396; //The Airy 180 semi-major and semi-minor axes used for OSGB36 (m)
double b = 6356256.909;
double F0 = 0.9996012717;
@matthewtole
matthewtole / httpebble-simple.c
Last active December 19, 2015 18:59
An incredibly basic Pebble app that uses httpebble.
#include "pebble_os.h"
#include "pebble_app.h"
#include "pebble_fonts.h"
#include "http.h"
/* If compiling this for iOS, set ANDROID to be false. */
#define ANDROID true
#if ANDROID
#define MY_UUID { 0x91, 0x41, 0xB6, 0x28, 0xBC, 0x89, 0x49, 0x8E, 0xB1, 0x47, 0x10, 0x34, 0xBF, 0xBE, 0x12, 0x98 }
@brysonian
brysonian / UITableViewDataSource.boilerplate.m
Created July 25, 2013 21:29
UITableViewDataSource boilerplate methods
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return self.items.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellId = @"SimpleCell";
@r3econ
r3econ / gist:9959500
Created April 3, 2014 18:02
Smooth out the CMMotionManager acceleration readings with Low Pass Filter.
- (CMAcceleration)smoothOutAcceleration:(CMAcceleration)acceleration
{
static CGFloat x0 = 0;
static CGFloat y0 = 0;
static CGFloat z0 = 0;
const NSTimeInterval dt = (1.0 / 20);
const double RC = 0.3;
const double alpha = dt / (RC + dt);
@minorbug
minorbug / timeago.swift
Created November 7, 2014 15:28
"Time ago" function for Swift (based on MatthewYork's DateTools for Objective-C)
func timeAgoSinceDate(date:NSDate, numericDates:Bool) -> String {
let calendar = NSCalendar.currentCalendar()
let unitFlags = NSCalendarUnit.CalendarUnitMinute | NSCalendarUnit.CalendarUnitHour | NSCalendarUnit.CalendarUnitDay | NSCalendarUnit.CalendarUnitWeekOfYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitSecond
let now = NSDate()
let earliest = now.earlierDate(date)
let latest = (earliest == now) ? date : now
let components:NSDateComponents = calendar.components(unitFlags, fromDate: earliest, toDate: latest, options: nil)
if (components.year >= 2) {
return "\(components.year) years ago"
@flovilmart
flovilmart / Example.swift
Created February 17, 2016 12:46
Authenticate with custom OAuth example
import Parse
import Bolts
class AuthDelegate:NSObject, PFUserAuthenticationDelegate {
func restoreAuthenticationWithAuthData(authData: [String : String]?) -> Bool {
return true
}
}
let configuration = ParseClientConfiguration { (configuration) -> Void in
@bishalg
bishalg / UIView+Extension.swift
Created May 5, 2016 03:27
Swift UIView Extension for Inspectable CornerRadius, BorderWidth and BoarderColors etc
//
// UIView+Extension.swift
//
// Created by Bishal Ghimire on 4/30/16.
// Copyright © 2016 Bishal Ghimire. All rights reserved.
//
import UIKit
//
@arnaudlamy
arnaudlamy / timeago.swift
Last active July 17, 2019 09:13 — forked from jacks205/timeago.swift
"Time ago" function for Swift (based on MatthewYork's DateTools for Objective-C) *Swift 2
func timeAgoSinceDate(date:NSDate, numericDates:Bool) -> String {
let calendar = NSCalendar.currentCalendar()
let now = NSDate()
let earliest = now.earlierDate(date)
let latest = (earliest == now) ? date : now
let components:NSDateComponents = calendar.components([NSCalendarUnit.Minute , NSCalendarUnit.Hour , NSCalendarUnit.Day , NSCalendarUnit.WeekOfYear , NSCalendarUnit.Month , NSCalendarUnit.Year , NSCalendarUnit.Second], fromDate: earliest, toDate: latest, options: NSCalendarOptions())
if (components.year >= 2) {
return String.localizedStringWithFormat(NSLocalizedString("%d years ago", comment: ""), components.year)
} else if (components.year >= 1){