Skip to content

Instantly share code, notes, and snippets.

View ma2shita's full-sized avatar

Kohei MATSUSHITA ma2shita

View GitHub Profile
@ma2shita
ma2shita / i18n_ja_jp_filter.diff
Created April 9, 2014 07:11
PHP 3.0.18-ja-3 patch for modern linux
--- i18n_ja_jp_filter.c.orig 2000-04-04 09:18:32.000000000 +0900
+++ i18n_ja_jp_filter.c 2014-04-08 18:07:28.723051000 +0900
@@ -97,5392 +97,7 @@
/* unicode support by */
#define UNDEFCHAR_JIS 0x2126
#define UNDEFCHAR_UNICODE 0x30FB
-extern const unsigned short u2jtable[];
-extern const unsigned short j2utable[];
-extern const int u2jtable_size;
-extern const int j2utable_size;
@ma2shita
ma2shita / extend-sinatra-app-skelton-db.diff
Created December 1, 2014 09:24
Extend Sinatra-App-Skelton for using DB(PostgreSQL)
diff --git Gemfile Gemfile
index a531c7c..2932ed2 100644
--- Gemfile
+++ Gemfile
@@ -4,6 +4,11 @@ gem "sinatra"
gem "grape"
gem "slim"
gem "sass"
+gem "activerecord"
+gem "sinatra-activerecord"
@ma2shita
ma2shita / sequel_db_reconnector.rb
Created December 5, 2014 01:09
Reconnect to DB module using Sequel
require "singleton"
require "sequel"
=begin
Overview:
Reconnect to DB module using Sequel
When `ping` success, `connection` return same connection.
In case of fail, reload `config/database.yml` and try new connect.
Require:
`../config/database.yml` (Deploy in `lib/` (or other dir) this file.)
@ma2shita
ma2shita / ti_sensortag_simplekey.js
Last active August 29, 2015 14:11
TI SensorTag (CC2541) SimpleKey(button) Service sample Program on node.js
/* $ npm install sensortag (require `libbluetooth-dev`) */
var SensorTag = require('sensortag');
var net = require('net');
var myUUID = process.env["TI_UUID"] || "YOUR_TI_sensor_tag_UUID";
console.log("start");
console.log("waiting for connect from " + myUUID);
SensorTag.discover(function(sensorTag) {
console.log(">> STOP: Ctrl+C or SensorTag power off");
@ma2shita
ma2shita / multiple_sensortag.js
Last active January 19, 2018 23:20
Example code of read sensor data of multiple SensorTag (CC2541DK-SENSOR, CC2650STK) at same time by using node-sensortag
/*
* Example code of read sensor data of multiple SensorTag (CC2541DK-SENSOR, CC2650STK) at same time by using node-sensortag
*
* Node.js 0.10.36 or higher (4.4.2 ready)
*
* Usage;
* $ npm install sensortag async
* $ node multiple_sensortag.js
*
* e.g.)
@ma2shita
ma2shita / patlite.rb
Last active May 7, 2016 14:38
Patlite control ruby library
# Usage;
#
# Patlite.host = "192.168.254.209"
# red = Patlite.new(:red)
# p red.state?
# #=> :off / :on
# if red.off?
# red.on
# end
@ma2shita
ma2shita / awsiot_commander.rb
Created May 7, 2016 14:38
Receive desire from AWS IoT and send command to real-device (Commander)
# Receive desire from AWS IoT and send command to real-device (Commander)
#
# POINT:
# * Listen on /update/delta
# <when Received a delta...>
# 1. Parse the delta
# 2. Execute command according to content
# 3. Erase on 'desired'
# => Should be removed "desired" ASAP after parsing delta
# Remains "desired" is cause of trouble (e.g. Out of sync)
@ma2shita
ma2shita / awsiot_reporter.rb
Created May 7, 2016 14:39
Report device status to AWS IoT (Reporter)
# Report device status to AWS IoT (Reporter)
#
# POINT:
# 1. Delete exist shadow(status) for initialize [optional]
# 2. Fetch state of real-device
# 3. Formatting for submit to AWS IoT
# 4. Report to AWS IoT
# 2~4 <endless-loop>
require "timers" # NOTE: https://github.com/celluloid/timers
@ma2shita
ma2shita / patlite_example.rb
Created May 7, 2016 14:42
Example code using patlite.rb
require "./patlite"
Patlite.host = "192.168.254.209"
patlite = []
[:red, :yellow, :green].each do |i|
patlite << Patlite.new(i)
end
loop do
a = patlite.sample
@ma2shita
ma2shita / awsiot_thing_shadow_core.html
Created May 8, 2016 11:08
AWS IoT's Thing Shadow access w/ Websocket over MQTT and Cognito
<!--
AWS IoT's Thing Shadow access w/ Websocket over MQTT and Cognito
-->
<script type="text/javascript" src="https://sdk.amazonaws.com/js/aws-sdk-2.3.9.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/sha256.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/hmac-sha256.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/ma2shita/2c5a4c29242dd5382b05ce941731fd41/raw/eb4bc16c02e7a72bbd0086e937050c258da09a20/sigv4utils.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/ma2shita/63fb1dfd07753dc1ff67fe98132c0bc0/raw/ef50f3ec3276dd1c5dd90a3003e5105045b837e2/mqttws31.js"></script>
<script>