Skip to content

Instantly share code, notes, and snippets.

{
"name": "rails-react-demo",
"version": "1.0.0",
"description": "This README would normally document whatever steps are necessary to get the application up and running.",
"main": "index.js",
"directories": {
"lib": "lib",
"test": "test"
},
"scripts": {
import React from 'react';
import './App.css';
const fetchTestDatas = function () {
fetch('/api/v1/tests')
.then(res => res.json())
.then((response) => { console.log("Test datas response", response); })
.catch((error) => { console.log("Error while fetching test datas", error); })
}
{
"name": "client",
"version": "0.1.0",
"proxy": "http://127.0.0.1:3000",
"private": true,
"dependencies": {
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-scripts": "3.1.1"
},

Sequelize v5

Init project

In your express project folder

yarn global add sequelize-cli
yarn add sequelize mysql2 dotenv

other available dialect : pg pg-hstore | mariadb | sqlite3 | tedious

- Install passenger
- Install nginx
- Install nginx-passenger
- Configure nginx-passenger for ruby path
## Nginx conf
`/etc/nginx/site-available/domain.com`
```text
map $http_upgrade $connection_upgrade {
default upgrade;
@Eth3rnit3
Eth3rnit3 / create-react-app-to-cordova.js
Last active March 31, 2019 13:12
Une this script to covert your index.html of create-react-app into index.html cordova ready !
let FS = require('fs');
// read the index.html from build folder
let data = FS.readFileSync('./build/index.html', 'utf8');
function insertContent(fullContent, beforeWhat, newContent) {
// get the position before which newContent has to be added
const position = fullContent.indexOf(beforeWhat);
// since splice can be used on arrays only
{
"current": "0.1.6"
}
///////////////////// Exercice 1 ///////////////////////
let num1 = 5;
let num2 = 4;
let i = 0;
let result = 0;
while(i < num1){
result = result + num2
i++;
}
if(process.env.NODE_ENV == 'production'){
app.use(express.static(path.join(__dirname, 'client')));
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'client', 'index.html'));
});
}
@Eth3rnit3
Eth3rnit3 / nestedInclude.js
Created January 9, 2019 15:22
In this example, Product belongsTo Media and Category hasMany Product Media > Product > Category Product know mediaId Product know categoryId
Category.findByPk(req.params.id, {
include: [
{
model: Product, as: 'products', include:
[
{model: Media, as: 'image'}
]
}
]
})