Skip to content

Instantly share code, notes, and snippets.

View barmgeat's full-sized avatar

Mustafa Hazim barmgeat

  • Berlin, Germany
View GitHub Profile
// in the controller controller.js
module.export = function(app){
}
// in the app.js
var express = require('express');
var controller = require('./controller/controller.js');
..
// in the controller.js handel the user reactions
module.export = function(app){
app.get('/AppName', function(req, res){
res.render('mainAppPage');
});
};
// in the views/mainAppPage.ejs
our html tamplate
const app = require('express')();
var http = require('http').createServer(app);
var io = require('socket.io')(http);
const hostname = '192.168.56.1';
const port = 3001;
app.get('/', (req, res) =>{
res.sendFile(__dirname+'/server.html');
});
@barmgeat
barmgeat / server.js
Last active June 27, 2019 16:30
connect to mongo database from node server
const mongoose = require('mongoose');
mongoose.connect(
'mongodb://username:password@host/databasename', {useNewUrlParser: true}
);
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
var userSchema = mongoose.Schema({
"id": Number,
"username": String,
"paswod": String,
"name": String,
"last_name": String
});
var user = mongoose.model('users', userSchema);
const app = require('express')();
const http = require('http').createServer(app);
const io = require('socket.io')(http);
const userFunctions = require('./userFunctions')
const hostname = '192.168.56.1';
const port = 3001;
io.on('connection', function (socket) {
console.log('a user connected');
function registerNeuUser(data){
userName = data.userName;
firstName = data.firstName;
lastName = data.lastName;
email = data.email;
password = data.password;
birthDay = data.birthDay;
//log the registered user
console.log('++++++++++ New-User +++++++++++++\n' +
YouTube iframe:
<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/videoseries?list=PLx0sYbCqOb8TBPRdmBHs5Iftvv9TPboYG"
frameborder="0"
allow="autoplay; encrypted-media"
allowfullscreen>
</iframe>
@barmgeat
barmgeat / php requests function.js
Last active October 25, 2019 15:04
note extension for sure html but for markup i make it js
public static function postRequest($url, $postData, $headers){
//init curl:
$ch = curl_init($url);
// Configuring curl options
$options = array(
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $postData,
CURLOPT_HTTPHEADER => $headers
);
@barmgeat
barmgeat / expamle.js
Last active October 26, 2019 05:27
to create html elements
// Ex: create category container
/// add the consts in data obj can be not definde just the type is requseted
const catContainer = htmlE({
type: 'div', // type of the element
classes: 'first-class second-class', // css classes
id: elementId, // element id
container: container, // parent container to append to
onClick: catClick, // on element click function
params: [category] // on element click function params
});