Skip to content

Instantly share code, notes, and snippets.

View vcanales's full-sized avatar

Vicente Canales vcanales

View GitHub Profile
@vcanales
vcanales / app.js
Created February 18, 2015 20:25
expressJS + socket.io configuration.
var express = require('express');
var path = require('path');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var app = express();
// Extras para Socket.io
// var server = require('http').Server(app);
@vcanales
vcanales / AppController.php
Created March 24, 2015 14:48
Really, really important.
/**
* @Route("/teapot/brew/{slug}");
*/
# THE MOST IMPORTANT METHOD ON THIS APPLICATION
public function teapotAction($slug = '') {
$response = new Response();
if ($slug != 'tea') {
$response->setStatusCode(Response::HTTP_I_AM_A_TEAPOT);
} else {
$response->setStatusCode(Response::HTTP_OK);
@vcanales
vcanales / app.js
Last active August 29, 2015 14:19
This configuration leaves express running on ports 3000 and 3030.
// This configuration leaves express running on ports 3000 and 3030. I need to avoid that. Help!
var server = app.listen(3030, function() {
debug('Express server listening on port '+ server.address().port);
});
var io = require('socket.io')(server);
var connections = 0;
io.sockets.on('connection', function(socket) {
connections++;
console.log('client connected ('+connections+' total)');
onDrop(files,e) {
let element;
if (e.target.className.indexOf('box_gif') == -1) {
element = e.target.parentElement;
} else {
element = e.target;
}
element.style.backgroundImage = 'url('+files[0].preview+')';
@vcanales
vcanales / Video.jsx
Created February 15, 2016 14:48
Component Lifecycle Problems
componentDidMount() {
this.setState(this.initialize());
return CatedralStore.addChangeListener(() => this._onCatedralChange());
}
componentWillUnmount() {
console.log("remove change listener")
return CatedralStore.removeChangeListener(this._onCatedralChange);
}
@vcanales
vcanales / bootstrap.js
Created April 26, 2016 13:36
Load Controllers
loadControllers() {
let controllers = fs.readdirSync('./controllers');
controllers.map((file) => {
if (file != config.controllers.mainController) {
this.files.push(file);
this.controllers.push(JSON.parse(`{ "fileName": "${file}", "actions": [] }`));
}
});
}
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;

Keybase proof

I hereby claim:

  • I am vcanales on github.
  • I am vcanales (https://keybase.io/vcanales) on keybase.
  • I have a public key ASDdKnBQjAKZHAyQHqhiPfKhEzDwdZodR9QyMC7KKB9jBwo

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am vcanales on github.
  • I am vcanales (https://keybase.io/vcanales) on keybase.
  • I have a public key ASBq2EhLiuptV1C7u7NJQHqzMi4xXpfJn1LPJ9nPqLYLZgo

To claim this, I am signing this object:

@vcanales
vcanales / exists.js
Last active January 22, 2020 03:53
Given an array of objects, check if for any member, the pair `key`, `value` exists
const readableExists = (array, key, value) => array.reduce((acc, obj) => {
if (obj[key] && obj[key] === value) {
return true;
}
return acc;
}, false);
const cleverExists = (array, key, value) => array.reduce((acc, obj) => {
return obj[key] && obj[key] === value || acc;
}, false);