Skip to content

Instantly share code, notes, and snippets.

View carsonfarmer's full-sized avatar

carsonfarmer carsonfarmer

View GitHub Profile
@carsonfarmer
carsonfarmer / addFile.js
Created February 21, 2019 17:22
Working with Textile REST API from Javascript
/* eslint no-undef: "error" */
/* eslint-env browser */
import 'babel-polyfill'
import toposort from 'toposort'
import waterfall from 'async/waterfall'
const getThreadInfo = async (thread) => {
const threadId = thread || 'default'
return executeJsonCmd('GET', `${API}/threads/${threadId}`, { ctype: 'application/json' })
}
@carsonfarmer
carsonfarmer / Profile.js
Last active April 3, 2019 23:59
Profile Component
import React, { Component } from 'react'
import { observer, inject } from 'mobx-react'
import { Card, Icon, Image, Input, Form } from 'semantic-ui-react'
import Moment from 'react-moment'
@inject('store') @observer
class Profile extends Component {
handleUsername = e => {
e.preventDefault()
this.props.store.setProfile(this.inputRef.value, null)
@carsonfarmer
carsonfarmer / Store.js.diff
Last active April 3, 2019 23:58
Store Diff
diff --git a/src/Store.js b/src/Store.js
--- a/src/Store.js
+++ b/src/Store.js
@@ -1,7 +1,10 @@
-import { observe, action, observable } from 'mobx'
+import { observe, action, observable, runInAction } from 'mobx'
+import { utc } from 'moment'
import { Textile } from '@textile/js-http-client'
import { toast } from 'react-semantic-toasts'
@carsonfarmer
carsonfarmer / App.diff
Last active April 4, 2019 00:02
Full 'app' diff
diff --git a/src/Main.js b/src/Main.js
index a545559..e34f915 100644
--- a/src/Main.js
+++ b/src/Main.js
@@ -1,21 +1,11 @@
import React, { Component } from 'react'
import { observer, inject } from 'mobx-react'
-import { Image } from 'semantic-ui-react'
-// import Moment from 'react-moment'
-import * as Logo from './[email protected]'
@carsonfarmer
carsonfarmer / index.js
Created May 11, 2019 06:14
Initial stub cmd-line tool
#!/usr/bin/env node
const cli = require('cac')('txtl')
const { log } = console
// Create 'default' chat command
cli.command('', 'Starts an interactive chat session in a thread.')
.action((opts) => {
log('do something')
@carsonfarmer
carsonfarmer / step-two.diff
Created May 11, 2019 06:22
Adding some interactivity
diff --git a/index.js b/index.js
index 11b46ac..4cf1473 100644
--- a/index.js
+++ b/index.js
@@ -1,6 +1,7 @@
#!/usr/bin/env node
const cli = require('cac')('txtl')
+var readline = require('readline')
@carsonfarmer
carsonfarmer / step-three.diff
Created May 11, 2019 06:26
Adding some Textile functionality
diff --git a/index.js b/index.js
index 4cf1473..598b1d1 100644
--- a/index.js
+++ b/index.js
@@ -1,6 +1,7 @@
#!/usr/bin/env node
const cli = require('cac')('txtl')
+const textile = require('@textile/js-http-client').default
var readline = require('readline')
@carsonfarmer
carsonfarmer / step-four.diff
Created May 11, 2019 06:36
Flushing out the subscription step
diff --git a/index.js b/index.js
index 598b1d1..963d96f 100644
--- a/index.js
+++ b/index.js
@@ -31,7 +31,31 @@ cli.command('', 'Starts an interactive chat session in a thread.')
// Only subscribe to text events on the specified thread
textile.subscribe.stream(['TEXT'], opts.thread)
.then((stream) => {
- log('do something')
+ // All js-http-client stream endpoints return a ReadableSream
@carsonfarmer
carsonfarmer / step-five.diff
Created May 11, 2019 06:51
Adding some styling
diff --git a/index.js b/index.js
index 963d96f..6e7bfc1 100644
--- a/index.js
+++ b/index.js
@@ -3,6 +3,8 @@
const cli = require('cac')('txtl')
const textile = require('@textile/js-http-client').default
var readline = require('readline')
+const chalk = require('chalk')
+const { emojify } = require('node-emoji')
@carsonfarmer
carsonfarmer / index.ts
Created May 11, 2019 07:18
Typescript verison
#!/usr/bin/env node
import { cac } from 'cac'
import textile, { Block, FeedItem } from '@textile/js-http-client'
import readline from 'readline'
import chalk from 'chalk'
import { emojify } from 'node-emoji'
const cli = cac('txtl')
const { log } = console