Skip to content

Instantly share code, notes, and snippets.

View peterj's full-sized avatar
🌟
....

Peter Jausovec peterj

🌟
....
View GitHub Profile
@peterj
peterj / snippet.js
Last active December 29, 2017 18:22
import gql from 'graphql-tag';
import { graphql } from 'react-apollo';
const CREATE_SHORT_LINK_MUTATION = gql`
mutation CreateLinkMutation($url: String!, $description: String!, $hash: String!) {
createLink(url: $url, description: $description, hash: $hash) {
id
}
}
`;
createHash = (itemCount) => {
let hashDigits = [];
// dividend is a unique integer (in our case, number of links)
let dividend = itemCount + 1;
let remainder = 0;
while (dividend > 0) {
remainder = dividend % 62;
dividend = Math.floor(dividend / 62);
hashDigits.unshift(remainder);
}
import React, { Component } from 'react';
import LinkList from './components/LinkList';
import CreateShortLink from './components/CreateShortLink';
class App extends Component {
render() {
return (
<div>
<div>
<h2>All links</h2>
const LINKS_SUBSCRIPTION = gql`
subscription NewLinkCreatedSubscription {
Link(filter: { mutation_in: [CREATED] }) {
node {
id
url
description
hash
}
}
componentDidMount() {
this.props.allLinksQuery.subscribeToMore({
document: LINKS_SUBSCRIPTION,
updateQuery: (prev, { subscriptionData }) => {
const newLinks = [
...prev.allLinks,
subscriptionData.data.Link.node,
];
const result = {
...prev,
@peterj
peterj / samplelog
Created December 30, 2017 21:43
samplelog
2017-12-30T21:40:11.541Z 2149ms SUCCESS {
"event": {
"data": {
"Link": {
"node": {
"id": "cjbtvf0qsx2w1012100gk57ka"
}
}
},
"context": {
const { fromEvent } = require('graphcool-lib');
const createHash = itemCount => {
let hashDigits = [];
// dividend is a unique integer (in our case, number of links)
let dividend = itemCount + 1;
let remainder = 0;
while (dividend > 0) {
remainder = dividend % 62;
dividend = Math.floor(dividend / 62);
import React from 'react';
import { Switch, BrowserRouter, Route } from 'react-router-dom';
import Home from './Home';
const AppRouter = () => (
<BrowserRouter>
<Route exact path="/" component={Home} />
</BrowserRouter>
);