Skip to content

Instantly share code, notes, and snippets.

View jhs's full-sized avatar

Jason Smith jhs

  • McKinsey & Company
  • New York, NY
View GitHub Profile
@jhs
jhs / app.js
Created June 15, 2016 07:28
How to use fun-pouchdb
var DB = require('fun-pouchdb').defaults({prefix: __dirname})
// Production app needs:
// 1. Validation functions
// 2. Cloudant credentials
// 3. Design documents
// Optional Cloudant credentials
var cloudant = {account:process.env.cloudant_account,
password:process.env.cloudant_password}
@jhs
jhs / gist:8381575
Created January 12, 2014 06:09
SSH public key
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAuWgWS41PlgjH1usjBOo6NFUoz8/g1HVZC6yBNP43vP2Iyajn8JkSLnLNkq72ndFQ9idZXjbfaJvxMWK8m5kBuiQm6EEws09jq7H5xtMY94nbhb+BCSO3sluuHw9hYlsEIWDHaegou5Y+UoyH1s8jsDggR7Wgv6TUp2RXdJ2ZO4zmLu72EJpYVx45iELxGmdxm9DE1FBNjZ33/i2T/5EpNyiFwVwA8pPfKTT42R2Wkig1aybc+wMoktBrcJ7JPgdu7qI+x8cz9fwm1r+Af2e8bTv+tQebFRukoej2DW+6pwDnTNJHrEz0zNVUVyyVfXTjWciK5T4IQq1Bp256sQcO8w== jhs@air.local
@jhs
jhs / README.md
Last active January 1, 2016 09:59
Next CouchDB changes feed project

Followers - The next-best thing to electroshock therapy.

Followers is a library to follow CouchDB changes feeds. In fact, the API is 100% identical to Follow, with a few differences.

  • Instead of a Feed class, there is a Socialist class
  • Instead of a "change" event, Followers emits a "socialist" event
  • Change objects do not have a .changes field, but rather a .socialists field.
# Pop up a message using notify-send or growlnotify. Example: n git push
popup() {
if [ -z "$notifier" ]; then
if which 'notify-send' >/dev/null 2>/dev/null; then
notifier='notify-send'
elif which growlnotify >/dev/null 2>/dev/null; then
notifier="growlnotify"
else
echo "popup error: cannot find notify-send or growlnotify" >&2
return 1
var bespoke = require('bespoke')
bespoke([
{ couch: "http://couch1", "pull_only":true },
{ couch: "http://couch2" },
{ couch: "http://couch3" "hub":true }
])
@jhs
jhs / style.js
Created December 14, 2013 08:43
var latest_found = null
for (var ver in doc.versions)
if (!latest_found || semver.gt(ver, latest_found))
latest_found = ver
jhs@air:~$ curl isaacs.ic.ht/registry/_design/app > app.json
jhs@air:~$ node -e 'app = JSON.parse(require("fs").readFileSync("app.json")); console.log(app.updates.package)' > package.js
jhs@air:~$ grep -A 10 'if(newdoc._attachments)' package.js
if(newdoc._attachments) {
var inline = false
for(var k in newdoc._attachments) {
if(newdoc._attachments[k].data) {
doc._attachments[k] = newdoc._attachments[k]
inline = true
}

If publishing your packages are b0rken

I (Jason) am very sorry but I will be offline for the next several hours and people still have busted conflicted npm packages. Here is a workaround.

The workaround is simply to touch your document over and over (i.e. GET and then PUT it back unchanged). You can use Futon https://isaacs.iriscouch.com/_utils/ and log in as your npm user, or use curl with basic auth, or write some JS even.

Once a doc revision has a longer change history, it becomes the winning revision and mostly shadows out all other revisions. That's good enough for npm. From there an npm publish —force usually puts things right I do not want to risk writing experimental code that is modifying and merging documents in an exhausted state. That's how things go from bad to worse.

-module(my_first_couchdb_plugin).
-export([handler/1]).
handler(Req) -> ok
, Bugs = couch_config:get("first", "enable_bugs", "false")
, {Code, Body} = case Bugs
of "false" -> ok
, {200, {[ {hello, <<"world">>} ]}}
; _ -> ok
@jhs
jhs / air.pub
Created September 13, 2013 04:27
Jason Smith keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAuWgWS41PlgjH1usjBOo6NFUoz8/g1HVZC6yBNP43vP2Iyajn8JkSLnLNkq72ndFQ9idZXjbfaJvxMWK8m5kBuiQm6EEws09jq7H5xtMY94nbhb+BCSO3sluuHw9hYlsEIWDHaegou5Y+UoyH1s8jsDggR7Wgv6TUp2RXdJ2ZO4zmLu72EJpYVx45iELxGmdxm9DE1FBNjZ33/i2T/5EpNyiFwVwA8pPfKTT42R2Wkig1aybc+wMoktBrcJ7JPgdu7qI+x8cz9fwm1r+Af2e8bTv+tQebFRukoej2DW+6pwDnTNJHrEz0zNVUVyyVfXTjWciK5T4IQq1Bp256sQcO8w== jhs@air.local