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 / node-cluster-messaging.js
Created July 3, 2017 09:08 — forked from jpoehls/node-cluster-messaging.js
Simple message passing between cluster master and workers in Node.js
var cluster = require('cluster');
if (cluster.isWorker) {
console.log('Worker ' + process.pid + ' has started.');
// Send message to master process.
process.send({msgFromWorker: 'This is from worker ' + process.pid + '.'})
// Receive messages from the master process.
@slaveofcode
slaveofcode / README.md
Created July 23, 2017 05:49 — forked from hofmannsven/README.md
My simply Git Cheatsheet
@slaveofcode
slaveofcode / gist:fb8f372d7471e6ef856270f1f5120dbf
Created July 26, 2017 16:06 — forked from mcavage/gist:1056404
Serving static content with restify
// Docs/etc.
server.get(null, '/', function(request, response, next) {
response.send(302, null, {
Location: config.siteName + '/docs'
});
return next();
}, log.w3c);
server.get(null, '/docs', function(req, res, next) {
@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 / 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'),