Skip to content

Instantly share code, notes, and snippets.

View michael-whi's full-sized avatar
💭
We're rowing.

michael-whi

💭
We're rowing.
View GitHub Profile
@michael-whi
michael-whi / RLE.js
Created October 30, 2019 14:57 — forked from samuelfvlcastro/RLE.js
Example of Run-length encoding (RLE) compression in javascript
var blocks = ["A","A","A","A","A","A","A","A","A","A","A","A","B","B","A","C","C","C","C","D","D","D","D","A","A","E","E","E","A"];
function Encode(input){
var segmentLength = blocks.length;
var run = 0, current = '', last = '', encoded = '';
current = last = blocks[0];
for(var i = 1; i <= segmentLength; i++){
if(current !== last){
@michael-whi
michael-whi / connect.js
Created September 19, 2019 12:56 — forked from gaearon/connect.js
connect.js explained
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (