Skip to content

Instantly share code, notes, and snippets.

View anthify's full-sized avatar
💻
coding

Anthony O'Neill anthify

💻
coding
View GitHub Profile
@anthify
anthify / find-dead-css.js
Created April 18, 2016 16:10 — forked from byrichardpowell/find-dead-css.js
Super simple node script to find CSS that is no longer in use. The results should be considered as safe as a global find and replace (not very), so use your judgement
var walk = require('walk');
var fs = require('fs');
var classesOrIds = [];
var viewsAndTemplates = []
var walkers = [];
var maybeUnusedClassesOrIds = [];
var compleWalkersCount = 0;
var classesToFileMap = {}
// Calback Function every time a walker ends
@anthify
anthify / parseRGBString.js
Last active April 8, 2019 09:38
Converts RGB/RGBA string to object
// pass a rgb/rgba string value into this function i.e. rgb(0,0,0)
// and it will return an object of { r: 0, g: 0, b: 0, a: 1 }
const parseRGBString = str => {
const vals = str.substring(str.indexOf('(') + 1, str.length - 1).split(', ');
const colors = {
r: parseInt(vals[0], 10),
g: parseInt(vals[1], 10),
b: parseInt(vals[2], 10),
a: parseFloat(vals[3])
@anthify
anthify / asyncForeach.js
Last active April 8, 2019 08:18
Async Await forEach loop
export default async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
};
// example
import forEach from '.';
const paths = [...];
@anthify
anthify / asyncDelay.js
Created April 8, 2019 08:20
Async Await Delay
export default time =>
new Promise(resolve => setTimeout(() => resolve(), time));
// example
import delay from '.'
const stopAndStart = async () => {
console.log('👋');
await delay(1000);
console.log('🕐, one second later');
@anthify
anthify / checkered-alpha-background.css
Created April 8, 2019 09:09
Checked Alpha Background
.chacked-alpha-background {
background-image:
-webkit-gradient(linear, 0 100%, 100% 0, color-stop(.25, #ccc), color-stop(.25, transparent)),
-webkit-gradient(linear, 0 0, 100% 100%, color-stop(.25, #ccc), color-stop(.25, transparent)),
-webkit-gradient(linear, 0 100%, 100% 0, color-stop(.75, transparent), color-stop(.75, #ccc)),
-webkit-gradient(linear, 0 0, 100% 100%, color-stop(.75, transparent), color-stop(.75, #ccc));
background-size: 30px 30px;
background-position: 0 0, 15px 0, 15px -15px, 0px 15px;
background-color: white;
}
@anthify
anthify / pipe.js
Created May 2, 2019 07:18
Pipe function
export default (...fns) => x => fns.reduce((v, f) => f(v), x);
@anthify
anthify / .eslintrc
Last active May 3, 2019 08:11
React web app lint setup
{
"extends": ["airbnb", "prettier", "prettier/react"],
"parserOptions": {
"sourceType": "module",
"allowImportExportEverywhere": true
},
"env": {
"browser": true,
"node": true,
"jest": true
@anthify
anthify / enzyme-helper.js
Created July 17, 2019 08:45
Wrapper for Enzyme and Styled Components
import React from 'react';
import { ThemeConsumer } from 'styled-components';
import { mount } from 'enzyme';
import theme from '../../app/theme';
/**
* find is object to provide quick short end element selectors
*/
export const find = subject => ({
attr: (attr, value, el = '') => subject.find(`${el}[${attr}="${value}"]`),
@anthify
anthify / rockpaperscissors.js
Created August 9, 2019 10:18
Rock, Paper, Scissors!
const rockPaperScissors = usersHand => {
let computersHand;
let result;
// logic
return `
You ${result}, computer picked ${computersHand}
`;
}
@anthify
anthify / rockpaperscissors.js
Created August 9, 2019 15:51
Solution: Rock, Paper, Scissors
const game = {
choices: ["rock", "paper", "scissors"],
rock: "scissors",
paper: "rock",
scissors: "paper"
};
const play = playerChoice => {
if (!game.choices.includes(playerChoice)) {
return `Player hasn't selected valid choice`;