View node_logger.js
const fs = require('fs');
function createLogger() {
// const log_file = fs.createWriteStream(`${__dirname}/debug.log`, { flags: 'w' });
const logStream = fs.createWriteStream('log.txt', { flags: 'a' });
// logStream.log('Initial line...');
// logStream.end('this is the end line');
function formatDate(d) {
View php_xpath_libxml_dom.php
<?php
$html = '<div><img src="rabbit.jpg">';
libxml_use_internal_errors(true) and libxml_clear_errors();
$doc = new \DOMDocument;
$doc->loadHTML($html ?: '<html></html>');
$path = '//div';
View Reactjs_and_express_server.md

React + Node Server

We want to be able to use express/hapi/feather/etc using passport for auth and only load our react app after successful login. We also want ES6, live-reloading, and hot-loading for fast development.

A common solution is to run create-react-app on one port and node server.js on another. Then you add a proxy: http://localhost:3000 to the create-react-app package.json file and it allows your react app to talk to the express server. When you are ready to deploy to production, you generate static files and only need node server.js from them on. That works as long as you don't need the express/hapi/koa/server:

  • to be the first point of entry
  • to provide inital state (you can use componentDidMount() + AJAX to load inital state)

Another solution is to simply have your node server load webpack/babel as needed for development, but default to static files for production.

View .eslintrc
{
"extends": "airbnb",
"parser": "babel-eslint",
"rules": {
"no-console": 0,
"react/jsx-filename-extension": 0,
}
}
View routes.coffee
# for API and DB endpoints
user = require './controllers/userController'
mainFeed = require './controllers/mainFeedController'
{isLoggedIn} = require './middleWare'
{alreadyLoggedOut} = require './middleWare'
module.exports = (app, passport) ->
#=========================
# Routes here!!
View http.php
<?php
// command line
// curl --data "text=foobar" http://localhost:3001/api/decrypt
// File sockets
function http_request($url, $data, $a = null, $b = null) {
$opts = array('http' =>
array(
'method' => 'POST',
View onoff.js
const express = require('express');
const app = express();
let isOn = true
// Testing
app.get('/off', (req, res) => {
isOn = false
res.json({ method: req.method, path: req.path, on: isOn });
View promise-exceptions.js
function promiseMe(exception) {
return new Promise((resolve, reject) => {
if (exception == 'exception') {
throw new Error('problem');
}
reject(new Error('reject-called'));
});
}
View mysql_install.sh
# Install
sudo apt-get install mariadb-server
# Secure the server
sudo mysql_secure_installation
# vim /root/.my.cnf and place the following
[mysql]
user=root
password=...
View atom.md

Install eslint for NPM

npm install --save-dev eslint babel-eslint eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react

babel-eslint provides es6 features like arrow functions

If using meteor

npm install eslint-plugin-meteor --save-dev