Skip to content

Instantly share code, notes, and snippets.

@boundsj
boundsj / ViewController.swift
Last active May 7, 2020 04:53 — forked from hhartz/ViewController.swift
Mapbox offline pack resume bug
// Source code for mapbox offline pack resume bug
//
// Adapted from https://www.mapbox.com/ios-sdk/examples/offline-pack/.
// To download, use the shake gesture (ctrl-cmd-Z), and kill the app. When the app is resumed
// it will find a partial pack and resume it. Notice how the network and disk activity shows
// that a download is indeed ocurring, while there are no notifications posted on progress.
import UIKit
import Mapbox
@boundsj
boundsj / ios_heatmap_example.md
Created February 22, 2017 15:24
iOS Heatmap Example using runtime styling and clustering
    
    // Ported from https://www.mapbox.com/mapbox-gl-js/example/heatmap/
  
    func mapViewDidFinishLoadingMap(_ mapView: MGLMapView) {
        let source = MGLSource(identifier: "source")

        let symbolLayer = MGLSymbolStyleLayer(identifier: "place-city-sm", source: source)
        let url = URL(string: "https://www.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson")!
        let options = [MGLShapeSourceOption.clustered: NSNumber(booleanLiteral: true),
@boundsj
boundsj / example_swift_geojson_clustering_filters.md
Created September 26, 2016 22:46
Swift GeoJSON + Clustering + Filters Example
    func mapViewDidFinishLoadingMap(_ mapView: MGLMapView) {
        let source = MGLSource(sourceIdentifier: "source")!
        
        let symbolLayer = MGLSymbolStyleLayer(layerIdentifier: "place-city-sm", source: source)
        let url = URL(string: "https://www.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson")!
        let options = [MGLGeoJSONClusterOption: NSNumber(booleanLiteral: true),
                       MGLGeoJSONClusterRadiusOption: NSNumber(integerLiteral: 20),
                       MGLGeoJSONClusterMaximumZoomLevelOption: NSNumber(integerLiteral: 15)]
        let geoJSONSource = MGLGeoJSONSource(sourceIdentifier: "earthquakes", url: url, options: options)
@boundsj
boundsj / glbufferdata_crash.md
Created September 27, 2016 19:54
glBufferData crash
libc++abi.dylib: terminating with uncaught exception of type mbgl::gl::Error: glBufferData(target, pos, array, GL_STATIC_DRAW): Error GL_INVALID_OPERATION at /Users/boundsj/workspace/mbgl/src/mbgl/geometry/buffer.hpp:59
(lldb) bt
* thread #1: tid = 0x2a3a90, 0x000000010a1eddda libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x000000010a1eddda libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x000000010a225797 libsystem_pthread.dylib`pthread_kill + 90
    frame #2: 0x0000000109f67ff7 libsystem_c.dylib`abort + 129
    frame #3: 0x0000000109d3395a libc++abi.dylib`abort_message + 266
    frame #4: 0x0000000109d58ce7 libc++abi.dylib`default_terminate_handler() + 243
    frame #5: 0x000000010647f4b4 libobjc.A.dylib`_objc_terminate() + 124
@boundsj
boundsj / earthquake_clusters.md
Last active September 21, 2016 01:27
earthquake clusters
    NSURL *url = [NSURL URLWithString:@"https://www.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson"];
    MGLSource *source = [[MGLSource alloc] initWithSourceIdentifier:@"source"];
    MGLSymbolStyleLayer *symbolLayer = [[MGLSymbolStyleLayer alloc] initWithLayerIdentifier:@"place-city-sm" source:source];
    
    NSDictionary *options = @{MGLGeoJSONClusterOption: @(YES),
                              MGLGeoJSONClusterRadiusOption: @10,
                              MGLGeoJSONClusterMaximumZoomLevelOption: @15};
    
    MGLGeoJSONSource *geoJSONSource = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"earthquakes" URL:url options:options];
@boundsj
boundsj / style_vector_layer.md
Created September 7, 2016 18:08
style_vector_layer
- (void)mapViewDidFinishLoadingMap:(MGLMapView *)mapView
{
    [self.mapView setStyleURL:[MGLStyle darkStyleURLWithVersion:9]];
    
    NSURL *url = [[NSURL alloc] initWithString:@"mapbox://mapbox.mapbox-terrain-v2"];
    MGLVectorSource *vectorSource = [[MGLVectorSource alloc] initWithSourceIdentifier:@"terrain-data" URL:url];
    [self.mapView.style addSource:vectorSource];
    
    MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithLayerIdentifier:@"background"];
@boundsj
boundsj / force_touch_annotations.md
Last active August 4, 2016 16:14
Force touch annotations

Since an MGLAnnotationView is a UIView you can use familiar APIs to manipulate it. For example, on devices that support 3D touch, you can transform the view as a function of the touch force.

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
    super.touchesMoved(touches, withEvent: event)

    if let touch = touches.first {
        let normalizedForce = touch.force / touch.maximumPossibleForce * 2.5
        self.transform = CGAffineTransformMakeScale(1 + normalizedForce, 1 + normalizedForce)
    }
@boundsj
boundsj / python_env_mac.md
Last active February 6, 2016 13:07
Setting up a Python environment: Mac

Creating an Agile Python Environment: Mac

This gist assumes you are on a Mac. It also assumes that you already have Python and pip installed and that you are most likely using Python version 2.7.x. If your environment differs you may have to work a little harder to get things sorted but hopefully the gist of the gist (agile Python) will still be useful for you. If you are on a windows machine, this is probably not the gist you are looking for.

We will take the minimum amount of steps nessessary to set up a complete set of tools that are fully controllable from the command line. Use your text editor or IDE of choice for creating the spec and implementation files. Note that some IDEs (i.e. PyCharm) make some of what we cover below a lot easier (i.e. debugging) but it is probably still useful to understand what is going on behind the scenes.

We will create a simple application that pulls down Guido van Rossum's twitter feed and prints out some of his latest perls of wisdo

@boundsj
boundsj / pckit.sh
Last active December 27, 2015 10:49
Add PivotalCoreKit as a submodule
# bash -c "$(curl -fsSL https://gist.github.com/boundsj/7314358/raw/be3e7f29f6d69b067bf9696fa4ebbaab07c62c82/pckit.sh)"
EXTERNALS="Externals"
if [ ! -d $EXTERNALS ]; then
mkdir Externals
fi
git submodule add https://github.com/pivotal/PivotalCoreKit.git Externals/PivotalCoreKit
git submodule init
@boundsj
boundsj / SomeViewController.m
Created November 4, 2013 05:03
JavaScriptCore, Objective-C calln' javascripts
#import "ViewController.h"
@import JavaScriptCore;
@interface ViewController ()
@property (nonatomic, strong) JSContext *context;
@end
@implementation ViewController