Skip to content

Instantly share code, notes, and snippets.

@bgentry
bgentry / base_connection.rb
Last active May 10, 2019
graphql-ruby class-based Relay connections + edges, with totalCount field on all connections. Adapted from http://rmosolgo.github.io/blog/2018/04/09/updating-github-to-graphql-1-dot-8-0/
View base_connection.rb
# frozen_string_literal: true
module Types
class BaseConnection < BaseObject
# For some reason these are needed, they call through to the underlying connection wrapper.
extend Forwardable
def_delegators :@object, :cursor_from_node, :parent
# When this class is extended, add the default connection behaviors.
# This adds a new `graphql_name` and description, and searches
@bgentry
bgentry / app_models_batch.js
Created Apr 12, 2018
Ember identity map for ember-apollo-client models
View app_models_batch.js
// this is an example model
import ObjectProxy from "@ember/object/proxy";
function objectEqual(a, b) {
if (typeOf(a) === "instance" || typeOf(b) === "instance") {
return isEqual(a, b);
} else if (typeOf(a) === "object" && typeOf(b) === "object") {
return Object.entries(a).every(([propname, value]) => {
return b[propname] === value;
@bgentry
bgentry / access_instrumentation.rb
Last active Aug 9, 2019
graphql-ruby Pundit-based access control instrumentation
View access_instrumentation.rb
class FieldAccessInstrumentation
attr_reader :current_user_key
def initialize(current_user_key = :current_user)
@current_user_key = current_user_key
end
def instrument(type, field)
field = instrument_type(type, field) if type.metadata[:access]
# only add the field access check if it exists and isn't identical to the
@bgentry
bgentry / yarn.lock.diff
Created Aug 14, 2017
yarn.lock diff after regenerating dropped build time from 115s to 19s
View yarn.lock.diff
diff --git a/yarn.lock b/yarn.lock
index 72eb98e..912a492 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -48,9 +48,9 @@
dependencies:
"@glimmer/util" "^0.22.3"
-"@glimmer/resolver@^0.3.0":
- version "0.3.0"
@bgentry
bgentry / xbee.ino
Created Feb 19, 2017
XBee ZigBee HA interaction, Arduino example
View xbee.ino
/**
This is an implementation of Zigbee device communication using an XBee
and a Centralite Smart Switch 4256050-ZHAC
dave (www.desert-home.com)
source: http://www.desert-home.com/2014/10/zigbee-protocol-xbee-but-this-time.html
*/
// This code will handle both a Uno and a Mega2560 by careful use of
// the defines. I tried it on both of them, and the only problem is that
@bgentry
bgentry / ember-cli-build.js
Created Feb 10, 2017
attempt to make graphql files available as ember imports
View ember-cli-build.js
/* global require, module */
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
var Filter = require('broccoli-filter');
var Funnel = require('broccoli-funnel');
module.exports = function(defaults) {
var env = EmberApp.env();
var isProductionLikeBuild = ['production', 'staging'].indexOf(env) > -1;
var ENV = defaults.project.config(env);
View components.one-way-input.js
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'input',
attributeBindings: [ 'type', 'value', 'placeholder', 'data-stripe', 'name' ],
type: 'text',
_sanitizedValue: undefined,
input() { this._handleChangeEvent(); },
change() { this._handleChangeEvent(); },
@bgentry
bgentry / postgresql_sequel.rb
Created Nov 29, 2016
ActionCable Sequel Postgres adapter
View postgresql_sequel.rb
# forked from:
# https://github.com/rails/rails/blob/a373be9da45d4bee684ea03420212780ec1ef4b1/actioncable/lib/action_cable/subscription_adapter/postgresql.rb
gem 'pg', '~> 0.18'
require 'pg'
require 'thread'
module ActionCable
module SubscriptionAdapter
class PostgresqlSequel < Base # :nodoc:
@bgentry
bgentry / components.person-item.js
Last active Nov 22, 2016 — forked from machty/controllers.application.js
repro of EC set on destroyed item
View components.person-item.js
import Ember from 'ember';
import { task } from 'ember-concurrency';
const PersonItem = Ember.Component.extend({
person: null,
editMode: false,
changePerson: null,
latestPost: Ember.computed.oneWay('person.latestPost'),
@bgentry
bgentry / controllers.application.js
Last active Nov 18, 2016
query redirects broken on beforeModel
View controllers.application.js
import Ember from 'ember';
export default Ember.Controller.extend({
queryParams: 'timeframe',
timeframe: null
});