Skip to content

Instantly share code, notes, and snippets.

View thelbouffi's full-sized avatar

Taha EL BOUFFI thelbouffi

View GitHub Profile
@thelbouffi
thelbouffi / mailparse installation
Created September 25, 2016 11:05
how to instal mailparse on php7
REQUIREMENTS:
- php-pear (install automatically php7.0-xml and php-xml)
sudo apt-get install php-pear
-php7.0-mbstring
sudo apt-get install php7.0-mbstring
-php7.0-dev
sudo apt-get install php7.0-dev
INSTALLATION:
1- cd /tmp/xxxxxx (e.g: cd /tmp/pear/download)
@thelbouffi
thelbouffi / xlsx-node-parser.js
Last active October 6, 2016 14:27
Node.js parser of xlsx files
var XLSX = require('xlsx');
var workbook = XLSX.readFile('fileName.xlsx');
var sheet_names = workbook.SheetNames;//array of sheet names
//console.log(sheet_names);
var worksheet = workbook.Sheets;
for(x in sheet_names) {
worksheet = workbook.Sheets[sheet_names[x]];
//console.log(worksheet);
var header = []; //initialize header array
@thelbouffi
thelbouffi / code_base64_decode.js
Created October 6, 2016 14:48
Coding and decoding a file in base64 (for example a pdf file)
var fs = require('fs');
// Reade file synchronously and put the result in buffer
var file = fs.readFileSync('fileName.pdf');
// Code the file in base64
var base64EncodedPDF = new Buffer(file).toString('base64');
// Decode the file
var baseDecodedPDF = new Buffer(base64EncodedPDF, 'base64');
// Get the decoded file in its original format
fs.writeFileSync('decodedPDF.pdf', baseDecodedPDF);
@thelbouffi
thelbouffi / decrement_loop.js
Created October 7, 2016 11:10
Loop using self invoking function and decrementation
// This code will generate 10 iterations
(function test(i){
console.log('test'+i);
// put here the code of anything you want to execute
if(i--){
test(i)
}
})(10)
@thelbouffi
thelbouffi / looping_delay.js
Created October 7, 2016 11:46
Looping with delay
// Loop for doesn't work
/*
for (var i=1; i < 5; i++) {
setTimeout(function () {
console.log('test');
}, 3000);
}
*/
// Solution
@thelbouffi
thelbouffi / Mongodb_ubuntu_15.10.md
Last active October 18, 2016 13:54
Installation and configuration of mongodb in ubuntu 15.10

Install mongodb
sudo apt-get install mongodb

Acess mongodb.service and insert the configuration code
cd /lib/systemd/system
sudo vim mongodb.service

[Unit]
Description=High-performance, schema-free document-oriented database
Documentation=man:mongod(1)
var vehicle = function(ty) {
this.type=ty;
}
vehicle.prototype.ride = function() {
console.log('I am riding a ', this.type);
}
var newRebuild = function(constructor){
var obj = {};
Object.setPrototypeOf(obj, constructor.prototype);
var arArgs = Array.from(arguments).slice(1);
@thelbouffi
thelbouffi / Typings in Typscript
Last active May 12, 2022 11:28
What are Typings in Typescript?
JavaScript is untyped, meaning that we can pass around data and objects as we want.
We can write code that calls methods that don't exist on an object, or variables that we don't have.
These problems are hard to discover when you are writing code and it can lead to unstable code,
and doing big changes of your code can become very difficult and risky as you don't immediately see if your changes
conflicts with the rest of the code.
TypeScript is mainly about adding types to JavaScript. That means that TypeScript requires you to accurately
describe the format of your objects and your data. When you do that, that means that the compiler can investigate
your code and discover errors. It can see that you are trying to call a function that does not exist or use a variable
that is not accessible in the current scope.
@thelbouffi
thelbouffi / npm-cheat-sheet.md
Created November 9, 2017 22:05 — forked from AvnerCohen/npm-cheat-sheet.md
Node.js - npm Cheat Sheet

Node.js - npm Cheat Sheet

(Full description and list of commands at - https://npmjs.org/doc/index.html)

##List of less common (however useful) NPM commands

######Prepand ./bin to your $PATH Make sure to export your local $PATH and prepand relative ./node_modules/.bin/:

// Node.js CheatSheet.
// Download the Node.js source code or a pre-built installer for your platform, and start developing today.
// Download: http://nodejs.org/download/
// More: http://nodejs.org/api/all.html
// 0. Synopsis.
// http://nodejs.org/api/synopsis.html