Skip to content

Instantly share code, notes, and snippets.

View RichardLitt's full-sized avatar

Richard Littauer RichardLitt

View GitHub Profile
@RichardLitt
RichardLitt / README.md
Created September 25, 2015 00:53
archive-format readme.

archive-format

This is a discussion repo for creating a spec and implemenation of an IPFS archive format. Please see the issues to join the conversation.

@RichardLitt
RichardLitt / gist:87ff56363343bd4e745d
Last active August 29, 2015 14:28
Array iterators and async
var readPDFText = function (documentObject, options, cb) {
if (!documentObject) throw new Error('No pdf provided')
// For each page
async.map(
pdfjs.getDocument(documentObject).then(function (pdf) {
// Get all of the apges
async.times(pdf.numPages, function (pageNum, callback) {
pdf.getPage(pageNum + 1).then(function (page) {
// Get all of the strings on the page
module.exports.getConversationPosts = exports.getConversationPosts = function getConversationPosts (conversation, cb) {
return db.query(function (doc) {
if (doc.conversation && doc.type && doc.type === 'note') {
emit(doc.conversation)
}
}, {include_docs: true, key: conversation.id}).then(function (response) {
// TODO This shouldn't be needed, the query should be doing this for us.
// Actually, this isn't working at all. The conversation.id is undefined.
console.log('conversation', response, conversation.id)
return _.filter(justTheDocs(response), function (doc) {
@RichardLitt
RichardLitt / gist:90243a2dfa0ed5785e75
Last active August 29, 2015 14:25
Why are new props not being rerendered?
var React = require('react/addons')
var PouchDBUrl = require('../env.js').PouchDBUrl
var PouchDB = require('pouchdb')
PouchDB.plugin(require('pouchdb-authentication'))
var db = new PouchDB(PouchDBUrl)
var _ = require('lodash')
// TODO: On Load:
// Get the conversations needed -- Pass these through to the component
// Get the date of the first (or last?) note in each conversation
module.exports.getConversationsForUser = function (user, cb) {
db.query(function (doc) {
if (doc.author === user.userId) {
emit(doc)
}
}.bind(this), {include_docs: true}).then(function (response) {
console.log('response', response)
cb(null, response)
}).catch(function (err) {
cb(err)
componentWillMount: function () {
let dummyImage = 'http://upload.wikimedia.org/wikipedia/en/4/42/Richard_Feynman_Nobel.jpg'
let userPromises = []
let clone = _.each(this.state.conversations.slice(), function (conversation) {
conversation.avatars = []
_.each(_.keys(conversation.participants), function (key) {
if (conversation.participants.hasOwnProperty(key)) {
// Suggestion: Only show avatars for participants who have actively contributed to conversation
let getAvatar = db.getUser(key).then(function (err, res) {
if (res.avatar) {
@RichardLitt
RichardLitt / gist:d668e99f9566dcf386fb
Created April 30, 2015 14:58
Shell script for local node modules
cd ..
printf 'cd to' && pwd
echo 'Cloning BeagleLab/beagle-style'
git clone git@github.com:BeagleLab/beagle-style.git
cd beagle-style
echo 'Installing modules...'
npm install
cd ..
echo 'Cloning BeagleLab/beagle-pdf'
git clone git@github.com:BeagleLab/beagle-pdf.git
# 2015 April 16th
What am I trying to do?
I have a Chrome extension and I want to implement OAuth in it so that users can be authenticated and have accounts.
So, first, I need users. The user objects shouldn’t be too hard to implement. Juan sent me a way to do it.
Then, I need to figure out how to use Google OAuth. Actually, this doesn’t require me hitting the API for the Google Contacts I need, I believe - I should be able to just use Google OAuth before I hit the API, as that is actually a separate concern.
@RichardLitt
RichardLitt / gist:4e2f86e68b6b743a9ccf
Created April 10, 2015 02:17
db.put not returning response
db.get(documentId).then(function (value) {
// if (err && err.name !== 'not_found') {
// return console.log('Failed to get ' + documentId + 'from db', err)
// }
/* Instantiate the object if it doesn't exist yet */
value = value || {}
value._id = documentId
/* Add in the selection to the selections array */
// Initiation of browserify object
var b = browserify({
// Required watchify args
'cache': {},
'packageCache': {},
'fullPaths': true,
// Browserify options
'entries': [paths.jsPath + 'main.js'],
'noParse': ['react.js', 'jquery.js', 'pdf.combined.js'],
'transform': [reactify]