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 / i18n-restify-app.js
Created August 26, 2017 16:50 — forked from mashpie/i18n-restify-app.js
i18n-node in an restify app setup
// require modules
var restify = require('restify'),
i18n = require('i18n'),
app;
// minimal config
i18n.configure({
locales: ['en', 'de'],
directory: __dirname + '/locales'
});
@slaveofcode
slaveofcode / CategorySagas.js
Created September 12, 2017 04:49 — forked from jgautheron/CategorySagas.js
Redux-Saga for next.js
import {call, put, take, fork} from 'redux-saga/effects'
import {END} from 'redux-saga'
import CategoryActions, {CategoryTypes} from '../Redux/CategoryRedux'
// attempts to fetch category
export function* fetchCategoryServer (api) {
let action = yield take(CategoryTypes.CATEGORY_SERVER)
// check when it stopped
while (action !== END) {
yield fork(fetchCategoryAPI, api)
@slaveofcode
slaveofcode / tmux-cheatsheet.markdown
Created October 9, 2017 02:54 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@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


@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 / 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 / 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 / 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 / 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 / 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;