Skip to content

Instantly share code, notes, and snippets.

View edwinlab's full-sized avatar
🐢
run

Edwin edwinlab

🐢
run
View GitHub Profile
@edwinlab
edwinlab / main.go
Created December 23, 2022 13:12 — forked from yingray/main.go
Golang: aes-256-cbc examples (with iv, blockSize)
package main
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"encoding/hex"
"fmt"
)
@edwinlab
edwinlab / postgres_recovery.md
Created May 22, 2022 09:34 — forked from supix/postgres_recovery.md
Postgres error: Missing chunk 0 for toast value in pg_toast

The problem

In some cases, it is possible that PostgreSQL tables get corrupted. This can happen in case of hardware failures (e.g. hard disk drives with write-back cache enabled, RAID controllers with faulty/worn out battery backup, etc.), as clearly reported in this wiki page. Furthermore, it can happen in case of incorrect setup, as well.

One of the symptoms of such corruptions is the following message:

ERROR: missing chunk number 0 for toast value 123456 in pg_toast_45678

This almost surely indicates that a corrupted chunk is present within a table file. But there is a good way to get rid of it.

package main
import (
"fmt"
"sync"
)
func main() {
ConcurrentFunctions(func1, func2, func3, func4)
}
package query
import (
"fmt"
"strings"
)
type Builder struct {
table string
query string
@edwinlab
edwinlab / README.md
Created February 11, 2019 01:35 — forked from joyrexus/README.md
time in go

Working with time in Go is pretty straightforward.

Times

Get the current local time:

now := time.Now()                                   // 02 Apr 15 14:03

Construct a time with Date(y, m, d, h, m, s, ns, loc):

@edwinlab
edwinlab / azure_sas.go
Last active February 10, 2019 04:27
Generate Microsoft Azure Storage account shared access signature with Golang
package main
import (
"crypto/hmac"
"crypto/sha256"
"fmt"
"encoding/base64"
"strings"
)
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
)
func main() {
module Callable
extend ActiveSupport::Concern
class_methods do
def call(*args)
new(*args).call
end
end
end
# Takes a table name, and an array of hashes where keys are column names and values are values.
# Expects hashes to all contain the same keys.
def bulk_insert(table, rows)
columns = rows.first.keys
to_insert = rows.map do |d|
vals = columns.map {|k| d[k] }
ActiveRecord::Base.send(:replace_bind_variables, "(#{vals.length.times.collect {'?'}.join(',')})", vals)
end