Skip to content

Instantly share code, notes, and snippets.

💯
crushing code

Steven Myers slmyers

💯
crushing code
Block or report user

Report or block slmyers

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
@slmyers
slmyers / schema.graphql
Last active Jul 27, 2019
lesson0 graphql schema
View schema.graphql
# this file was autogenerated by updateSchema.js
# yarn update:schema
type Mutation {
dummy: Boolean
}
"""An object with an ID"""
interface Node {
@slmyers
slmyers / index.md
Created Apr 1, 2019
State tracking for conditional rendering in form anti-pattern
View index.md

A common situation is rendering a form input iff some condition has been met. As an example, a user selects other from a gender dropdown and a text input is rendered so they can specify.

// how we commonly address this use-case
class Example extends React.Component {
  state = { gender: null } //tracking form state in component
  onGenderChange = e => this.setState({ gender: e.target.value }) //updating form state outside of form
  render() {
    const { gender } = this.state
@slmyers
slmyers / server.js
Created Aug 30, 2018
Example of running https server with node.
View server.js
const http = require('http');
const https = require('https');
const fs = require('fs');
const App = require('./App');
const httpsOpts = {
key: fs.readFileSync("../certs/key.pem", "utf8"),
cert: fs.readFileSync("../certs/server.crt", "utf8")
};
http.createServer(App).listen(3000, () => console.log("The http server is listening on port 3000."));
@slmyers
slmyers / IncomingMessages.js
Last active Aug 12, 2018
Apollo client link example
View IncomingMessages.js
import React, { Component } from "react"
import logo from '../logo.svg';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
import Avatar from '@material-ui/core/Avatar';
import { GET_MESSAGES } from "../GraphQL"
import { Query } from 'react-apollo';
export default class extends Component {
render(){
@slmyers
slmyers / State.js
Last active Aug 12, 2018
Apollo client link example
View State.js
import { ApolloClient } from 'apollo-client';
import { withClientState } from 'apollo-link-state';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { resolvers, defaults } from './resolvers/message';
const typeDefs = `
interface Node {
id: ID!
}
@slmyers
slmyers / resolvers.js
Last active Aug 12, 2018
Apollo Client Link example
View resolvers.js
import gql from 'graphql-tag';
export const defaults = {
messages: []
};
export const resolvers = {
Mutation: {
addMessage: (_, { content, author }, { cache }) => {
const query = gql`
@slmyers
slmyers / coverage.js
Created Feb 26, 2018 — forked from ebidel/coverage.js
CSS/JS code coverage during lifecycle of page load
View coverage.js
/**
* @author ebidel@ (Eric Bidelman)
* License Apache-2.0
*
* Shows how to use Puppeeteer's code coverage API to measure CSS/JS coverage across
* different points of time during loading. Great for determining if a lazy loading strategy
* is paying off or working correctly.
*
* Install:
* npm i puppeteer chalk cli-table
@slmyers
slmyers / my-component.ts
Created Jul 27, 2017
my-example-angular-component
View my-component.ts
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'my-component',
styleUrls: './my-component.css',
template: `
<button [style.color]="color" (click)="bar.emit('bar')"> {{ foo }} </button>
`
})
export class MyComponent implements OnInit{
@slmyers
slmyers / recursion.md
Last active Apr 15, 2017
Novosbed Inc application questions
View recursion.md

In the context of Computer Science recursion refers to a function that calls itself in order to arrive at a return value. In order to avoid infinite recursion (infinite loop) a base case is established which does not have a recursive call. This
solution is typically employed in Divide and Conquer algorithms or where recursion is more elegant than a loop. A common example is calculating a number's factorial. Here is an example written in es6.

const factorial = number => number === 1 ? 1 : number * factorial(number - 1);
@slmyers
slmyers / lumen.lua
Created Mar 18, 2017 — forked from anonymous/lumen.lua
Self-hosted Lisp using vvander's Lua browser runtime: https://cdn.rawgit.com/vvanders/wasm_lua/d68f46a8/main.html
View lumen.lua
environment = {{}}
target = "lua"
function nil63(x)
return(x == nil)
end
function is63(x)
return(not nil63(x))
end
function no(x)
return(nil63(x) or x == false)
You can’t perform that action at this time.