Skip to content

Instantly share code, notes, and snippets.

View arifsetiawan's full-sized avatar

arif setiawan arifsetiawan

View GitHub Profile
@villelahdenvuo
villelahdenvuo / jsonb_set_deep.sql
Created June 14, 2016 12:24
PostgreSQL jsonb_set is nice, but it does't create missing objects so I made this little helper.
CREATE OR REPLACE FUNCTION jsonb_set_deep(target jsonb, path text[], val jsonb)
RETURNS jsonb AS $$
DECLARE
k text;
p text[];
BEGIN
-- Create missing objects in the path.
FOREACH k IN ARRAY path LOOP
p := p || k;
IF (target #> p IS NULL) THEN
@simg
simg / Node-pg Entity Relationship Benchmark.md
Last active September 30, 2019 05:18
Benchmarking the performance of creating entity relationships with Postgres Arrays compared to "join tables"

A very common pattern in relational databases is the use of a join table to create one-to-many or many-to-many relationships between entities.

eg, something like:

CREATE TABLE table1 ( 
  id serial PRIMARY KEY 
, acolumn character varying); 

CREATE TABLE table2 (

@linxlad
linxlad / example.go
Created April 10, 2016 18:54 — forked from yanmhlv/example.go
simple DRY controller. golang github.com/labstack/echo example
package main
import (
"fmt"
"net/http"
"reflect"
"strconv"
"github.com/jinzhu/gorm"
"github.com/labstack/echo"
@threeaccents
threeaccents / openbrowser.go
Created February 25, 2016 18:55
open chrome browser with golang function
// openBrowser tries to open the URL in a browser,
// and returns whether it succeed in doing so.
func openBrowser(url string) bool {
var args []string
switch runtime.GOOS {
case "darwin":
args = []string{"open"}
case "windows":
args = []string{"cmd", "/c", "start"}
default:
@olivere
olivere / bulk_processor_example1.go
Created January 16, 2016 11:17
Example #1 of bulk processor usage
// This is an example of using elastic's BulkProcessor with Elasticsearch.
//
// See https://github.com/olivere/elastic and
// and https://github.com/olivere/elastic/wiki/BulkProcessor
// for more details.
/*
* This example illustrates a simple process that performs bulk processing
* with Elasticsearch using the BulkProcessor in elastic.
*
@julz
julz / main.go
Created November 20, 2015 12:39
containersched minicontainer
package main
import (
"fmt"
"os"
"os/exec"
"syscall"
)
func main() {
import (
log "github.com/sirupsen/logrus"
"github.com/jinzhu/gorm"
)
type GormLogger struct {}
func (*GormLogger) Print(v ...interface{}) {
if v[0] == "sql" {
log.WithFields(log.Fields{"module": "gorm", "type": "sql"}).Print(v[3])
func testImplicitAuth() {
conf := &oauth2.Config{
ClientID: "clientid",
RedirectURL: "https://server.com",
Endpoint: oauth2.Endpoint{
TokenURL: "http://test.com/auth/token",
AuthURL: "http://test.com/auth/authorize",
},
}
@dtjm
dtjm / join_test.go
Last active December 20, 2024 07:25
Benchmarking various ways of concatenating strings in Go
package join
import (
"fmt"
"strings"
"testing"
)
var (
testData = []string{"a", "b", "c", "d", "e"}
@andreas-marschke
andreas-marschke / run.sh
Created December 17, 2014 22:21
Small example LUA script for wg/wrk using a tiny JSON implementation(http://regex.info/blog/lua/json) to log test results to a file.
# Example usage with several configuration sets as in multiple connections durations and threads.
# You may go take the rest of the day off while this will run ;)
for duration in 10s 1m 10m 1h
do
for connections in 100 200 300 400 500 600
do
for thread in 1 2 3 4 5
do
wrk -d$duration -c$connections -t$thread -s wrk-script.lua http://localhost:4001/beacon/0001/demo-load-test/test/web