Skip to content

Instantly share code, notes, and snippets.

@peteroid
peteroid / error-report.js
Created January 6, 2017 10:01 — forked from tianjianchn/error-report.js
Error report util with fabric/crashlytics in react-native
/*global __DEV__*/
import StackTrace from 'stacktrace-js';
const Fabric = require('react-native-fabric');
const { Crashlytics } = Fabric;
//call this to start capturing any no-handled errors
exports.init = function(captrueOnDebugMode){
if (__DEV__ && !captrueOnDebugMode) {
return;
@peteroid
peteroid / curl.sh
Created November 13, 2016 11:46
curl for the json show the data of the google link shortener
#!/bin/bash
curl 'https://goo.gl/api/analytics' --data 'security_token&url=http%3A%2F%2Fgoo.gl%2FBKGdcm' --compressed
@peteroid
peteroid / UDPNetworkManager.cs
Last active January 4, 2017 00:34
UDP Network Manager for connect to Arduino and receive the sensor data
using UnityEngine;
using System.Collections.Generic;
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Linq;
// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class
// 10/7/2011 by Jeff Rowberg <[email protected]>
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
//
// Changelog:
// 2013-05-08 - added multiple output formats
// - added seamless Fastwire support
// 2011-10-07 - initial release
/* ============================================
// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class
// 10/7/2011 by Jeff Rowberg <[email protected]>
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
//
// Changelog:
// 2013-05-08 - added multiple output formats
// - added seamless Fastwire support
// 2011-10-07 - initial release
/* ============================================
@peteroid
peteroid / unity-arduino-mpu6050.c
Last active October 27, 2016 04:20
Arduino side of this
...
// modify the initiator of the packet
uint8_t teapotPacket[20] = { '$', 0x02,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0,
0x00, 0x00, '\r', '\n' };
...
loop() {
...
@peteroid
peteroid / unity-arduino-mpu6050.cs
Last active December 16, 2017 12:30
Get the quaternion from arduino output string with filter
// !!! Attention !!!
void initPort (SerialPort port) {
// set this encoding to extend the ascii range
port.Encoding = System.Text.Encoding.GetEncoding(28591);
}
// Take a string and parse the quaternion and corresponding index
// return:
// quat = Quaternion.identity if packet is invalid
// index = -1 if packet is invalid
var getTenPinBowlingScore = function (result) {
// construct the array from string
var resultArr = result.split(',').map(s => {
return parseInt(s)
})
var calculatedResult = resultArr.reduce((preVal, curVal, curIdx, arr) => {
// calcualte any extra score
@peteroid
peteroid / SparkBench.scala
Created August 3, 2016 23:42
A simple scala object for benchmarking Spark app
import java.text.SimpleDateFormat
import java.util.Date
import scala.collection._
import sys.process._
import java.io._
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
import org.apache.spark.scheduler._
@peteroid
peteroid / vertical-align.css
Created August 3, 2016 17:20
An example implementing the vertical alignment
/* absolution position + transform approach */
.parent {
height: 100vh;
position: relative;
.children {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);