Skip to content

Instantly share code, notes, and snippets.

View ryardley's full-sized avatar

гλ ryardley

View GitHub Profile
import React from 'react';
import useFriendStatus from './useFriendStatus';
export default function FriendListItem(props) {
const isOnline = useFriendStatus(props.friend.id);
return (
<li style={{ color: isOnline ? 'green' : 'black' }}>
{props.friend.name}
</li>
const Comments = ({ repoFullName }) => (
<Mutation mutation={DELETE_COMMENT}>
{(deleteComment) => (
<Query query={GET_CURRENT_USER}>
{({data: {currentUser}}) => (
<Subscription
subscription={COMMENTS_SUBSCRIPTION}
variables={{ repoFullName }}>
{({ data: { commentAdded }, loading }) => (
<div>
// This function takes a component...
function withSubscription(WrappedComponent, selectData) {
// ...and returns another component...
return class extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.state = {
data: selectData(DataSource, props)
};
@ryardley
ryardley / mixin-example.jsx
Created October 28, 2018 05:52
An example of the old React mixin API
import React from 'react';
// numberBehaviour.js
const numberBehaviour = {
getInitialState() {
return {
newNumber: 1
}
},
setNewNumber(num) {
@ryardley
ryardley / hooks-example.jsx
Last active March 23, 2020 17:06
An example of the basic hooks api.
import { useState } from 'react';
function Example() {
// Declare a new state variable, which we'll call "count"
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count => count + 1)}>
@ryardley
ryardley / telnet-imap
Created May 21, 2018 10:34 — forked from gustavohenrique/telnet-imap
playing with gmail via telnet
openssl s_client -crlf -connect imap.gmail.com:993
tag login [email protected] passwordhere
tag list "" "*"
tag select "inbox"
tag fetch 1:3 body[header]
tag fetch 3 body[header]
tag fetch 3 body[text]
tag fetch 2 all
tag fetch 2 fast
tag fetch 2 full
@ryardley
ryardley / grid-bookmarklet.js
Last active April 21, 2017 04:12 — forked from michaeltaranto/bookmarklet.js
Baseline Bookmarklet
javascript:(function () {
var BASE_PIXELS = 8;
var baselineNode = document.querySelector(".baseliner-overlay");
if (baselineNode) {
baselineNode.remove();
return;
}
var body = document.body,
html = document.documentElement,
height = Math.max(body.scrollHeight, body.offsetHeight,
// ======================================
// HIGHER ORDER CURRIED ARROW FUNCTIONS
// ======================================
// Double arrows are great for creating functions
// that dont need all their arguments at once
// This is best for functions that need configuration
// before running on an active value.
// So here we have a function called
import React, { Component } from 'react';
import './App.css';
const SORT_UP = 'up';
const SORT_DOWN = 'down';
function alphanumeric(a,b){
if(a === b){ return 0; }
return a > b ? 1 : 0;
}
@ryardley
ryardley / keystone_roles_permissions.md
Created August 28, 2016 01:20 — forked from webteckie/keystone_roles_permissions.md
Keystone Roles and Permissions

Keystone Roles & Permissions Support

The following documents the user permission support in keystone based on the support being added via PR #2111. Permissions are based on roles. If a user has a role and the list also specifies that role for any of its CRUD operations then it is permissive for the user to perform whichever CRUD operation matches the role. All users must define, at least, one role. The following are guidelines for adding role/permission support to your application:

Define a Role List Model: