Skip to content

Instantly share code, notes, and snippets.

@ryanguill
ryanguill / postgres-pivot.md
Last active June 29, 2022 14:08
Example of postgres pivot using jsonb_object_agg for variable columns in output. To play with this yourself in an online repl, click here: https://dbfiddle.uk/?rdbms=postgres_14&fiddle=39e115cb8afd6e62c0101286ecd08a3f
/*
================================================================================
Pivot example with variable number of columns in the output.
================================================================================

example data is straight forward, imagine a table with a customer identifier, 
an invoice date and an amount.
*/
@duhaime
duhaime / doors-ice.jpg
Last active May 1, 2024 12:52
Three.js Image Overlay
doors-ice.jpg
@miguelmota
miguelmota / insert.go
Last active May 28, 2024 15:34
Golang SQL insert row and get returning ID example
func InsertOrder(order *Order) (int, error) {
var id int
tx, err := db.Begin()
if err != nil {
return id, err
}
{
@cpu
cpu / embedjws.go
Created August 25, 2017 14:22
A small Go program using go-jose.v2 to generate an example JWS in the ACME V1 style.
package main
import (
"crypto/rand"
"crypto/rsa"
"fmt"
"os"
"gopkg.in/square/go-jose.v2"
)
@sindresorhus
sindresorhus / StatusBarButton.swift
Last active April 21, 2022 18:22
Creates a NSStatusBarButton with proxy methods for the NSStatusItem methods, so you don't have to deal with that class anymore. Most of the NSStatusItem properties are deprecated, so it's much nicer to deal with the NSStatusBarButton directly.
final class AssociatedObject<T: Any> {
subscript(index: Any) -> T? {
get {
return objc_getAssociatedObject(index, Unmanaged.passUnretained(self).toOpaque()) as! T?
} set {
objc_setAssociatedObject(index, Unmanaged.passUnretained(self).toOpaque(), newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
@alextanhongpin
alextanhongpin / time.go
Last active January 13, 2025 02:16
JavaScript timestamp to golang time.Time
package main
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
)
@myshov
myshov / function_invocation.js
Last active August 19, 2024 12:23
11 Ways to Invoke a Function
console.log(1);
(_ => console.log(2))();
eval('console.log(3);');
console.log.call(null, 4);
console.log.apply(null, [5]);
new Function('console.log(6)')();
Reflect.apply(console.log, null, [7])
Reflect.construct(function(){console.log(8)}, []);
Function.prototype.apply.call(console.log, null, [9]);
Function.prototype.call.call(console.log, null, 10);
@crizstian
crizstian / cinema.microservices.Dockerfile
Last active April 15, 2020 02:15
Example of Dockerfile for a nodejs app
# the first thing we specify in a Dockerfile is the base image.
# This is essentially bare bones alpine linux with node installed.
FROM node:7.5.0-alpine
# Creates a non-root-user.
RUN addgroup -S nupp && adduser -S -g nupp nupp
# Sets the HOME environment variable.
ENV HOME=/home/nupp
@colophonemes
colophonemes / create_triggers
Last active February 1, 2025 14:53
Postgres TRIGGER to call NOTIFY with a JSON payload
CREATE TRIGGER person_notify AFTER INSERT OR UPDATE OR DELETE ON income
FOR EACH ROW EXECUTE PROCEDURE notify_trigger(
'id',
'email',
'username'
);
CREATE TRIGGER income_notify AFTER INSERT OR UPDATE OR DELETE ON income
FOR EACH ROW EXECUTE PROCEDURE notify_trigger(
'id',
@ablwr
ablwr / moon phases
Created September 24, 2016 15:14
get the moon in your bash profile
function moonphase() {
/usr/bin/env ruby <<-EORUBY
# Convert a date to Julian.
def julian(year, month, day)
a = (14-month)/12
y = year+4800-a
m = (12*a)-3+month
return day + (153*m+2)/5 + (365*y) + y/4 - y/100 + y/400 - 32045
end