Skip to content

Instantly share code, notes, and snippets.

View fxmontigny's full-sized avatar

François-Xavier Montigny fxmontigny

  • Paris, France
View GitHub Profile
@fxmontigny
fxmontigny / array-to-json.js
Created August 19, 2019 09:33
Get json from Array of objects
Array.prototype.toJson = function(name, value = name) {
return this.reduce((acc, cur) => {
acc[cur[name]] = cur[value];
return acc;
}, {});
}
/** Test **/
const form = [
{ name: 'firstname', flex: 1, value: 'test1' },
jQuery(document).ready(function() {
jQuery('video').each(function() {
const sourceDom = jQuery(this).find('source');
if(sourceDom.length === 1) {
const src = jQuery(sourceDom[0]).attr('src'),
indexVimeo = src.indexOf('vimeo.com');
if(indexVimeo !== -1) {
const split = src.split('/')
@fxmontigny
fxmontigny / auto-rotate-image.ts
Created May 15, 2018 08:53
Auto rotate image and retour base64
onRotateImage(file, checkError = true) {
const promise = new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (e) => {
this.getOrientation(file, (orientation) => {
if (orientation > 0) {
const image = new Image();
image.src = e.target['result'];
image.onload = () => {
@fxmontigny
fxmontigny / quill-insert-html.js
Created April 19, 2018 13:37
Quilljs insert html
const editor = new Quill(...);
// defined method insert html
editor.insertHTML = (html) => {
const range = this.editor.getSelection(true),
date = Date.now();
editor.insertEmbed(range.index, 'div', { id: date }, 'user');
editor.setSelection(range.index + 1, Quill.sources.SILENT);
$(html).insertAfter('#' + date);
@fxmontigny
fxmontigny / get-set-html-quilljs-editor.js
Last active March 20, 2024 16:27
Insert and get html content with quilljs editor
const editor = $('.editor');
const quill = new Quill(editor);
// set html content
quill.setHTML = (html) => {
editor.root.innerHTML = html;
};
// get html content
@fxmontigny
fxmontigny / recursive-replace-strings.js
Last active March 21, 2023 22:51
Recursively find and replace all strings from a object
const cleanObject = (object) => {
if (object !== null) {
switch (typeof object) {
case 'string' :
const regex = new RegExp('your regex', 'gm');
object = object.replace(regex, 'your new string');
break;
case 'object':
if (object instanceof Array) {
const length = object.length;
@fxmontigny
fxmontigny / build.sh
Last active October 25, 2016 08:47
[SHELL] How make prod env with angular-cli
#!/bin/bash
npm install
ng build -prod
cp src/.htaccess dist/
find dist/assets -type f \( -name '*.js' -o -name '*.css' \) -exec gzip -k -f "{}" \; #every js and css files you cannot add to angular-cli.json
@fxmontigny
fxmontigny / shell.txt
Last active October 25, 2016 08:43
[SHELL] How to count all the lines of code in a directory recursively
find . -iname "*.ts" -exec grep -vE '^#' {} \; | wc -l