Skip to content

Instantly share code, notes, and snippets.

@rrafal
rrafal / sqlx_json.go
Created March 31, 2016 00:02
Use JSON field with golang sqlx driver
package main
import (
"encoding/json"
"errors"
"database/sql/driver"
"fmt"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
"log"
@SimonSun1988
SimonSun1988 / gist:2ef7db45e46b889783647d941ec15e4d
Created April 12, 2016 03:03
解決 Ubuntu "can’t set the locale; make sure $LC_* and $LANG are correct" 的錯誤
## 安裝語系檔
`$ sudo locale-gen "en_US.UTF-8"`
## 重新設定語系檔
`$ sudo dpkg-reconfigure locales`
## 設定檔
@ebraminio
ebraminio / upload.go
Last active March 22, 2023 06:01
golang upload client and server
// curl -X POST -H "Content-Type: application/octet-stream" --data-binary '@filename' http://127.0.0.1:5050/upload
package main
import (
"fmt"
"io"
"net/http"
"os"
"time"
@kiewic
kiewic / xhubsignature.js
Created November 17, 2016 08:39
How to validate a X-Hub-Signature header when using Express.js and body-parser
var express = require('express');
var bodyParser = require('body-parser')
var crypto = require('crypto');
// Calculate the X-Hub-Signature header value.
function getSignature(buf) {
var hmac = crypto.createHmac("sha1", process.env.FB_APP_SECRET);
hmac.update(buf, "utf-8");
return "sha1=" + hmac.digest("hex");
}
@posener
posener / go-kit.md
Last active February 23, 2024 21:35
Why I Recommend to Avoid Using the go-kit Library

Why I Recommend to Avoid Using the go-kit Library

There is a trending 'microservice' library called go-kit. I've been using the go-kit library for a while now. The library provide a lot of convenience integrations that you might need in your service: with service discovery with Consul, distributed tracing with Zipkin, for example, and nice logic utilities such as round robin client side load balancing, and circuit breaking. It is also providing a way to implement communication layer, with support of RPC and REST.

@thomasdarimont
thomasdarimont / KeycloakAdminClientExample.java
Last active February 1, 2025 18:22
Using Keycloak Admin Client to create user with roles (Realm and Client level)
package demo.plain;
import org.keycloak.OAuth2Constants;
import org.keycloak.admin.client.CreatedResponseUtil;
import org.keycloak.admin.client.Keycloak;
import org.keycloak.admin.client.KeycloakBuilder;
import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.admin.client.resource.UsersResource;
import org.keycloak.representations.idm.ClientRepresentation;
@josue
josue / urlheaders.go
Created June 30, 2017 04:20
Golang - Get HTTP headers from given string, and/or the value from specific header key
package main
import (
"log"
"net/http"
"strings"
)
/*
Returns a map array of all available headers.
@branflake2267
branflake2267 / ElementalFileDndExample.java
Last active July 24, 2017 12:02
GWT 2.8.1 Elemental 2 file drop onto a browser div and then upload the file example. Example of DomGlobal, Element, DragEvent, File/Blob upload.
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import elemental2.dom.DataTransfer;
import elemental2.dom.DomGlobal;
import elemental2.dom.DragEvent;
import elemental2.dom.Element;
import elemental2.dom.Event;
import elemental2.dom.EventListener;
import elemental2.dom.File;
@ibaca
ibaca / ElementoFileDndUploadExample.java
Created July 15, 2017 07:33
GWT Elemento file drop onto a browser div and then upload the file example.
package dnd;
import static elemental2.dom.DomGlobal.document;
import static org.jboss.gwt.elemento.core.EventType.dragend;
import static org.jboss.gwt.elemento.core.EventType.dragover;
import static org.jboss.gwt.elemento.core.EventType.drop;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import elemental2.dom.DataTransfer;
@ipepe
ipepe / install-chrome-headless.sh
Last active February 10, 2025 16:14
Installing headless chrome on Ubuntu.
#!/bin/bash
# from https://chromium.woolyss.com/
# and https://gist.github.com/addyosmani/5336747
# and https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:canonical-chromium-builds/stage
sudo apt-get update
sudo apt-get install chromium-browser
chromium-browser --headless --no-sandbox http://example.org/