Skip to content

Instantly share code, notes, and snippets.

@alexrqs
alexrqs / loadUniqueScripts.js
Last active September 4, 2019 12:39
How to load only one time even if the script is required multiple times, and how to check or detect if the script is loaded.
// keep track of the loaded libraries
const loadedLibraries = []
function registerLibraryLoaded(id) {
// record the libs only if the array doesn't contain the same already
if (loadedLibraries.indexOf(id) < 0) {
loadedLibraries.push(id)
}
}
@alexrqs
alexrqs / get-window-user-props.js
Created August 28, 2018 20:36
Get window properties defined by the user
(function () {
var results, currentWindow,
// create an iframe and append to body to load a clean window object
iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
// get the current list of properties on window
currentWindow = Object.getOwnPropertyNames(window);
@alexrqs
alexrqs / videojs-plugin-events-logger.js
Last active November 9, 2023 10:09
VideoJS event list
// The events are from https://www.w3.org/TR/html5/semantics-embedded-content.html#media-elements-event-summary
import videojs from 'video.js'
const Plugin = videojs.getPlugin('plugin')
const EVENTS = [
'loadstart',
'progress',
'suspend',
'abort',
'error',
@alexrqs
alexrqs / install.sh
Created June 17, 2018 21:53
webpack boilerplate for js with babel
yarn add -D webpack webpack-cli webpack-dev-server babel-loader@next @babel/core @babel/preset-env @babel/preset-stage-0 html-webpack-plugin
@alexrqs
alexrqs / URI.js
Last active June 22, 2018 16:03
URI parser to avoid the regex use when all you need is host, pathname, port, search..
function parseURL(url) {
// Assign resource as string
const parser = document.createElement('a')
parser.href = url
return {
// hash // == "#chiripiorca"
hash: parser.hash,
// host // == "www.chespirito.com:3000"
host: parser.host,
@alexrqs
alexrqs / App.jsx
Created May 11, 2017 00:56
Very ugly TodoApp with create-react-app redux, classnames and transitions to explain on pioneras developers
import React, { Component } from 'react'
import TodoList from './components/TodoList'
import TodoInput from './components/TodoInput'
import Filter from './components/Filter'
import './App.css'
class App extends Component {
render() {
return (
<div className="App">
@alexrqs
alexrqs / app.jsx
Last active April 25, 2017 20:53
Code spliting react router 4 with import() and webpack 2.4
import React, { Component } from 'react'
import { BrowserRouter as Router, Route, Link } from 'react-router-dom'
import async from './components/async'
class App extends Component {
render() {
return (
<Router>
<div>
<Route exact path="/" component={async(import('./pages/home')) } />
@alexrqs
alexrqs / webpack.config.babel.js
Last active April 24, 2017 23:12
webpack 2 configuration example with `webpack --opt.source=true` html/pug/jade, dev-server, eslint and scss
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'
import ExtractTextPlugin from 'extract-text-webpack-plugin'
import CompressionPlugin from 'compression-webpack-plugin'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import autoprefixer from 'autoprefixer'
import webpack from 'webpack'
import path from 'path'
import PACKAGE from './package.json'
@alexrqs
alexrqs / app.js
Created September 29, 2016 19:14 — forked from acdlite/app.js
Quick and dirty code splitting with React Router v4
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
@alexrqs
alexrqs / prefix_commits.md
Created July 19, 2016 23:34
git command to prefix some words to multiple commits on the same branch.

This command will prefix xx commits number with [SYTO-640] including sqare brakets, the importance of the \c at the end of the prefix is to avoid new lines on the commit otherwise this will transform the the commit name to commit description.

more info about \c http://stackoverflow.com/questions/7154800/what-is-the-bash-escape-character-c

git filter-branch -f --msg-filter '
  echo "[SYTO-640] \c" && cat 
' HEAD~xx..HEAD