Skip to content

Instantly share code, notes, and snippets.

View ryardley's full-sized avatar

гλ ryardley

View GitHub Profile
// ======================================
// 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
@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,
@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 / 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 / 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) {
// 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)
};
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>
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>
<DataProvider render={data => (
<h1>Hello {data.target}</h1>
)}/>
let state = [];
let setters = [];
let firstRun = true;
let cursor = 0;
function createSetter(cursor) {
return function setterWithCursor(newVal) {
state[cursor] = newVal;
};
}