Skip to content

Instantly share code, notes, and snippets.

View zackify's full-sized avatar
🤠
coding like crazy

Zach Silveira zackify

🤠
coding like crazy
View GitHub Profile
@zackify
zackify / hook.js
Last active January 30, 2019 01:31
React hook that triggers one time, when an element becomes visible on the screen
//Copied from SO checking if an element is in view
const checkIfInView = (elementPosition, extraOffset) =>
elementPosition.top >= 0 &&
elementPosition.left >= 0 &&
elementPosition.bottom + extraOffset <=
(window.innerHeight || document.documentElement.clientHeight) &&
elementPosition.right + extraOffset <=
(window.innerWidth || document.documentElement.clientWidth);
//React hook that sets state when in view
@zackify
zackify / docker-compose.yml
Created April 15, 2018 18:17
Quickstart gutenblock (docker-compose up and it will sync blocks folder)
version: '3.3'
services:
db:
image: mysql:latest
volumes:
- dbdata:/var/lib/mysql
restart: always
ports:
- "3306:3306"
import React from 'react';
import styles from './styles.css';
export default ({ title, }) => (
<section className={styles.wrapper}>
{title}
</section>
);
/*
@zackify
zackify / mock.js
Last active March 11, 2018 22:43
mock.js
const getAppointments = Appointment => () => {
return Appointment.joins(:customer).where('customers.pays_a_lot = true').includes(:customer).order_by('customers.age DESC')
}
const dbmock = fakes => new Proxy({}, {
get: (target, name) => {
if(!fakes[name]) return this
return fakes[name]
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "es2015",
"moduleResolution": "node",
"target": "es5",
"jsx": "react",
"allowJs": true,
const beforeInsert = ({ values, state }) => {
if(state.deleted) values.deleted_at = Date.now()
return values
}
const conversions = {
column_one: ({value, setState}) => {
if(value.match(/zz/)) setState({ deleted: true})
return (
<Toggle>
<p toggle>some text you click to toggle</p>
<div on>if on, this renders!</div>
<div off>if off, this renders!</div>
</Toggle>
)
@zackify
zackify / setup.js
Created March 27, 2017 14:58
Global test helpers
//Useful helpers for async await in tests
global.sleep = time =>
new Promise(resolve => setTimeout(() => resolve(), time));
global.waitFor = (value, equal) =>
new Promise(resolve =>
setInterval(
() => {
if (value === equal) resolve(value);
@zackify
zackify / link.js
Created February 19, 2017 17:08
Async link and route components that wait for the bundle (no route change -> empty content -> bundle loads -> page content is now there)
@zackify
zackify / test.php
Last active February 8, 2017 15:26
public function __construct(Book $bookModel, BookTransformer $transformer)
{
parent::__construct();
$this->transmit = [
'transformer' => $transformer,
'model' => $bookModel,
];
}