Skip to content

Instantly share code, notes, and snippets.

View HichemBenChaaben's full-sized avatar
🚀
RW Code™️

Hichem ben chaabene HichemBenChaaben

🚀
RW Code™️
  • Amsterdam
  • 15:14 (UTC -12:00)
View GitHub Profile
const { getRandomWordSync, getRandomWord } = require("word-maker");
console.log("It works!");
// 1
[...Array(100)].map((_, index) =>
console.log(`${index + 1}: ${getRandomWordSync()}`)
);
// 2
(function() {
var cornify_count = 0;
var cornify_add = function(options) {
// Track how often we cornified.
cornify_count += 1;
// Create a container DIV for our 'corn or 'bow.
var div = document.createElement('div');
div.style.position = 'fixed';
// Prepare our lovely variables.
var numType = 'px';
@HichemBenChaaben
HichemBenChaaben / requestAnimationFrame.js
Created December 12, 2018 23:43 — forked from jacob-beltran/requestAnimationFrame.js
React Performance: requestAnimationFrame Example
// How to ensure that our animation loop ends on component unount
componentDidMount() {
this.startLoop();
}
componentWillUnmount() {
this.stopLoop();
}
const categories = [
{
name: 'clothing',
category: null
},
{
name: 'adult',
category: 'clothing'
},
{
// [1] => 1
// [1, [2,3,4]] => [1,2,3,4]
// [1, [2,3, [4,5]]] => [1,2,3,4,5]
const flatten = (arr) =>
arr.reduce((acc, next) =>
acc.concat(Array.isArray(next) ? flatten(next) : next), []);
const data = [1, [2, 3, [4, 5]]];
flatten(data);
const trampoline = fn => (...args) => {
let result = fn(...args)
while (typeof result === 'function') {
result = result()
}
return result
}
// the trampoline wrapper function
const trampoline = fn => (...args) => {
let result = fn(...args)
while (typeof result === 'function') {
result = result()
}
return result
}
const countDown = (n) => {
const countDown = (n) => {
console.log(n);
return (n > 0) ? setTimeout(() => countDown(n - 1), 0) : n;
}
const num = 0;
countDown(num);
const countDown = (n) => {
console.log(n);
return (n > 0) ? countDown(n - 1) : n;
}
countDown(10);
import React from 'react';
import 'jest-styled-components';
import { ThemeProvider } from 'styled-components';
import renderer from 'react-test-renderer';
import { mount } from 'enzyme';
import SubmitBlock from '../SubmitBlock';
import { fashionTradeTheme as theme } from '../../../../constants/theme';
describe('snapshots', () => {
describe('it should render the compoent', () => {