使用 golang 寫的一些小玩意
貴金屬價格懸浮提示工具
近 2 年貴金屬波動大,受到一些投資者的追捧,像我們這些散戶玩家可能需要一款小窗口價格提醒工具。
PriceReminder 就是這樣一款工具,由本人采用 Golang 編寫,支持自定義懸浮窗位置。
金銀數據采集自新浪財經。特別注意:投資需謹慎。
link:
近 2 年貴金屬波動大,受到一些投資者的追捧,像我們這些散戶玩家可能需要一款小窗口價格提醒工具。
PriceReminder 就是這樣一款工具,由本人采用 Golang 編寫,支持自定義懸浮窗位置。
金銀數據采集自新浪財經。特別注意:投資需謹慎。
link:
see article detail 文章:
https://learnku.com/articles/53099
github source link 源碼:
https://github.com/ycrao/learning_golang/tree/main/go-path-test
RabbitMQ 提供了 6 種模式,分別是 Simple
、 Worker
(或稱 Work Queue
)、 Publish/Subscribe
、 Routing
、 Topic(s)
、RPC Request/Reply
。下面傳送門倉庫詳細講述了前 5 種,并給出代碼實現和思路(主動拉取模式屬于消費端一種模式,不在此列,一般場景下均為推模式),其中 Publish/Subscribe
、 Routing
與 Topics
三種模式可以統一歸為 Exchange
模式,只是創建時交換機的類型不一樣,分別是 fanout
、 direct
與 topic
。
傳送門:
最近在學習 vue
,遇到了父子組件數據綁定的問題。Vue
官方文檔有這樣一段話:
所有的 prop 都使得其父子 prop 之間形成了一個單向下行綁定:父級 prop 的更新會向下流動到子組件中,但是反過來則不行。這樣會防止從子組件意外改變父級組件的狀態,從而導致你的應用的數據流向難以理解。
但這并不是說父頁面就不能跟子組件雙向通訊,不過就是麻煩了一點。在 Google
了諸多之后,嘗試了網絡上一些破碎零星的代碼(什么計算屬性,偵聽器等)之后,終于找到了最佳的做法:prop.sync
。
完整代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Prop 雙向綁定的實現</title>
<script src="dist/vue.js"></script>
</head>
<body>
<div id="app">
<h1>父組件數據</h1>
<table>
<tr>
<th>姓名</th>
<th>年齡</th>
</tr>
<tr>
<td>{{ name }} <input type="text" v-model="name" /></td>
<td>{{ age }} <input type="number" v-model.number="age" /></td>
</tr>
</table>
<!--
v-bind:my-name
v-on:update:my-name="my-name = $event"
參考文檔
https://cn.vuejs.org/v2/guide/components-custom-events.html
-->
<user-table
v-bind:my-name.sync="name"
v-bind:my-age="age"
v-on:change-age="age = $event"
></user-table>
</div>
<template id="userTable">
<div>
<h2>子組件數據</h2>
<table>
<tr>
<th>姓名</th>
<th>年齡</th>
</tr>
<tr>
<td>{{ myName }} <input type="text" :value="myName" @input="updateName" /></td>
<td>{{ myAge }} <input type="number" :value="myAge" @input="updateAge" /></td>
</tr>
</table>
</div>
</template>
<style>
table, td, th {
border-collapse: collapse;
border-spacing: 0
}
table {
margin: 20px;
}
td, th {
border: 1px solid #bcbcbc;
padding: 5px 10px
}
th {
background: #42b983;
font-weight: 400;
color: #fff;
cursor: pointer
}
</style>
<script>
var UserTable = {
props: {
myName: String,
myAge: Number
},
template: '#userTable',
watch: {
myName: function (val) {
console.log('child-component watch fater-component name:' + val)
},
myAge: function (val) {
console.log('child-component watch father-component age:' + val)
}
},
methods: {
updateName (evt) {
console.log(evt)
console.log('_name value:' + this.myName)
console.log('evt.target.value:' + evt.target.value)
this.$emit('update:myName', evt.target.value)
console.log('child-component myName:' + this.myName)
},
updateAge (evt) {
console.log(evt)
console.log('_name value:' + this.myAge)
console.log('evt.target.value:' + evt.target.value)
// 自定義 change-age 事件
this.$emit('change-age', Number(evt.target.value))
console.log('child-component myAge:' + this.myAge)
}
}
}
new Vue({
el: '#app',
data: {
name: '張三',
age: 20
},
components: {
'user-table': UserTable
},
mounted() {
const vm = this
setInterval(() => { console.log('name', this.name, 'age', this.age); }, 3000);
}
})
</script>
</body>
</html>
使用 Event-Emit
方式實現的示例(請隨意在輸入框中輸入數據,觀察數據文本變化):
最近在開發過程中,發現頁面 響應在首行都會輸出一行空白,這個問題初步搜索說是 UTF-8 BOM
問題。人工一個一個文件排查是很耗時的,一“翻”谷歌之后,發現了一款檢測神奇 phptags tag tidier 。
解決辦法如下(似乎直接下載 phptags-1.2.phar
使用不行):
# 直接下載 phptags 源碼
wget http://include-once.org/p/phptags/phptags
# 追加可寫權限
chmod +x phptags
# /php/project/folder 項目文件夾目錄
php phptags --whitespace /php/project/folder
官網提供了更多的使用示例:
usage examples
phptags --whitespace *.php cleans up spaces or UTF-8 BOM issues before opening and after close tags
phptags --warn directory/ searches through a directory and just warns about whitespace issues
phptags --close --long --tokenizer *.php adds close tags, converts open tags into long form <?php and uses the more reliable --tokenizer mode (instead of --regex)
phptags --unclosed --shortall dir/ ../*.tpl includes/ converts all tags into short forms, and strips close tags of a document (it's advised to rather have whitespace issues fixed than keep using the newcomer workaround)