Skip to content

Instantly share code, notes, and snippets.

🤠
coding like crazy

Zach Silveira zackify

🤠
coding like crazy
Block or report user

Report or block zackify

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View fetch.js
export const api = ({ url, headers = {}, body, method }) =>
new Promise(async (resolve, reject) => {
try {
body = JSON.stringify(body);
headers['Content-Type'] = 'application/json';
} catch (e) {}
//intercept before if i want
let token = await storage.get('userToken')
headers.Authorization = token
@zackify
zackify / create-cert.md
Last active Oct 14, 2019
Create cert for webpack in one command, mac
View create-cert.md
"create-cert": "bash -c \"openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout config/server.key -out config/server.crt -subj \"/C=US/ST=Nevada/L=test/O=test/OU=Software/CN=localhost\" -extensions san -config <(echo '[req]'; echo 'distinguished_name=req'; echo '[san]'; echo 'subjectAltName=DNS:localhost,IP:127.0.0.1') && sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain config/server.crt\"",

View authenticated.js
import { mapValues } from 'lodash';
const authCheck = (resolver, isPublic) => (parent, args, context, info) => {
if (isPublic || context.user) {
return resolver(parent, args, context, info);
}
return ApolloError({ code: 401 });
};
export default (resolvers, publicResolvers = []) =>
@zackify
zackify / hook.js
Last active Jan 30, 2019
React hook that triggers one time, when an element becomes visible on the screen
View hook.js
//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 Apr 15, 2018
Quickstart gutenblock (docker-compose up and it will sync blocks folder)
View docker-compose.yml
version: '3.3'
services:
db:
image: mysql:latest
volumes:
- dbdata:/var/lib/mysql
restart: always
ports:
- "3306:3306"
View post.js
import React from 'react';
import styles from './styles.css';
export default ({ title, }) => (
<section className={styles.wrapper}>
{title}
</section>
);
/*
View 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]
View tsconfig.json
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "es2015",
"moduleResolution": "node",
"target": "es5",
"jsx": "react",
"allowJs": true,
View table.js
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})
View toggle.js
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>
)
You can’t perform that action at this time.