Skip to content

Instantly share code, notes, and snippets.

import React from 'react'
class App extends Component {
componentDidMount() {
// Subscribe here
}
componentWillUnmount() {
// Unsubscribe here
}
import React from 'react'
import Router from 'next/router'
const HistoryContext = React.createContext([]);
export class HistoryProvider extends React.Component {
state = {
history: []
}
@HaNdTriX
HaNdTriX / withRoute.js
Created July 19, 2017 00:42
next.js withRoute hoc
import React from 'react'
import Router from 'next/router'
const widthRoute = (Component) => {
return class extends React.Component {
componentDidMount() {
this.route = Router.route()
this.forceUpdate()
}
@HaNdTriX
HaNdTriX / AppBarWithTabs.js
Last active August 11, 2021 03:00
Example next.js and Material-UI next: TabNav with shared state
import React from 'react'
import Router from 'next/router'
import AppBarMD from 'material-ui/AppBar'
import Tabs, { Tab } from 'material-ui/Tabs'
const routes = [
'/',
'/articles'
]

Shortcuts

Mac

Action Shortcut
Jump to the next open tab ⌘ + Option + Right arrow
⌘ + Option + Tab
Jump to the previous open tab ⌘ + Option + Left arrow
⌘ + Option + Shift + tab
@HaNdTriX
HaNdTriX / toDataUrl.js
Last active February 18, 2021 20:02
Example of converting a file to a dataURL in ES6
const toDataURL = url => fetch(url)
.then(response => response.blob())
.then(blob => new Promise((resolve, reject) => {
const reader = new FileReader()
reader.onloadend = () => resolve(reader.result)
reader.onerror = reject
reader.readAsDataURL(blob)
}))
@HaNdTriX
HaNdTriX / README.md
Last active May 16, 2017 19:32
Creating a webextension generator

Hi

I am Henrik and I want to create a webextension generator that supports chrome, firefox, opera and safari. The stack I would like to use will contain:

  • yeoman for scaffolding
  • gulp as a build system
  • webpack for script compilation (modules, env variables, polyfills)
  • npm as a module system
  • and babel for ES2015
@HaNdTriX
HaNdTriX / execInNewTerminalTab
Created June 18, 2015 09:00
Opens a new Terminal Tab and executes command
function execInNewTerminalTab {
osascript -e 'tell application "Terminal"
activate
tell application "System Events" to keystroke "t" using command down
do script "'"$1"'" in window 1
end tell'
}
@HaNdTriX
HaNdTriX / selectize.inputmaxlength.plugin.js
Last active April 19, 2018 17:09
Selectize Plugin to allow to set a maxlength
Selectize.define('inputMaxlength', function(options) {
var self = this;
this.setup = (function() {
var original = self.setup;
return function() {
original.apply(this, arguments);
this.$control_input.attr('maxlength', this.settings.inputMaxlength);
};
})();
});
@HaNdTriX
HaNdTriX / imgURLToDataURL.es6
Last active October 31, 2018 20:06
Convert an imageURL to a base64 dataURL via canvas
/**
* Convert an imageURL to a
* base64 dataURL via canvas
*
* @param {String} url
* @param {Object} options
* @param {String} options.outputFormat [outputFormat='image/png']
* @param {Float} options.quality [quality=1.0]
* @return {Promise}
* @docs https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement#Methods