Skip to content

Instantly share code, notes, and snippets.

@morrxy
morrxy / diff.md
Last active October 11, 2017 08:12
[file compare] #diff

https://www.computerhope.com/unix/udiff.htm

-c view differences in context mode -u Unified mode (the -u option) is similar to context mode, but it doesn't display any redundant information -y Display output in two columns

diff file1 file2 
diff -c file1 file2
diff -u file1 file2

diff -y file1 file2

@morrxy
morrxy / str-to-int.go
Last active August 28, 2017 03:12
[str to int] #golang
//https://www.dotnetperls.com/parseint-go
package main
import (
"fmt"
"strconv"
)
func main() {
@morrxy
morrxy / tpl-data-choice.md
Created August 17, 2017 06:53
[template data choice] 用map还是用struct #golang

https://stackoverflow.com/questions/12484398/global-template-data

An important distinction between applying a template to a struct vs. to a map: with a map, you can make references in your template which don't exist in your map; the template will execute with no errors and the references will just be empty. If you process against a struct and make a reference to something that doesn't exist in your struct, the template execution returns an error.

@morrxy
morrxy / check-empty.md
Created August 16, 2017 11:35
[template check empty value] #golang
@morrxy
morrxy / check-map-field.go
Last active February 27, 2022 22:42
[template check field exists] #golang
//https://stackoverflow.com/a/19294004/1215930
type Data []interface{}
func (p Data) HasField(name string, value interface{}) bool {
for _, v := range p {
if m, ok := v.(map[string]interface{}); !ok {
return false
} else if _, ok := m[name]; ok && reflect.DeepEqual(m[name], value) {
return true
@morrxy
morrxy / gitlab.md
Created August 16, 2017 01:19
[gitlab cli] #gitlab

修改配置文件,重启

vim /etc/gitlab/gitlab.rb
sudo gitlab-ctl reconfigure

重启

sudo gitlab-ctl restart

@morrxy
morrxy / index.md
Created August 15, 2017 02:49
[template range index] #golang
@morrxy
morrxy / truncate.go
Created August 14, 2017 07:51
[template string truncate] #golang
#https://stackoverflow.com/questions/23466497/how-to-truncate-a-string-in-a-golang-template
"{{ printf \"%.25s\" .Content }}"
@morrxy
morrxy / tpl-str-concat.md
Created August 14, 2017 03:13
[template string concat] #golang
@morrxy
morrxy / iterate-map-in-order.md
Last active August 16, 2017 01:14
[iterate map in order] #golang