Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<body>
<p>Click the button to get your coordinates.</p>
<button id ='getCoordinates'>Try It</button>
<p id='coordinates'></p>
@junqueira
junqueira / gist:2c5a6f8d10724e272ac7a3db093a3e40
Created November 15, 2017 03:26 — forked from giannisp/gist:ebaca117ac9e44231421f04e7796d5ca
Upgrade PostgreSQL 9.6.5 to 10.0 using Homebrew (macOS)
After automatically updating Postgres to 10.0 via Homebrew, the pg_ctl start command didn't work.
The error was "The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0."
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.x and latest 10.0 installed, and keep 10.0 as default
brew unlink postgresql
brew install postgresql@9.6
brew unlink postgresql@9.6
brew link postgresql
@junqueira
junqueira / gist:1eed8844754f120d95fc3290f97992c1
Created November 15, 2017 03:26 — forked from giannisp/gist:ebaca117ac9e44231421f04e7796d5ca
Upgrade PostgreSQL 9.6.5 to 10.0 using Homebrew (macOS)
After automatically updating Postgres to 10.0 via Homebrew, the pg_ctl start command didn't work.
The error was "The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0."
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.x and latest 10.0 installed, and keep 10.0 as default
brew unlink postgresql
brew install postgresql@9.6
brew unlink postgresql@9.6
brew link postgresql
@junqueira
junqueira / postgres.md
Created December 28, 2017 23:06 — forked from simondobner/postgres.md
Postgres notes

Database commands in psql

Connect to psql as a non postgres user $ psql -d testdbname - when the os user exists in the db and trusted authentication is enabled.

# create database db2; - create a database
# drop database db2; - drop a database
# \c[onnect] db2 - connect to a database
# \l[ist] - list all databases
# \l+ - list all databases with extra details, including size

@junqueira
junqueira / CombineMaps.scala
Created March 26, 2019 15:06 — forked from tzachz/CombineMaps.scala
Apache Spark UserDefinedAggregateFunction combining maps
import org.apache.spark.SparkContext
import org.apache.spark.sql.expressions.{MutableAggregationBuffer, UserDefinedAggregateFunction}
import org.apache.spark.sql.types._
import org.apache.spark.sql.{Column, Row, SQLContext}
/***
* UDAF combining maps, overriding any duplicate key with "latest" value
* @param keyType DataType of Map key
* @param valueType DataType of Value key
* @param merge function to merge values of identical keys
@junqueira
junqueira / k8s-services.yaml
Created April 5, 2019 05:25 — forked from dmaze/k8s-services.yaml
Very minimal Kubernetes NodePort/LoadBalancer services
---
apiVersion: v1
kind: ConfigMap
metadata: {name: content}
data:
index.html: '<html><body><h1>Hello world</h1></body></html>'
---
apiVersion: apps/v1beta2
kind: Deployment
metadata: {name: lb}
@junqueira
junqueira / letsencrypt_2018.md
Created April 6, 2019 00:59 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SSL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SLL rating)


Virtual hosts

Let's say you want to host domains first.com and second.com.

Create folders for their files:

@junqueira
junqueira / install-docker-ubuntu.md
Created April 21, 2019 03:20 — forked from subfuzion/install-docker-ubuntu.md
Installing Docker on Ubuntu

Installing with apt-get

#!/bin/sh
# https://docs.docker.com/engine/installation/linux/ubuntu/#install-using-the-repository
sudo apt-get update && sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88 | grep docker@docker.com || exit 1
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
@junqueira
junqueira / aggregation_lookup.md
Created May 16, 2019 21:55 — forked from bertrandmartel/aggregation_lookup.md
MongoDB $lookup aggregation example

MongoDB $lookup aggregation

SO link

db.votes.aggregate([{
    $lookup: {
        from: "users",
        localField: "createdBy",
        foreignField: "_id",
@junqueira
junqueira / aggregate.js
Created May 16, 2019 21:56
Aggregate data from MongoDB with Node.js and mongoose
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
//Database connection
var uristring = 'mongodb://localhost/test';
var mongoOptions = { };
mongoose.connect(uristring, mongoOptions, function (err, res) {
if (err) {
console.log('Error when connecting to: ' + uristring + '. ' + err);