Skip to content

Instantly share code, notes, and snippets.

View brospars's full-sized avatar

Benoit Rospars brospars

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@brospars
brospars / readme.md
Created September 18, 2020 11:54
Reset Vuex state store

Reseting Vuex module to its original state could be tideous if you have to manually reset all values. So instead you could use a function to retrieve the default state.

const getDefaultState = () => {
  return {
    id: '',
    authors: []
  }
}
@brospars
brospars / readme.md
Last active September 25, 2020 15:07
Generate CRUD mutations and actions for Vuex

Vuex can be quite repetitive to write generic mutations (arrays : set, add, update, delete, literals: update) for each state property. But it's important to keep track of changes inside the store.

So here's a way to generate generic mutations and associated actions :

// book-store.js
const state = {
  id: '',
  title: '',
  authors: [],
@brospars
brospars / uid.js
Created June 17, 2020 08:04
One liner uid javascript
Math.random().toString(36).slice(-10);
@brospars
brospars / readme.md
Created September 3, 2019 12:33
Guide to setup Ionic with Vue project for Android

Guide to setup Ionic with Vue project

  1. Install Vue CLI npm install -g @vue/cli
  2. Create your App vue create my-vue-app
  3. Choose the recommended default setup (with router, store, etc)
  4. Add Ionic/Vue as a dependency of your project npm install @ionic/vue
  5. Add Ionic as a Vue plugin in your main.js
// [...]
@brospars
brospars / step-by-step.js
Last active April 17, 2019 12:49
A step by step script with delay between each action, demo : https://brospars.github.io/snippets/step-by-step
function nextStep(cb, ...args) {
setTimeout(() => {
cb(...args)
}, 1000)
}
function step1(foo){
// some logic and pass result to next step
var bar = foo * 2
nextStep(step2, foo, bar)
@brospars
brospars / readme.md
Created September 18, 2018 08:30
Bookmarlet to generate table of content of a MOOC from edx studio
  1. Create a bookmarlet with the code below
  2. Go to the homepage of your MOOC in studio (in our case : studio.fun-mooc.fr/course/[MOOC_ID])
  3. Run the bookmarklet
javascript:(function(){
	var base_url = window.location.href.replace('studio.fun-mooc.fr/course','fun-mooc.fr/courses')+'/jump_to_id/';
	var sections = $('.outline-section');
	var sectionList = $('<ul/>');
@brospars
brospars / readme.md
Last active September 4, 2018 13:54
Fix gnome authentication failure
@brospars
brospars / environment.yml
Last active August 30, 2018 06:57
Jupyter conda environment with R and Scipy
name: mooc_rr
channels:
- conda-forge
- defaults
dependencies:
- alembic=0.9.9
- attrs=18.1.0
- automat=0.7.0
- backcall=0.1.0
- beautifulsoup4=4.6.0
@brospars
brospars / regex_vtt.md
Last active December 12, 2022 12:27
Regular expression to match vtt subtitles

Regex : /^(\d{2}:\d{2}:\d{2}[.,]\d{3})\s-->\s(\d{2}:\d{2}:\d{2}[.,]\d{3})\n(.*(?:\r?\n(?!\r?\n).*)*)/gm
Demo : https://regex101.com/r/TH1JhU/1
Code example :

const regex = /^(\d{2}:\d{2}:\d{2}[.,]\d{3})\s-->\s(\d{2}:\d{2}:\d{2}[.,]\d{3})\n(.*(?:\r?\n(?!\r?\n).*)*)/gm;
const str = `WEBVTT

00:00:00.000 --> 00:00:04.469
Blah Bla bla 1
Multine