Skip to content

Instantly share code, notes, and snippets.

@eldyvoon
eldyvoon / matrix_spiral.js
Created January 5, 2018 06:49
Matrix Spiral in JavaScript
//specs
matrix(2)
[[1,2],
[4,3]]
matrix(4)
[[1,2,3,4],
[12,13,14,5],
[11,16,15,6],
[10,9,8,7]]
@eldyvoon
eldyvoon / gist:179b70809ea644ce5269a02c833e200b
Created January 25, 2018 04:11
react-modal css scoping parentSelector
//util
export default getClassesFromNode = node => {
const classnames = node && node.className
let classnames_in_string = ''
classnames.split(' ').forEach(v=>{
classnames_in_string += '.' + v
})
return ()=>document.querySelector(classnames_in_string)
}
const moment = require('moment')
const crypto = require('crypto')
exports.sign = (req, res) => {
const s3Config = {
bucket: 'assets.example.com',
region: 's3-ap-southeast-1',
keyStart: 'uploads/',
params: {
acl: 'public-read',
@eldyvoon
eldyvoon / gist:87213c12a788feb8a3484ebf03311418
Created September 16, 2018 04:26
media query mixin scss/sass to avoid duplication
// variables.scss file
$breakpoints:(
sm: 640px,
md: 1200px,
lg: 1400px,
xl: 1900px
);
// mixins.scss file
@eldyvoon
eldyvoon / js
Created June 29, 2019 06:45
Users.js
import React, { useState, useEffect } from "react";
import axios from "axios";
import styled from "styled-components";
const Loader = styled.div``;
const Row = styled.li`
list-style: none;
margin: 10px;
`;
@eldyvoon
eldyvoon / js
Created June 29, 2019 06:47
axios.js
export default {
get: jest.fn().mockResolvedValue({ data: {} })
};
@eldyvoon
eldyvoon / js
Created June 29, 2019 06:52
jest.config.js
module.exports = {
setupFilesAfterEnv: ["@testing-library/react/cleanup-after-each"]
};
@eldyvoon
eldyvoon / js
Created June 29, 2019 07:03
Users.spec.js
import React from "react";
import { render, waitForElement } from "@testing-library/react";
import "jest-dom/extend-expect";
import axios from "axios";
import Users, { url } from "./Users";
test("show loader when it's fetching data, then render users' name on rows", async () => {
axios.get.mockResolvedValueOnce({
data: {
results: [
@eldyvoon
eldyvoon / js
Created June 29, 2019 07:07
Users.split.spec.js
import React from "react";
import { render, waitForElement } from "@testing-library/react";
import "jest-dom/extend-expect";
import axios from "axios";
import Users, { url } from "./Users";
afterEach(() => {
axios.get.mockClear();
});
const CounterHOC = ComposedComponent =>
class extends Component {
constructor(props) {
super(props);
this.state = {
count: props.initCounter
};
}