Skip to content

Instantly share code, notes, and snippets.

View Musinux's full-sized avatar

Louis Cherel Musinux

View GitHub Profile
@Musinux
Musinux / javascript-functions-contexts.js
Last active March 24, 2017 09:22
Hint of different behaviors of functions depending on context in which the function is defined and executed
'use strict' // attention ces considérations ne sont valides qu'en utilisant le mode strict
var globale = 'globale'
var methode3 = () => {
if (!this || !this.attrLocal) {
console.log(' > methode3() NE partage PAS le contexte de Classe1')
}
if (this && this.attrLocal) {
console.log(' > methode3() partage le contexte de Classe1')
#!/usr/local/bin/node
var irc = require('irc')
var me = 'me'
var channel = '#chann'
var dest = 'dest'
var data = '\x24\xb1\x04\x08' // 0x804b120
var client = new irc.Client('irc.root-me.org', me, {
@Musinux
Musinux / node-postgres-benchmark.js
Last active October 1, 2017 11:25
Small benchmark tool for db drop, create, insert and select *
const { Pool } = require('pg')
const debug = require('debug')('a')
const defaultParams = {
database: 'postgres',
user: 'myuser',
password: 'mysecretpassword',
host: 'localhost',
port: 5432
}
@Musinux
Musinux / cssToInlineStyle.js
Created July 4, 2018 07:48
Node.js implementation of transforming a <style> tag to inline style. Useful to tranform Google Documents into Email-compatible format
const cssParser = require('css')
const { JSDOM } = require('jsdom')
function cssToInlineStyle (inputHtml) {
let style = inputHtml.match(/(?:<style[^>]*>)((?:[\r\n]|.)*?)(?:<\/style>)/)
const html = inputHtml.replace(/<style[^>]*>(([\r\n]|.)*?)<\/style>/, '')
if (!style) {
throw new Error('error while parsing')
}
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Titre de la page</title>
<style>
nav ul li {
display: inline-block;
border: 1px solid red;
width: 200px;
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Titre de la page</title>
<style>
nav ul li {
display: inline-block;
border: 1px solid red;
width: 200px;
/* globals Vue */
;(function () {
'use strict'
const template = `
<section id="accueil">
<h1>Titre de ma page d'accueil</h1>
<p>Mon super texte</p>
</section>
`
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Titre de la page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="app">
<nav>
@Musinux
Musinux / guacamole-add-connection.js
Created January 12, 2017 09:34
CLI Add an instance to an user for guacamole
var parseString = require('xml2js').parseString
var builder = new (require('xml2js').Builder)()
var fs = require('fs')
var argv = require('optimist')
.usage('Usage: $0 --input <input.xml> --name <machine-name>')
.options('hostname', {default: '@host'})
.options('port', {default: '3389'})
.options('serverLayout', {default: 'fr-fr-azerty'})
.options('colorDepth', {default: '16'})
.demand('name')
const Axios = require('axios')
exports.startToEndProcessQuery = function (req, res) {
return Axios.get('/explore.articlesearch.v1/favouriteSearch?edismax=true&storeId=00016&language=fr-FR&country=FR&query=' + req.params.str + '&rows=1000&page=1&profile=orSearch&null&__t=1541347156148')
.then(function (response) {
let stringIds = ''
let limits = response.data.regularResults.resultIds.length > 50 ? 50 : response.data.regularResults.resultIds.length
for (let i = 0; i < limits; i++) {
stringIds += response.data.regularResults.resultIds[i] + '&ids='
}