2021年3月17日水曜日
拙作のRestfulサーバ(Saraswatiと命名)
Base64再び
Base64というのは、文字列とバイナリの置き換えなのだけど、
文字列もバイナリも、長さ固定だと使いにくい
文字列ならstd::string
バイナリなら、std::vector<BYTE>を使えばいい
それで探してみたら以下のようなものを見つけた。
===base64.h===
#pragma once #include===base64.cpp===#include typedef unsigned char BYTE; std::string base64_encode(BYTE const* buf, unsigned int bufLen); std::vector base64_decode(std::string const&);
#include "base64.h" #includestatic const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; static inline bool is_base64(BYTE c) { return (isalnum(c) || (c == '+') || (c == '/')); } std::string base64_encode(BYTE const* buf, unsigned int bufLen) { std::string ret; int i = 0; int j = 0; BYTE char_array_3[3]; BYTE char_array_4[4]; while (bufLen--) { char_array_3[i++] = *(buf++); if (i == 3) { char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); char_array_4[3] = char_array_3[2] & 0x3f; for(i = 0; (i <4 0xfc="" 3="" base64_chars="" char_array_3="" char_array_4="" for="" i="" if="" j="" ret="">> 2; char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); char_array_4[3] = char_array_3[2] & 0x3f; for (j = 0; (j < i + 1); j++) ret += base64_chars[char_array_4[j]]; while((i++ < 3)) ret += '='; } return ret; } std::vector base64_decode(std::string const& encoded_string) { int in_len = encoded_string.size(); int i = 0; int j = 0; int in_ = 0; BYTE char_array_4[4], char_array_3[3]; std::vector 4>ret; while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) { char_array_4[i++] = encoded_string[in_]; in_++; if (i ==4) { for (i = 0; i <4 0x30="" 2="" base64_chars.find="" char_array_3="" char_array_4="" i="">> 4); char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; for (i = 0; (i < 3); i++) ret.push_back(char_array_3[i]); i = 0; } } if (i) { for (j = i; j <4 0="" 0x30="" 2="" base64_chars.find="" char_array_3="" char_array_4="" for="" j="">> 4); char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; for (j = 0; (j < i - 1); j++) ret.push_back(char_array_3[j]); } return ret; } 4>4>
使い方
===test.cpp===
#include#include "base64.h" int main(void) { std::string str = "abcde"; std::string out = base64_encode( (BYTE *)str.c_str(),str.length()); printf("%s\n",out.c_str()); std::vector buff = base64_decode(out); printf("%s\n",(char*)buff.data()); }
2021年2月25日木曜日
SednaのXQueryバージョンがちょっと古い・・・まぁ問題ないんだけど
golangで作ったRESTfulサーバにアクセスし、結果をJSONで戻してみた。
takahiro@takahiro-Virtual-Machine:~/gorest/src$ curl -i localhost:5000/foodstuff?foodname="りんご"
HTTP/1.1 200 OK
Content-Tye: application/json
Date: Thu, 25 Feb 2021 10:47:59 GMT
Content-Length: 769
Content-Type: text/plain; charset=utf-8
{"food": [{"food_id": "7148", "foodname": "りんご 皮なし 生"}, {"food_id": "7176", "foodname": "りんご 皮つき 生"}, {"foodname": "りんご 皮つき 焼き", "food_id": "7180"}, {"food_id": "7149", "foodname": "りんご 果実飲料 ストレートジュース"}, {"food_id": "7150", "foodname": "りんご 果実飲料 濃縮還元ジュース"}, {"food_id": "7151", "foodname": "りんご 果実飲料 50%果汁入り飲料"}, {"food_id": "7152", "foodname": "りんご 果実飲料 30%果汁入り飲料"}, {"food_id": "7153", "foodname": "りんご 缶詰"}, {"food_id": "7154", "foodname": "りんご ジャム"}, {"food_id": "17018", "foodname": "<調味料類> (食酢類) 果実酢 りんご酢"}]}
実はSedna XML DatabaseのSerialization機能を使ってJSONを戻そうとしたのだけど、Sedna の XQuryのバージョンが1.0らしく、3.0以降の機能が使えない、、、
つまり、SerializationでJSONとか指定できない、、、
仕方ないので、一度 Sedna から受け取ったXMLをgolangでJSONに変換し、ヘッダにapplication/jsonを設定して戻すこととした。
動きは上記の通り、
Curlでリクエストを投げ、結果がJSONでちゃんと戻っている。
今回はこれで事足りるんだけど、いずれ、何でもできるように SednaのXQueryを3.1などに対応させないとダメかもしれない。
Go でRestAPI (DBはSedna XML Database)
2021年2月7日日曜日
Sedba XML Database 再び
2020年5月25日月曜日
NTC thermistor Setting for Duet
2020年4月30日木曜日
Setting Permissions for Updating OwnCloud
https://doc.owncloud.org/server/10.4/admin_manual/maintenance/update.html#setting-permissions-for-updating
But OwnCloud recommend Strong permissions after update.
https://doc.owncloud.org/server/10.4/admin_manual/installation/installation_wizard.html#setting-strong-directory-permissions
This Script prevent upgrading OwnCloud.
2020年4月17日金曜日
Use XSL as Model of MVC
I confirmed its result by using this link
https://www.freeformatter.com/xsl-transformer.html#ad-output
XSL having basic function and selection method of XPath.
It is possible to build Logic of Translation from GUI values to SQL.
Followings are the example.
XML
<Models>
<model_1>
<table>TBL_SAMPLE</table>
<param_1>101</param_1>
<param_2>102</param_2>
</model_1>
</Models>
XSL
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="text" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:template match="//model_1">
SELECT *
FROM <xsl:value-of select="table" />
WHERE p1 = <xsl:value-of select="param_1" />
AND p2 = '<xsl:value-of select="param_2" />'
</xsl:template>
</xsl:transform>
Result
SELECT * FROM TBL_SAMPLE WHERE p1 = 101 AND p2 = '102'
2020年4月6日月曜日
Duet Maestro Firmware 2.0 to 3.0 settings changes and Precision Piezo Orion settings
2.0
M574 X2 Y2 Z2 S1 ; set active high endstops
3.0
; Endstops
;M574 X2 Y2 Z2 S1 ; set active high endstops
M574 X2 S1 P"xstop" ; X min active high endstop switch
M574 Y2 S1 P"ystop" ; Y min active high endstop switch
M574 Z2 S1 P"zstop" ; Z min active high endstop switch
; Z-Probe
2.0
M558 P5 I1 H5 R0.4 F300 X0 Y0 Z0 T10000 ; set Z probe type to switch and the dive height + speeds
3.0
M558 P5 I1 H5 R0.4 F300 X0 Y0 Z0 T10000 C"^zprobe.in" ; Piezo connected to Z probe IN pin, free up MOD pin
G31 X0 Y0 Z-0.1 P100 ; set Z probe trigger value, offset and trigger height
M557 R140 S20 ; define mesh grid
; Heaters
2.0
; Heaters
M305 P0 T100000 B4138 R2200 ; set thermistor + ADC parameters for heater 0
M143 H0 S120 ; set temperature limit for heater 0 to 120C
M305 P1 T100000 B4138 R2200 ; set thermistor + ADC parameters for heater 1
M143 H1 S280 ; set temperature limit for heater 1 to 280C
M308 S1 P"e0_temp" Y"thermistor" T100000 B3950 C7.06e-8 ; define E0 temperature sensor
M950 H0 C"bed_heat" T0 ; heater 0 uses the bed_heat pin, sensor 0
M950 H1 C"e0_heat" T1 ; heater 1 uses the e0_heat pin and sensor 1
2020年2月3日月曜日
VirtualBox not launches VM
<Machine uuid="{xxxxxxxxxx-xxxx-xxxx-xxxxxxxx}" name="Windows7" OSType="Windows7_64" stateFile="{xxxxxxxxxx-xxxx-xxxx-xxxxxxxx}.sav" currentSnapshot="{xxxxxxxxxx-xxxx-xxxx-xxxxxxxx}" snapshotFolder="Snapshots" lastStateChange="2020-02-01T11:11:111">
and remove red part.
2019年9月25日水曜日
reinterprit_cast
-
どうも書かなくてはならないネタが出来てしまった。 マルチスレッドには欠かせないSleep(0)についてだ。 自分はSleep(0)を多用していた。 MSDNの記述 によると 「中断時間として 0ms を指定してこの関数を呼び出すと、現在のスレッドは自らに割り当てられている...
-
https://social.msdn.microsoft.com/Forums/vstudio/en-US/f0502813-9c4f-4b45-bab8-91f98971e407/popup-popupstaysopen-togglebutton-and-data-bindi...



