Skip to content

Instantly share code, notes, and snippets.

View wangrenjun's full-sized avatar
🎯
Focusing

wangrenjun

🎯
Focusing
View GitHub Profile
@wangrenjun
wangrenjun / gormjoin.go
Last active February 3, 2024 13:20
Example of GORM using join
package main
import (
"encoding/json"
"fmt"
"time"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
@wangrenjun
wangrenjun / main.go
Created February 5, 2021 09:17
Go loading data and coordinates from GeoJson file to PostgreSQL using Gorm.
package main
import (
"flag"
"fmt"
"io/ioutil"
"strconv"
"time"
geojson "github.com/paulmach/go.geojson"
#! /bin/bash
cat << EOD
Format/result | Command | Output
--------------------------------+-------------------------------+------------------------------
YYYY-MM-DD_hh:mm:ss | date +%F_%T | $(date +%F_%T)
YYYYMMDD_hhmmss | date +%Y%m%d_%H%M%S | $(date +%Y%m%d_%H%M%S)
YYYYMMDD_hhmmss (UTC version) | date --utc +%Y%m%d_%H%M%SZ | $(date --utc +%Y%m%d_%H%M%SZ)
YYYYMMDD_hhmmss (with local TZ) | date +%Y%m%d_%H%M%S%Z | $(date +%Y%m%d_%H%M%S%Z)
YYYYMMSShhmmss | date +%Y%m%d%H%M%S | $(date +%Y%m%d%H%M%S)
@wangrenjun
wangrenjun / goredis_pipeline.go
Created December 15, 2019 04:20
Redis pipeline example with Go
package main
import (
"fmt"
"strconv"
"github.com/go-redis/redis/v7"
)
func main() {
client := redis.NewClient(&redis.Options{
@wangrenjun
wangrenjun / gjson_foreach_example.go
Last active December 10, 2019 10:43
GJSON example of ForEach()
package main
import "github.com/tidwall/gjson"
import "fmt"
import "strings"
func main() {
jsonstring := `
{
    "status":"ok",
@wangrenjun
wangrenjun / libev-client.c
Last active October 17, 2019 04:51
another libev example
/*
* Licensed under the Apache License, Version 2.0.
*
* simple libev client example
* based on multi-process and ring buffer
* wangrj1981@gmail.com
*/
/*
gcc ./libev-client.c -c -o ./libev-client.o -I/usr/local/include/
@wangrenjun
wangrenjun / gist:9798915
Last active August 29, 2015 13:57
test
#include <stdio.h>
int main()
{
printf("hello world\n");
return 0;
}
@wangrenjun
wangrenjun / gist:9803449
Last active August 29, 2015 13:57
linux splice simple test
/*
* No license provided.
*/
#define _GNU_SOURCE
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>