Skip to content

Instantly share code, notes, and snippets.

View ericeslinger's full-sized avatar

Eric Eslinger ericeslinger

View GitHub Profile
@ericeslinger
ericeslinger / README.md
Last active May 27, 2016 01:28
Convert an HTML string into a rich-text delta using node.js and jsdom

This is a really ugly hack, but it works well enough for me to do as a one-off to convert a bunch of data from html strings into rich-text objects. I had originally stored my data in the long_text column as an html string, and now I want to store the raw JSON version of the same data in the rich_text column.

This is really just a demo of the idea, but if it helps anyone, I'll be happy that it does.

@ericeslinger
ericeslinger / Client Updates with Listen - Notify in PostgreSQL.md
Last active October 6, 2016 13:04
Postgres Listen/Notify for automatic updates

Listen / Notify for automatic object updates - pattern in postgreSQL Presented at the San Francsico PostgreSQL User Group Meetup 8/17/15

by Eric Eslinger [email protected] github.com/ericeslinger

This example uses listen/notify calls in PostgreSQL that trigger on row update to pass events from the database to a listening node.js web application that in turn uses socket.io to pass events

@ericeslinger
ericeslinger / authenticate.js
Last active August 29, 2015 14:15
angular token authentication
// based heavily on https://github.com/witoldsz/angular-http-auth/blob/master/src/http-auth-interceptor.js
var buffer401 = [];
angular.module('app.model').config(function($httpProvider) {
$httpProvider.interceptors.push(function($rootScope, $q) {
return {
responseError: function(rejection) {
if (rejection.status === 401) {
return $q(function(resolve, reject) {
@ericeslinger
ericeslinger / batchRequest.coffee
Last active August 29, 2015 14:05
Batch loader with bassmaster
angular.module 'clientApp.apiModel.batchRequest', ['ng']
.service 'BatchRequest', ($q, Server, $http, $timeout)->
timeoutPromise = undefined
queue = []
postBatch = ->
requestQueue = queue.map (req)-> {method: 'GET', path: req.url, deferred: req.deferred}
queue = []
timeoutPromise = undefined
$http
method: 'POST'
@ericeslinger
ericeslinger / document.coffee
Last active May 13, 2016 21:09
Add side-loads to BookshelfJS
Knex = require 'knex'
Promise = require 'bluebird'
FlormModel = require './flormModel'
Document = FlormModel.extend
tableName: 'documents'
# here's an example sideload construct. I want to know document editor ids, which are stored in the
# edges join table - that table stores parent_id and child_id polymorphically (with parent_type and child_type)
# also polymorphically with join type- 'grant: edit' denotes editorship.
#!/bin/sh
# http://stackoverflow.com/questions/3878624/how-do-i-programmatically-determine-if-there-are-uncommited-changes
require_clean_work_tree () {
# Update the index
git update-index -q --ignore-submodules --refresh
err=0
# Disallow unstaged changes in the working tree
if ! git diff-files --quiet --ignore-submodules --; then