Skip to content

Instantly share code, notes, and snippets.

@brunops
brunops / app.js
Created May 16, 2016 04:14
avoid anon callbacks
// don't do this
$(document).ready(function () {
$.get('/foo', function (response) {
var list = $('<ul />')
response.list.forEach(function (item) {
list.append($('<li />').text(item))
})
$('#content').append(list)
@brunops
brunops / bind-no-bind-test-examples.js
Created April 7, 2016 22:00
Examples of testing promise controller steps with and without bind
const steps = {
stepBind(req, foo) {
// bla
},
stepNoBind: (req) => (foo) => {
// bla
@brunops
brunops / index.js
Created October 26, 2015 01:22
mapping classes
var map = require('./map');
new map['Test']();
// "hello from Test contructor"
@brunops
brunops / transform-order.js
Created September 14, 2015 03:12
transform order diff
var q = require('q');
function subtract2(data) {
return data - 2;
}
function multiply5(data) {
return data * 5;
}
@brunops
brunops / promise-chain-test.js
Last active May 12, 2017 09:41
Promise chain test
var q = require('q'),
assert = require('chai').assert,
sinon = require('sinon');
var obj = {
load: function () {
console.log('-- `load` called with: %s', JSON.stringify(arguments));
var defer = q.defer();
setTimeout(function () {
@brunops
brunops / event-emitter.js
Created September 5, 2014 22:59
event emitter example
var EventEmitter = require('events').EventEmitter;
var obj1 = new EventEmitter();
obj1.on('event1', function () {
console.log('event1 triggered');
});
for (var i = 0; i < 3; ++i) {
var net = require('net');
var server = net.Server();
var port = process.env.PORT || 1337;
server.listen(port);
server.on('connection', function (socket) {
socket.write('hello');
});
@brunops
brunops / gist:7638156
Last active December 29, 2015 07:39
why does it hang for a while before terminating?
var Readable = require('stream').Readable;
var rs = new Readable;
rs.push('bro ');
rs.push(null);
for (var i = 0; i < 10000; i++)
rs.pipe(process.stdout);
@brunops
brunops / html5.html
Created January 31, 2013 00:47
minimal html5 doc
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
@brunops
brunops / perms.txt
Last active October 13, 2015 05:48
Drupal files permissions
# Include your user in www-data group
# This command needs to be run only once
useradd -G www-data brunops
# File User/Group owners
sudo chown -R brunops:www-data /path/to/folder --preserve-root
# Drupal file permissions
# Execution perm for files
sudo find /path/to/folder -type f -print0 | xargs -0 sudo chmod 644 --preserve-root