Skip to content

Instantly share code, notes, and snippets.

View fpawel's full-sized avatar

Pavel Filimonenkov fpawel

View GitHub Profile
package main
import (
"encoding/json"
"fmt"
"reflect"
)
type A struct {
B string
func IsLittleEndian() bool {
var i int32 = 0x01020304
u := unsafe.Pointer(&i)
pb := (*byte)(u)
b := *pb
return b == 0x04
}
@fpawel
fpawel / worklog.go
Last active September 26, 2018 20:36
worklog
package worklog
import (
"github.com/jmoiron/sqlx"
"time"
)
type CurrentWorkMessage = struct {
WorkIndex int `db:"work_index"`
WorkName string `db:"work_name"`
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)
}
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 {
@fpawel
fpawel / main.go
Created June 4, 2018 07:55
rpc client app
package main
import (
"github.com/go-chi/chi"
"net/http"
"strings"
"net/rpc"
"log"
"github.com/jsonrpc2ws"
"sync"
@fpawel
fpawel / clientCodec.go
Created June 4, 2018 07:11
An implementation of rpc.CleintCodec over gorilla/webscket
// 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"
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]) {
import ReconnectingWebSocket from 'reconnectingwebsocket';
export type Handler = (params: any) => Result;
interface Result {
result?: any;
error?: string;
}
export function register(functionName: string, h: Handler) {
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')));