Skip to content

Instantly share code, notes, and snippets.

View cfsghost's full-sized avatar

Fred Chien(錢逢祥) cfsghost

View GitHub Profile
@cfsghost
cfsghost / source_merge_updates.js
Last active September 20, 2024 09:43
Column updates
function mergeUpdates(data) {
let output = {};
Object.entries(data).forEach(function(entry) {
let key = entry[0];
let value = entry[1];
if (key.startsWith(fieldName + '.')) {
let column = key.split('.')[1];
output[column] = value;
return
@cfsghost
cfsghost / reconnect-nats-streaming.go
Created June 16, 2020 17:36
Reconnect to NATS Streaming
func Connect() error {
var nc *nats.Conn
// Connect to NATS
nc, err := nats.Connect(eb.host,
nats.PingInterval(10*time.Second),
nats.MaxPingsOutstanding(3),
nats.MaxReconnects(-1),
@cfsghost
cfsghost / router.js
Last active September 26, 2017 23:28
Groa.js : Koa-like gRPC Middleware Framework - router.js
const Groa = require('groa');
const Router = require('groa-router');
const app = new Groa();
const router = new Router();
// Add proto file
app.addProto(__dirname + '/router.proto');
// package: example.foo
@cfsghost
cfsghost / router.proto
Last active September 26, 2017 23:08
Groa.js : Koa-like gRPC Middleware Framework - router.proto
syntax = "proto3";
package example.foo;
service Example1 {
rpc Ping(Echo) returns (Echo) {}
rpc Echo(Echo) returns (Echo) {}
rpc Hello(Hello) returns (Hello) {}
}
@cfsghost
cfsghost / example1-client.js
Last active September 26, 2017 22:51
Groa.js : Koa-like gRPC Middleware Framework - example1-client.js
const { Client } = require('groa');
const main = async () => {
let client = new Client('0.0.0.0', 50051);
// Load definition file
await client.loadProto(__dirname + '/example1.proto');
// Get specific service
@cfsghost
cfsghost / example1.js
Created September 26, 2017 22:31
Groa.js : Koa-like gRPC Middleware Framework - example1.js
const Groa = require('groa');
const app = new Groa();
// Add proto file
app.addProto(__dirname + '/example1.proto');
// Add middleware
app.use(async (ctx, next) => {
@cfsghost
cfsghost / example1.proto
Created September 26, 2017 22:18
Groa.js : Koa-like gRPC Middleware Framework - proto
syntax = "proto3";
package example.foo;
service Example1 {
rpc Ping(Ping) returns (Pong) {}
}
message Ping {
string content = 1;
@cfsghost
cfsghost / Installation.sh
Last active September 26, 2017 22:18
Groa.js : Koa-like gRPC Middleware Framework Installation
npm install groa --save
@cfsghost
cfsghost / middleware
Last active March 14, 2017 11:20
Benchmark for Node.js web frameworks
$ make test -f Makefile2
> [email protected] postinstall /Users/fred/projects/koa-benchmark/koa2
> babel koa2-async.js --out-file koa2-async-compile.js
prepare complete
benchmark koa-1
1 middleware
6295.24
@cfsghost
cfsghost / light-sensor.ino
Created October 13, 2016 14:41
light-sensor.ino
/*
* 此範例
* A2接Light Sensor v1.1
* D4接Buzzer v1.2
* analogPin=撈取A2 Sensor值
* 計算方式 5v/1024每個刻度4.9mv左右
* 實際量測過這顆sensor 輸出最高數值約為2.08v左右
* 依照這個基準點算起來2.08v/4.9mv所以就會得到425左右的值輸入
* 此範例程式將撈取到的值供Delay使用
* 所以當沒有光線的時候Delay越少