Skip to content

Instantly share code, notes, and snippets.

View Natata's full-sized avatar
🙌

Jonathan Natata

🙌
View GitHub Profile
@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);
@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 / 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 {
func recoverFactory(f func()) func() {
rf := func() {
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered in f", r, "ker")
}
}()
f()
}
@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
@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 / Dockerfile
Created April 7, 2018 07:06
Dockerfile example for run cron job on ubuntu
FROM ubuntu:16.04
MAINTAINER natataworld@love.com
ARG USER=docker_user
RUN apt-get update && apt-get -y install cron sudo
# create a normal user
RUN adduser --disabled-password --gecos '' $USER
RUN adduser $USER sudo
@Natata
Natata / createOrOpenFile.go
Last active April 24, 2018 01:49
function for create or open a file
func createOrOpenFile(dir, fn string) (*os.File, error) {
if _, err := os.Stat(dir); os.IsNotExist(err) {
err := os.Mkdir(dir, 0700)
if err != nil {
log.Infof("mkdir %v fail", dir)
return nil, err
}
}
fallPath := filepath.Join(dir, fn)
@Natata
Natata / http_server.go
Created May 16, 2018 15:46
simple http server, just print request path and echo post payload
package main
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
)
func sayHello(w http.ResponseWriter, r *http.Request) {
#!/bin/sh
# usage:
# ./go_installer_mac.sh [go version]
#
# example install go 1.10.2:
# ./go_installer_mac.sh 1.10.2
set -uex