Instantly share code, notes, and snippets.

View api-client.sh
#!/bin/bash
WAIT=10
NEXT=0
SESSION=`curl -s https://~/start | jq -r .session_id`
LAST=0
gpspipe -w | jq --unbuffered -c '. | if .class == "TPV" then {lat,lon,time} else empty end' | while read -r f; do
CURRENT=`date +%s`
TARGET=$(( LAST + WAIT ))
View apigateway-template.json
{
"TableName": "データ蓄積テーブル",
"Item": {
"session_id": {
"S": "$input.path('$.session_id')"
},
"time": {
"S": "$input.path('$.time')"
},
"lat": {
View create-session-script.js
const AWS = require('aws-sdk');
AWS.config.update({
'region': 'ap-northeast-1'
});
const dynamo = new AWS.DynamoDB.DocumentClient();
exports.handler = (event, context, callback) => {
const l = 8;
const c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
View iam-role-trust.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"apigateway.amazonaws.com",
"lambda.amazonaws.com"
]
View iam-role-policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmtxxxxxxxx",
"Effect": "Allow",
"Action": [
"dynamodb:PutItem",
"dynamodb:Scan"
],
View mysqlinapp.php
<?php
define('ENV_STR', 'MYSQLCONNSTR_localdb');
$return = array('result' => false);
if (isset($_SERVER[ENV_STR])) {
$connectStr = $_SERVER[ENV_STR];
$return['connection'] = array(
'host' => preg_replace("/^.*Data Source=(.+?);.*$/", "\\1", $connectStr),
View cw2redis.go
package main
import (
"encoding/json"
"github.com/garyburd/redigo/redis"
"io/ioutil"
"log"
"net/http"
)
View testApp.cpp
// add [ int lineLine ] in testApp.h
void testApp::draw(){
srand((unsigned int)time(NULL));
int red = rand() % 124 + 124;
int green = rand() % 124 + 124;
int blue = rand() % 124 + 124;
ofSetLineWidth(10);
View testApp.cpp
// add [ int lineLine ] in testApp.h
void testApp::draw(){
if(lineLine == RECT_SIZE) {
lineLine = 0;
}
ofSetColor(255, 255, 255, 255-lineLine);
ofRect(0, 0+lineLine, RECT_SIZE, 20);
View backup.sh
#!/bin/bash
_dir='/path/to/target/'
_target=`date +"%Y%m"`
if test ! -d $_dir$_target
then
mkdir $_dir$_target
_last=`date -d '1 month ago' +"%Y%m"`