Skip to content

Instantly share code, notes, and snippets.

View xta's full-sized avatar

Rex Feng xta

View GitHub Profile
import UIKit
// Returns a list of points on the convex hull in counter-clockwise order.
// Note: the last point in the returned list is the same as the first one.
//
// https://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain
//
func closedConvexHull(points_ : [CGPoint]) -> [CGPoint] {
// 2D cross product of OA and OB vectors, i.e. z-component of their 3D cross product.
import Foundation
import SceneKit
class Icosahedron : Geometry {
// The golden ratio
static let t = (1.0 + sqrt(5.0)) / 2.0;
// These vertices represent three orthogonal rectangles
// The corners of which define the 12 vertices of an icosahedron
// We get the normalized vector so that our points are on the unit sphere
@xta
xta / detect-private-browsing.js
Created April 3, 2018 20:16 — forked from cou929/detect-private-browsing.js
Detect private browsing mode (InPrivate Browsing or Incognito).
function retry(isDone, next) {
var current_trial = 0, max_retry = 50, interval = 10, is_timeout = false;
var id = window.setInterval(
function() {
if (isDone()) {
window.clearInterval(id);
next(is_timeout);
}
if (current_trial++ > max_retry) {
window.clearInterval(id);
//
// SimpleScrollingStack.swift
// A super-simple demo of a scrolling UIStackView in iOS 9
//
// Created by Paul Hudson on 10/06/2015.
// Learn Swift at www.hackingwithswift.com
// @twostraws
//
import UIKit
@xta
xta / sed cheatsheet
Created November 22, 2017 18:01 — forked from un33k/sed cheatsheet
magic of sed -- find and replace "text" in a string or a file
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
public struct Credentials {
public init(key: String, secret: String) {
self.key = key
self.secret = secret
}
public let key: String
public let secret: String
}
@xta
xta / SCSS.md
Created July 13, 2017 19:54 — forked from jareware/SCSS.md
Advanced SCSS, or, 16 cool things you may not have known your stylesheets could do

⇐ back to the gist-blog at jrw.fi

Advanced SCSS

Or, 16 cool things you may not have known your stylesheets could do. I'd rather have kept it to a nice round number like 10, but they just kept coming. Sorry.

I've been using SCSS/SASS for most of my styling work since 2009, and I'm a huge fan of Compass (by the great @chriseppstein). It really helped many of us through the darkest cross-browser crap. Even though browsers are increasingly playing nice with CSS, another problem has become very topical: managing the complexity in stylesheets as our in-browser apps get larger and larger. SCSS is an indispensable tool for dealing with this.

This isn't an introduction to the language by a long shot; many things probably won't make sense unless you have some SCSS under your belt already. That said, if you're not yet comfy with the basics, check out the aweso

@xta
xta / ios_locale_identifiers_to_country_codes_feb2017.csv
Created February 8, 2017 08:21
Swift v3.0.2 - Country Codes
localeIdentifier Country Code
eu
hr_BA BA
en_CM CM
en_BI BI
rw_RW RW
ast
en_SZ SZ
he_IL IL
ar
localeIdentifier Description
eu Basque
hr_BA Croatian (Bosnia & Herzegovina)
en_CM English (Cameroon)
en_BI English (Burundi)
rw_RW Kinyarwanda (Rwanda)
ast Asturian
en_SZ English (Swaziland)
he_IL Hebrew (Israel)
ar Arabic
eu Basque
hr_BA Croatian (Bosnia & Herzegovina)
en_CM English (Cameroon)
en_BI English (Burundi)
rw_RW Kinyarwanda (Rwanda)
ast Asturian
en_SZ English (Swaziland)
he_IL Hebrew (Israel)
ar Arabic