Skip to content

Instantly share code, notes, and snippets.

View LeKovr's full-sized avatar

Aleksei Kovrizhkin LeKovr

View GitHub Profile
@LeKovr
LeKovr / main.go
Created December 12, 2015 08:57
Go lang: "Hello, world"
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
@LeKovr
LeKovr / main.go
Last active December 12, 2015 09:08
Go lang: use Macaron, step 1
package main
// Code from http://go-macaron.com/docs/middlewares/templating
import (
"gopkg.in/macaron.v1"
"github.com/skratchdot/open-golang/open"
)
func main() {
@LeKovr
LeKovr / hello.tmpl
Created December 12, 2015 09:04
Go lang: use Macaron, step 1 template
<h1>Hello {{.Name}}</h1>
@LeKovr
LeKovr / go-install.sh
Created December 12, 2015 09:26
Go lang: install script
# Link from https://golang.org/dl/
wget https://storage.googleapis.com/golang/go1.5.2.linux-amd64.tar.gz
tar -xzf go1.5.2.linux-amd64.tar.gz
sudo mv go /usr/local/go-1.5.2
cd /usr/local
sudo ln -s go-1.5.2 go
for b in go godoc gofmt ; do ln -s /usr/local/go/bin/$b bin/$b ; done
@LeKovr
LeKovr / hookex.go
Created December 21, 2015 09:38
Hook response parsing example
package main
/*
hookex.go - Hook response parsing example
Use:
echo '{"output":"Hook start\nProcessing event (push)\nError fired by secret\n","error":"exit status 1"}' | go run hookex.go
*/
window.onerror = function (msg, url, line, col, error) {
var x = new (this.XMLHttpRequest || ActiveXObject)('MSXML2.XMLHTTP.3.0');
var req = 'msg=' + encodeURIComponent(msg) + '&url='+encodeURIComponent(url) + '&line=' + line + '&col=' +col; // + '&error=' + encodeURIComponent(error);
x.open('GET', '/blank.png?' + req, 1);
x.send();
};
@LeKovr
LeKovr / pgsql_template.sql
Created September 23, 2017 19:34
Simple plpgsql template function with variables in json hash
CREATE OR REPLACE FUNCTION template(tmpl TEXT, vars JSONB) RETURNS TEXT IMMUTABLE LANGUAGE 'plpgsql' AS
$_$
DECLARE
r RECORD;
BEGIN
FOR r IN SELECT * from jsonb_each_text(vars) LOOP
tmpl := regexp_replace(tmpl,'{{\s*' || r.key || '\s*}}', r.value);
END LOOP;
RETURN tmpl;
END;
@LeKovr
LeKovr / concat.sql
Created January 5, 2018 16:13
dbrpc sample function
/*
concat - sample function for dbrpc demo
See https://github.com/LeKovr/dbrpc
*/
CREATE OR REPLACE FUNCTION concat(
a_arg1 TEXT
, a_arg2 TEXT DEFAULT ''
) RETURNS TEXT IMMUTABLE LANGUAGE 'plpgsql' AS
$_$
BEGIN
@LeKovr
LeKovr / concat-def.md
Created January 5, 2018 20:13
dbrpc sample function docs

Sample function docs

Method

$ curl -gs http://localhost:8081/rpc/index?a_nsp=public

{
  "success": true,
  "result": [
    {
@LeKovr
LeKovr / concat-call.md
Created January 5, 2018 20:16
dbrpc sample function calls

Sample function calls

GET

$ curl -gs http://localhost:8081/rpc/concat?a_arg1=prefix&a_arg2=suffix

{
  "success": true,
  "result": [
    {
 "concat": "prefixsuffix"