Skip to content

Instantly share code, notes, and snippets.

View Natata's full-sized avatar
🙌

Jonathan Natata

🙌
View GitHub Profile
@Natata
Natata / paddingLabel.swift
Last active September 22, 2017 20:52
UILabel wrapper can set padding at utility panel.
// source: http://www.cnblogs.com/over140/p/4837652.html
class UILabelPadding : UILabel {
private var padding = UIEdgeInsets.zero
@IBInspectable
var paddingLeft: CGFloat {
get { return padding.left }
set { padding.left = newValue }
@Natata
Natata / Downloader.swift
Last active September 22, 2017 20:51
Alamofire-based downloader used to download file
//
// Downloader.swift
//
// Created by Natata on 2017/9/15.
// Copyright © 2017 Natata. All rights reserved.
//
import Foundation
import Alamofire
func recoverFactory(f func()) func() {
rf := func() {
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered in f", r, "ker")
}
}()
f()
}
@Natata
Natata / CMDeviceMotion.swift
Last active August 17, 2017 06:23 — forked from travisnewby/CMDeviceMotion.swift
Determine the direction of "gaze" of the device in any orientation
extension CMDeviceMotion {
func gaze(atOrientation orientation: UIInterfaceOrientation) -> SCNVector4 {
let attitude = self.attitude.quaternion
let aq = GLKQuaternionMake(Float(attitude.x), Float(attitude.y), Float(attitude.z), Float(attitude.w))
let pi2 = Double.pi/2
let final: SCNVector4
switch UIApplication.shared.statusBarOrientation {
@Natata
Natata / twitcasting_record.sh
Created March 1, 2017 13:02
record twitcasting streaming
#!/bin/bash
# coding: utf-8
# twitcasting_record.sh by Natata
# modified from showroom.sh by fcicq
# NOTE: need to install jq and livestreamer first
(jq --version 1>/dev/null 2>&1) || (echo 'install jq first'; exit)
(livestreamer --version 1>/dev/null 2>&1) || (echo 'install livestreamer first (run pip/pip3 install livestreamer)'; exit)
if [ -n "$1" ]; then
@Natata
Natata / robot.js
Created December 7, 2012 14:39
dsasadsa
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);