[ GoLang ] underscore function

underscore ( _ ) avoids having to declare all the variables for the returns values.

Example

changeInfo, err := c.RemoveAll(query)

This will cause the compile error

$ go build mongo_connect.go
# command-line-arguments
./mongo_connect.go:104: changeInfo declared and not used

So, change it to underscore.

_, err := c.RemoveAll(query)

ref : https://stackoverflow.com/questions/27764421/what-is-in-a-golang-declaration

 

[ GoLang ] mongodb mgo

http://qiita.com/rubytomato@github/items/4192e2340d81c0c39ca5

  1. Install Go

download tar, extract, and set the path

sudo tar -C /usr/local -xzf go1.8.3.linux-amd64.tar.gz

put this in .bashrc

export PATH=$PATH:/usr/local/go/bin

go that comes from ubuntu golang-go package is quite old ( version 1.8.2 ).

`​go get` will comes with go version at least 1.8.3 ( ref ), so it is recommended to install from tar.

2. hello.go

package main

import "fmt"

func main() {
 fmt.Printf("hello, world\n")
}

compile

go build hello.go

run

./hello

run without compile

go run hello.go

3. Install Mgo

go get gopkg.in/mgo.v2

Trobleshooting

$ go get gopkg.in/mgo.v2
# gopkg.in/mgo.v2
../../go/src/gopkg.in/mgo.v2/auth.go:38: import /home/pong/go/pkg/linux_amd64/gopkg.in/mgo.v2/internal/scram.a: not a package file

solution

remove $HOME/go/pkg

ref : https://groups.google.com/forum/#!topic/golang-nuts/VGa3vprcNiE

 

hello_mgo.go

package main

import (
        "fmt"
	"log"
        "gopkg.in/mgo.v2"
        "gopkg.in/mgo.v2/bson"
)

type Person struct {
        Name string
        Phone string
}

func main() {
        session, err := mgo.Dial("localhost") // server1.example.com,server2.example.com
        if err != nil {
                panic(err)
        }
        defer session.Close()

        // Optional. Switch the session to a monotonic behavior.
        session.SetMode(mgo.Monotonic, true)

        c := session.DB("test").C("people")
        err = c.Insert(&Person{"Ale", "+55 53 8116 9639"},
	               &Person{"Cla", "+55 53 8402 8510"})
        if err != nil {
                log.Fatal(err)
        }

        result := Person{}
        err = c.Find(bson.M{"name": "Ale"}).One(&result)
        if err != nil {
                log.Fatal(err)
        }

        fmt.Println("Phone:", result.Phone)
}

NOTE : only package main got binary code

Example : https://blog.laisky.com/p/mgo/,

http://qiita.com/rubytomato@github/items/4192e2340d81c0c39ca5

 

Example simple web go CRUD : https://github.com/GoogleCloudPlatform/appengine-guestbook-go/blob/part4-usingdatastore/hello.go

 

ref : https://golang.org/doc/install,

http://labix.org/mgo

[ waypoint ] sticky element

Sticky element

var sticky = new Waypoint.Sticky({
  element: $('.basic-sticky-example')[0],
wrapper: false
})

wrapper

Normally, it will be wrapped with the div

<div class="sticky-wrapper" />

other options as normal waypoint

example : offset, handler

( ref : http://imakewebthings.com/waypoints/api/waypoint/ )

 

destroy sticky

sticky.destroy()

 

fix position CSS

.stuck {
position:fixed;
top:0;
}

ref : http://imakewebthings.com/waypoints/shortcuts/sticky-elements/

[ javascript ] copy with clipboard js demo

Example

<html>
<head>
<title></title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.7.1/clipboard.min.js"></script>
 <script>
 window.onload = function(){
 new Clipboard('.btn');
 }
 </script>
</head>
<body>
<!-- Target -->
<input id="foo" value="https://github.com/zenorocha/clipboard.js.git">

<!-- Trigger -->
<button class="btn" data-clipboard-target="#foo">
<img src="assets/clippy.svg" alt="Copy to clipboard">
</button>
</body>
</html>

ref : https://clipboardjs.com/

[ macOS ] partition NTFS disk on macOS using command line

1) Paragon NTFS for Mac comes with Seagate external harddisk

Screen Shot 2017-08-12 at 7.58.45 PM.png

2)

$ diskutil listFilesystems
Formattable file systems

These file system personalities can be used for erasing and partitioning.
When specifying a personality as a parameter to a verb, case is not considered.
Certain common aliases (also case-insensitive) are listed below as well.

-------------------------------------------------------------------------------
PERSONALITY                     USER VISIBLE NAME
-------------------------------------------------------------------------------
APFS                            APFS
ExFAT                           ExFAT
Free Space                      Free Space
  (or) free
MS-DOS                          MS-DOS (FAT)
MS-DOS FAT12                    MS-DOS (FAT12)
MS-DOS FAT16                    MS-DOS (FAT16)
MS-DOS FAT32                    MS-DOS (FAT32)
  (or) fat32
HFS+                            Mac OS Extended
Case-sensitive HFS+             Mac OS Extended (Case-sensitive)
  (or) hfsx
Case-sensitive Journaled HFS+   Mac OS Extended (Case-sensitive, Journaled)
  (or) jhfsx
Journaled HFS+                  Mac OS Extended (Journaled)
  (or) jhfs+
UFSD_NTFS                       Windows NT Filesystem
UFSD_NTFSCOMPR                  Windows NT Filesystem (compressed)              $ diskutil partitionDisk /dev/disk2 4 MBR UFSD_NTFS P1 250G UFSD_NTFS P2 250G UFSD_NTFS P3 250G UFSD_NTFS P4 R
Started partitioning on disk2
Unmounting disk
Creating the partition map
Waiting for partitions to activate
Formatting disk2s1 as Windows NT Filesystem with name P1
Progress                                            

Formatting Volume ...
Creating file system structures.
Creating $UpCase for use in Windows 7 and later versions
NTFS format complete.
Bytes per sector    512.                                 

Bytes per cluster   4K.
232.83 GB total disk space.
232.32 GB available.
Mounting disk
Formatting disk2s2 as Windows NT Filesystem with name P2
Progress
Formatting Volume ...
Creating file system structures.
Creating $UpCase for use in Windows 7 and later versions
NTFS format complete.                  

Bytes per sector    512.
Bytes per cluster   4K.
232.83 GB total disk space.
232.32 GB available.                                                        

Mounting disk
Formatting disk2s3 as Windows NT Filesystem with name P3
Progress

Formatting Volume ...
Creating file system structures.
Creating $UpCase for use in Windows 7 and later versions
NTFS format complete.                    

Bytes per sector    512.
Bytes per cluster   4K.
232.83 GB total disk space.
232.32 GB available.
Mounting disk
Formatting disk2s5 as Windows NT Filesystem with name P4
Progress

Formatting Volume ...
Creating file system structures.   

Creating $UpCase for use in Windows 7 and later versions
NTFS format complete.                  

Bytes per sector    512.
Bytes per cluster   4K.
233.02 GB total disk space.
232.51 GB available.                                              

Mounting disk
Finished partitioning on disk2
/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *1.0 TB     disk2
   1:               Windows_NTFS P1                      250.0 GB   disk2s1
   2:               Windows_NTFS P2                      250.0 GB   disk2s2
   3:               Windows_NTFS P3                      250.0 GB   disk2s3
   4:               Windows_NTFS P4                      250.2 GB   disk2s5

ref : https://www.reddit.com/r/osx/comments/3nv23v/cant_partition_usb_flash_drive_with_el_capitan/?st=j697uhvq&sh=98f73982