This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"reflect" | |
) | |
type A struct { | |
B string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func IsLittleEndian() bool { | |
var i int32 = 0x01020304 | |
u := unsafe.Pointer(&i) | |
pb := (*byte)(u) | |
b := *pb | |
return b == 0x04 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package worklog | |
import ( | |
"github.com/jmoiron/sqlx" | |
"time" | |
) | |
type CurrentWorkMessage = struct { | |
WorkIndex int `db:"work_index"` | |
WorkName string `db:"work_name"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)") | |
var matchAllCap = regexp.MustCompile("([a-z0-9])([A-Z])") | |
func toSnakeCase(str string) string { | |
snake := matchFirstCap.ReplaceAllString(str, "${1}_${2}") | |
snake = matchAllCap.ReplaceAllString(snake, "${1}_${2}") | |
return strings.ToLower(snake) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func utf8ToWindows1251(b []byte) (r []byte, err error) { | |
buf := new(bytes.Buffer) | |
for k, v := range s1251 { | |
b = bytes.Replace(b, []byte(k), []byte(v), -1) | |
} | |
wToWin1251 := transform.NewWriter(buf, charmap.Windows1251.NewEncoder()) | |
_, err = io.Copy(wToWin1251, bytes.NewReader(b)) | |
if err == nil { | |
r = buf.Bytes() | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/go-chi/chi" | |
"net/http" | |
"strings" | |
"net/rpc" | |
"log" | |
"github.com/jsonrpc2ws" | |
"sync" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An implementation of rpc.CleintCodec over gorilla/webscket. | |
// Based on github.com/powerman/rpc-codec/jsonrpc2. | |
// Use of this source code is governed by a BSD-style. | |
// license that can be found in https://github.com/powerman/rpc-codec/blob/master/LICENSE | |
package jsonrpc2ws | |
import ( | |
"encoding/json" | |
"sync" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rpc = (window as any).Rpc; | |
export function register(functionName: string, h: Handler) { | |
if (!rpc) { | |
(window as any).Rpc = { | |
[functionName]: h, | |
}; | |
return; | |
} | |
if (rpc[functionName]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ReconnectingWebSocket from 'reconnectingwebsocket'; | |
export type Handler = (params: any) => Result; | |
interface Result { | |
result?: any; | |
error?: string; | |
} | |
export function register(functionName: string, h: Handler) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select (julianday('now')); | |
select (typeof(julianday('now'))); | |
select datetime(julianday(current_timestamp)) as dt_from_jd, current_timestamp as dt; | |
select STRFTIME('%Y-%m-%d %H:%M:%f', julianday(STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW'))); |