Skip to content

Instantly share code, notes, and snippets.

@ffafara
ffafara / deffered.js
Created October 25, 2017 02:42
Deffered pattern using ES6 promise
'use strict';
var Deferred = function Deferred() {
if (!(this instanceof Deferred)) {
return new Deferred();
}
var self = this;
self.promise = new Promise(function (resolve, reject) {
self.resolve = resolve;
To add port forwards from the command line to a running boot2docker VM use:
VBoxManage controlvm boot2docker-vm natpf1 "name,tcp,127.0.0.1,1234,,1234"
Where 'name' is the unique name for your rule, and '1234' is the port you wish to forward. So for the original Sinatra example:
VBoxManage controlvm boot2docker-vm natpf1 "sinatra-hello,tcp,127.0.0.1,5000,,5000"
@ffafara
ffafara / portforwarding.md
Created December 1, 2015 20:30 — forked from kujohn/portforwarding.md
Port forwarding in Mavericks

Port Forwarding in Mavericks


Since Mavericks stopped using the deprecated ipfw (as of Mountain Lion), we'll be using pf to allow port forwarding.

####1. anchor file Create an anchor file under /etc/pf.anchors/<anchor file> with your redirection rule like:

@ffafara
ffafara / gist:a40293c8bd0d03ecfcf8
Created November 2, 2015 19:34 — forked from fearofcode/gist:63aca07f84c3a82c83cd
Simple Elasticsearch usage
package org.wkh.learningelasticsearch;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.node.Node;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
@ffafara
ffafara / esacpeHTML.js
Last active August 29, 2015 14:25
escape HTML
// Use the browser's built-in functionality to quickly and safely escape the string
function escapeHtml(str) {
var div = document.createElement('div');
div.appendChild(document.createTextNode(str));
return div.innerHTML;
};
// UNSAFE with unsafe strings; only use on previously-escaped ones!
function unescapeHtml(escapedStr) {
var div = document.createElement('div');
// Use the browser's built-in functionality to quickly and safely escape the string
function escapeHtml(str) {
var div = document.createElement('div');
div.appendChild(document.createTextNode(str));
return div.innerHTML;
};
describe('controllerCtrl', function () {
var $controller,
$rootScope,
$scope;
beforeEach(module('controller'));
beforeEach(inject(function ($injector) {
$controller = $injector.get('$controller');
$rootScope = $injector.get('$rootScope');