Skip to content

Instantly share code, notes, and snippets.

View thelbouffi's full-sized avatar

Taha EL BOUFFI thelbouffi

View GitHub Profile
@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 / 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 / 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 / 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 / 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)