Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
peterhellberg / api.go
Last active January 18, 2019 01:58
A tiny example API written in Go using Martini and Redigo
package main
import (
"flag"
"fmt"
"net/http"
"github.com/codegangsta/martini"
"github.com/garyburd/redigo/redis"
"github.com/martini-contrib/render"
@matheusoliveira
matheusoliveira / json_manipulator.sql
Last active January 13, 2025 00:56
Simple PostgreSQL functions to manipulate json objects. (Note: performance is not a concern for those functions)
CREATE OR REPLACE FUNCTION public.json_append(data json, insert_data json)
RETURNS json
IMMUTABLE
LANGUAGE sql
AS $$
SELECT ('{'||string_agg(to_json(key)||':'||value, ',')||'}')::json
FROM (
SELECT * FROM json_each(data)
UNION ALL
SELECT * FROM json_each(insert_data)
@hoegaarden
hoegaarden / index.js
Last active November 19, 2015 14:17
node-postgres initial query for clients
var pg = require('pg');
var pgStart = require('./pg-start');
function printRes(type, err, res) {
console.log(
'from', type, 'we got', err ? 'an ERROR' : 'a response: ',
err || res
)
}
@momer
momer / grpc_with_reconnect.go
Last active February 7, 2024 00:44
A pattern I created to maintain connections to an RPC server in Go. Since net/rpc does not provide any methods for automatically reconnecting to an RPC server, I needed a work-around. Additionally, rpc.Client does not export any state variables (rpc.Client.shutdown and rpc.Client.closing) nor does it export the Client's Mutex. So, we wrap the rp…
package main
import (
"myapp/webserver/app/common"
"github.com/golang/glog"
"github.com/gorilla/mux"
"encoding/json"
"strconv"
"flag"
"fmt"
@apeckham
apeckham / bq.sql
Last active July 1, 2021 15:21
bigquery javascript UDF to extract URL components and query parameters with URI.js
-- gsutil mb -p project-id gs://my-udf-bukkit/
-- wget https://cdn.jsdelivr.net/uri.js/1.18.10/URI.min.js
-- gsutil cp URI.min.js gs://my-udf-bukkit/
-- open https://medialize.github.io/URI.js/docs.html
CREATE TEMP FUNCTION myFunc(b STRING)
RETURNS STRING
LANGUAGE js AS
"""
return URI(b).query(true)['my-param'];