Skip to content

Instantly share code, notes, and snippets.

module GraphQL
module Relay
module Cursor
# The encoder/decoder for the cursor used in our smart GraphQL connections
class DefaultEngine
def encode(data)
Base64.strict_encode64(JSON.generate(data))
end
def decode(cursor)
@vickeryj
vickeryj / role_based_authorization.rb
Created March 6, 2018 20:30
role based field authorization
GraphQL::Field.accepts_definitions(
required_role: GraphQL::Define.assign_metadata_key(:required_role),
unauthorized_value: GraphQL::Define.assign_metadata_key(:unauthorized_value)
)
class RoleBasedAuthorization
def instrument(_type, field)
if field.metadata[:required_role]
old_resolve_proc = field.resolve_proc
new_resolve_proc = ->(obj, args, ctx) do
@caseywatts
caseywatts / 0 README.md
Last active June 1, 2018 22:18
d3 & c3 npm shim to es6 module for Ember
@viniciussbs
viniciussbs / 1-single-user.js
Last active February 9, 2017 23:27
Relay-style GraphQL pagination using Apollo Client on Ember (ember-apollo-client).
// app/routes/users/user.js
import Ember from 'ember';
import gql from 'graphql-tag';
import ObservableQuery from '../../mixins/observable-query';
const { Route } = Ember;
export default Route.extend(ObservableQuery, {
query: gql`
@djk447
djk447 / Implementing an Array-Based Timeseries Store in Postgres Part 2.md
Last active November 8, 2016 22:06
Timeseries are problematical in Postgres, here's part 2 of an attempt to make them a little less so.

#Implementing an Array-Based Timeseries Store in Postgres Part 2 See Part 1 here for an explanation of what we're up to. In this bit, I'll be taking this to a larger data store and seeing how the results scale. ##Data Setup and Recap of Part 1 The data is the same as from Part 1, except that we're now using a much larger data set. And we're only using the test2 table that I defined earlier. For a referesher, here's the original schema:

CREATE SCHEMA data;
CREATE TABLE data.generators (
    id          varchar primary key,
    ptid        int NOT NULL UNIQUE,
@djk447
djk447 / Implementing an Array-Based Timeseries Store in Postgres.md
Last active October 26, 2022 16:42
Implementing an Array-Based Timeseries Store in Postgres

#Implementing an Array-Based Timeseries Store in Postgres

UPDATE: This is Part 1, Part 2 is here, enjoy!

In response to Jim Nasby's question over at ElephantStack I thought I'd play around with the concept and see where it took me. Hoping to spark ideas from others on how to store things that have a column and row element more effectively with Postgres. ##Data Setup The data I’m using for this example is publicly available data from the NYISO historical data set located here: http://www.nyiso.com/public/markets_operations/market_data/custom_report/index.jsp?report=rt_lbmp_gen

It’s the real time location based marginal price of electricity at multiple generators in New York State. The tables I’ve used to store data from the NYISO site are below (I probably ought be using text instea

@pablobm
pablobm / README.md
Last active June 3, 2022 10:07
A clear convention for a CRUD with standard Ember + Ember Data

CRUD with Ember (+ Data)

Compatible with Ember 1.13.0+ Compatible with Ember Data 1.13.0+

Ember's official documentation describes a number of low-level APIs, but doesn't talk much about how to put them together. As a result, a simple task such as creating a simple CRUD application is not obvious to a newcomer.

@stevedomin
stevedomin / create_post.exs
Last active July 12, 2023 01:32
Using UUIDs as primary key with Ecto
defmodule MyBlog.Repo.Migrations.CreatePost do
use Ecto.Migration
def change do
create table(:posts, primary_key: false) do
add :id, :uuid, primary_key: true
add :body, :string
add :word_count, :integer
timestamps
@arenoir
arenoir / group-by.js
Last active March 26, 2016 21:39
Ember group by computed macro
import Ember from 'ember';
var get = Ember.get,
arrayComputed = Ember.arrayComputed;
export default function (dependentKey, property) {
var options = {
#compdef heroku
# generated from Heroku v2.4.0
# with these plugins: heroku-v3, old_plugins
_heroku() {
local -a app_argument
app_argument=('(-a --app)'{-a,--app}'[application name]:')
_heroku_commands() {