Skip to content

Instantly share code, notes, and snippets.

The math is described at:
http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
…including the source code for command line utility and an online demonstration.
It is also pretty simple math:
function tile2long(x,z) { return (x/Math.pow(2,z)*360-180); }
@duzvik
duzvik / globalmaptiles.py
Created April 4, 2017 07:08 — forked from tucotuco/globalmaptiles.py
Classes to calculate Tile coordinates
#!/usr/bin/env python
###############################################################################
# $Id$
#
# Project: GDAL2Tiles, Google Summer of Code 2007 & 2008
# Global Map Tiles Classes
# Purpose: Convert a raster into TMS tiles, create KML SuperOverlay EPSG:4326,
# generate a simple HTML viewers based on Google Maps and OpenLayers
# Author: Klokan Petr Pridal, klokan at klokan dot cz
# Web: http://www.klokan.cz/projects/gdal2tiles/
@duzvik
duzvik / HTTPStatusCode.swift
Created February 7, 2017 11:36 — forked from ollieatkinson/HTTPStatusCode.swift
HTTP status codes as a Swift enum.
/// This is a list of Hypertext Transfer Protocol (HTTP) response status codes.
/// It includes codes from IETF internet standards, other IETF RFCs, other specifications, and some additional commonly used codes.
/// The first digit of the status code specifies one of five classes of response; an HTTP client must recognise these five classes at a minimum.
enum HTTPStatusCode: Int, Error {
/// The response class representation of status codes, these get grouped by their first digit.
enum ResponseType {
/// - informational: This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line.
case informational
@duzvik
duzvik / Playgrounds.swift
Created February 7, 2017 11:29 — forked from SpacyRicochet/Playgrounds.swift
Snippet of the Week; Prototyping views in Playgrounds
import UIKit
import PlaygroundSupport
//: NSLayoutConstraint convenience methods
public extension NSLayoutConstraint {
public static func pinning(attribute: NSLayoutAttribute, ofView firstView: UIView, toView secondView: UIView, multiplier: CGFloat = 1, offset: CGFloat = 0) -> NSLayoutConstraint {
return NSLayoutConstraint(item: firstView, attribute: attribute, relatedBy: .equal, toItem: secondView, attribute: attribute, multiplier: multiplier, constant: offset)
}
@duzvik
duzvik / iOSCreatePDF.swift
Created February 6, 2017 16:01 — forked from nyg/iOSCreatePDF.swift
iOS, Swift: Create a PDF file from an HTML string
// Thanks to http://www.labs.saachitech.com/2012/10/23/pdf-generation-using-uiprintpagerenderer
import UIKit
// 1. Create a print formatter
let html = "<b>Hello <i>World!</i></b>"
let fmt = UIMarkupTextPrintFormatter(markupText: html)
// 2. Assign print formatter to UIPrintPageRenderer
if let asset = firstAsset {
// 2 - Create AVMutableComposition object. This object will hold your AVMutableCompositionTrack instances.
let cmp = AVMutableComposition()
// 3 - Video track
let track = cmp.addMutableTrack(withMediaType: AVMediaTypeVideo, preferredTrackID: Int32(kCMPersistentTrackID_Invalid))
guard let sourceVideoTrack = asset.tracks(withMediaType: AVMediaTypeVideo).first else {return}
try! track.insertTimeRange(CMTimeRangeMake(kCMTimeZero, asset.duration), of: sourceVideoTrack, at: kCMTimeZero)
@duzvik
duzvik / mergegenstrings.py
Created October 18, 2016 11:22 — forked from yoichitgy/mergegenstrings.py
A script to generate .strings file for .swift, .m, .storyboard and .xib files by genstrings and ibtool commands, and merge them with existing translations.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Localize.py - Incremental localization on XCode projects
# João Moreno 2009
# http://joaomoreno.com/
# Modified by Steve Streeting 2010 http://www.stevestreeting.com
# Changes
# - Use .strings files encoded as UTF-8
#!/bin/bash
for png in `find . -name '*.png'`
do
name=`basename $png`
/Applications/Xcode.app/Contents/Developer/usr/bin/pngcrush -revert-iphone-optimizations $png RevertedImages/$name
done