Skip to content

Instantly share code, notes, and snippets.

View julioflima's full-sized avatar
🏠
Working from home

Julio Lima julioflima

🏠
Working from home
View GitHub Profile
function cell2csv(fileName, cellArray, append, separator, excelYear, decimal)
% Writes cell array content into a *.csv file.
%
% CELL2CSV(fileName, cellArray, append, separator, excelYear, decimal)
%
% fileName = Name of the file to save. [ i.e. 'text.csv' ]
% cellArray = Name of the Cell Array where the data is in
% append = false to open a new file, or true to go on with the existent.
% separator = sign separating the values (default = ';')
% excelYear = depending on the Excel version, the cells are put into
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main () {
char str[80] = "step(145621900,54544660)";
char duty[10];
char time[20];
int firstP = strcspn(str, "(");
int secondP = strcspn(str, ",");
@julioflima
julioflima / SensorRule.js
Created September 5, 2020 05:46
Rule, add a personalized date with moment timezone module.
const moment = require('moment-timezone');
module.exports = class SensorRule {
static date(req, res, next) {
try {
const { timestamp } = req.body;
const dateFull = new Date(timestamp).getTime();
const date = moment(dateFull).tz('UTC').format('YYYY/MM/DD HH:mm:ss.SSSSSSSSS');
@julioflima
julioflima / SensorDTO.js
Last active September 5, 2020 05:56
DTO using Joi exporting schemes to Celebrate.
const { Segments, Joi } = require('celebrate');
module.exports = class SensorDTO {
static getSensorTimestamps() {
return {
[Segments.QUERY]: Joi.object().keys({
name: Joi.string().required(),
}),
};
}
@julioflima
julioflima / App.js
Created September 5, 2020 05:58
App in class to facilitate reuse.
const express = require('express');
const cors = require('cors');
const { errors } = require('celebrate');
module.exports = class App {
constructor(routes) {
this.routes = routes;
this.server = express();
this.middleware();
this.router();
@julioflima
julioflima / index.js
Last active September 6, 2020 09:52
Server listener.
const Routes = require('./Routes');
const App = require('./App.js');
const routes = new Routes();
const app = new App(routes).server;
app.listen(3000);
@julioflima
julioflima / Cloud.js
Last active September 6, 2020 10:54
Cloud in class, have all configuration of database.
const knex = require('knex');
module.exports = class Cloud {
constructor(enviroment) {
// Object
this.knex = knex;
// Variables
this.enviroment = enviroment;
}
@julioflima
julioflima / Routes.js
Last active September 6, 2020 11:36
Routes become a map with the split of validations, rule added and two validations.
const { celebrate } = require('celebrate');
const express = require('express');
const SensorDTO = require('../model/SensorDTO');
const SensorRule = require('../rule/SensorRule');
const SensorController = require('../controller/SensorController');
module.exports = class Routes {
constructor() {
this.routes = express.Router();
@julioflima
julioflima / migrations.js
Last active September 6, 2020 12:04
Migrations using Query Builder Knex.
exports.up = (knex) => {
return knex.schema.createTable('sensor', (table) => {
table.string('id').primary();
table.bigInteger('timestamp').notNullable().primary();
table.string('date').notNullable();
table.string('name').notNullable();
table.float('value').notNullable();
});
};
@julioflima
julioflima / SensorController.js
Created September 6, 2020 12:07
Controller reading, writing and deleting o db.
const Cloud = require('../model/database/Cloud');
const db = new Cloud('development').connection();
module.exports = class SensorController {
static async index(req, res) {
try {
const { name } = req.query;
const count = await db('sensor')