Skip to content

Instantly share code, notes, and snippets.

View slaveofcode's full-sized avatar
🎯
Debugging

Aditya Kresna Permana slaveofcode

🎯
Debugging
View GitHub Profile
@slaveofcode
slaveofcode / install.txt
Created April 18, 2018 07:50
Installing Postgis
# Get ubuntu version
>> sudo lsb_release -a
# For xenial (16.04.2 LTS)
>> sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt xenial-pgdg main" >> /etc/apt/sources.list'
>> wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
>> sudo apt-get update
@slaveofcode
slaveofcode / alter.sql
Created April 3, 2018 15:33
Alter Postgres User to Super USER
CREATE USER aditya with password 'aditya';
ALTER USER aditya with SUPERUSER CREATEDB CREATEROLE REPLICATION BYPASSRLS;
@slaveofcode
slaveofcode / restore dump docker
Created March 16, 2018 17:59 — forked from jgillman/restore.sh
pg_restore a local db dump into Docker
# Assumes the database container is named 'db'
DOCKER_DB_NAME="$(docker-compose ps -q db)"
DB_HOSTNAME=db
DB_USER=postgres
LOCAL_DUMP_PATH="path/to/local.dump"
docker-compose up -d db
docker exec -i "${DOCKER_DB_NAME}" pg_restore -C --clean --no-acl --no-owner -U "${DB_USER}" -d "${DB_HOSTNAME}" < "${LOCAL_DUMP_PATH}"
docker-compose stop db
@slaveofcode
slaveofcode / reset_db.sql
Created March 16, 2018 17:44
Reset Postgres Database
# all of your tables are in a single schema, this approach could work (below code assumes that the name of your schema is public
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
# If you are using PostgreSQL 9.3 or greater, you may also need to restore the default grants.
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO public;
@slaveofcode
slaveofcode / docker-compose-postgres.yml
Created January 6, 2018 21:44 — forked from toast38coza/docker-compose-postgres.yml
Docker-compose files for Kong
version: "2"
services:
postgres:
image: postgres:9.4
container_name: kong-database
ports:
- "5432:5432"
environment:
- POSTGRES_USER=kong
@slaveofcode
slaveofcode / nodejs-express-cookies-example.js
Created December 17, 2017 09:21 — forked from gdm85/nodejs-express-cookies-example.js
How to create session cookies with Node.js + Express
var express = require('express'),
app = express(),
https = require('https'),
fs = require('fs'),
keys = require( "keygrip" )(['secret1', 'secret2']),
cookies = require( "cookies" );
// This line is from the Node.js HTTPS documentation
var options = {
key: fs.readFileSync('private_key_cert.pem'),
@slaveofcode
slaveofcode / regex.md
Created November 22, 2017 03:35 — forked from etiennemarais/regex.md
Regular expression for handlebars variables, includes, if/else blocks and unescaped variables

Regex

{{[{]?(.*?)[}]?}}

Captures the value of the variable name in a handlebars template

{{> components/templates/email/includes/email-tr-spacer }}
{{# deliveryAddress }}
@slaveofcode
slaveofcode / server.js
Created November 18, 2017 16:27
Node.js Sample Server with Restify
/*
* Node.js Sample Server with Restify
* Copyright (C) 2014 - Thiago Uriel M. Garcia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@slaveofcode
slaveofcode / joi_conditional_schema.js
Last active October 26, 2017 11:09
Joi Condition Schema
const Joi = require('joi')
const main = () => {
const VALID_TITLES = ["Mr.", "Mrs.", "Ms."]
const ADDRESS_HOME = "Home"
const ADDRESS_OFFICE = "Office"
const VALID_ADDRESS_TYPES = [ADDRESS_HOME, ADDRESS_OFFICE]
const digitalSchema = Joi.object().keys({
@slaveofcode
slaveofcode / ultimate-ut-cheat-sheet.md
Created October 10, 2017 03:19 — forked from yoavniran/ultimate-ut-cheat-sheet.md
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai and Sinon

The Ultimate Unit Testing Cheat-sheet

For Mocha, Chai and Sinon

using mocha/chai/sinon for node.js unit-tests? check out my utility: mocha-stirrer to easily reuse test components and mock require dependencies