Skip to content

Instantly share code, notes, and snippets.

@bgentry
bgentry / base_connection.rb
Last active May 10, 2019 05:23
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/
# 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 April 12, 2018 18:16
Ember identity map for ember-apollo-client models
// 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 August 9, 2019 10:57
graphql-ruby Pundit-based access control instrumentation
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 August 14, 2017 06:08
yarn.lock diff after regenerating dropped build time from 115s to 19s
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 February 19, 2017 06:59
XBee ZigBee HA interaction, Arduino example
/**
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 February 10, 2017 20:20
attempt to make graphql files available as ember imports
/* 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);
@bgentry
bgentry / components.one-way-input.js
Last active January 2, 2017 04:19 — forked from rwjblue/components.one-way-input.js
One Way Input with logging
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 November 29, 2016 18:53
ActionCable Sequel Postgres adapter
# 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 November 22, 2016 01:43 — forked from machty/controllers.application.js
repro of EC set on destroyed item
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 November 18, 2016 17:39
query redirects broken on beforeModel
import Ember from 'ember';
export default Ember.Controller.extend({
queryParams: 'timeframe',
timeframe: null
});