Skip to content

Instantly share code, notes, and snippets.

View RyanCCollins's full-sized avatar

Ryan Collins RyanCCollins

View GitHub Profile
field :authUser, AuthUserType do
argument :auth_token, !types.String
resolve -> (obj, args, ctx) do
User.find_by(auth_token: args[:auth_token])
end
end
AuthUserType = GraphQL::ObjectType.define do
name 'AuthUser'
description 'The authenticated user model type'
field :id, types.ID, 'The id of this user'
field :name, !types.String, 'The name of the user'
field :email, !types.String, 'The email of the user'
field :bio, types.String, 'The bio of the user'
field :created_at, types.String, 'The datetime string when the user was created'
field :events, types[EventType], 'The user events'
field :avatar, types.String, 'The user avatar'
@RyanCCollins
RyanCCollins / routes.rb
Created October 11, 2016 23:51
GraphQL, Rails, React
Rails.application.routes.draw do
devise_for :users
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/api"
root to: redirect("/graphiql")
resources :api
end
class ApiController < ApplicationController
def create
query_string = params[:query]
query_variables = ensure_hash(params[:variables])
result = MeetupEventPlannerSchema.execute(
query_string,
variables: query_variables,
context: { }
)
render json: result
@RyanCCollins
RyanCCollins / readme.md
Last active October 1, 2016 04:37
Maybe and other functors JavaScript
var _Maybe = function(val) {
  this.val = val;
}

var map = function(f, obj) {
  return obj.map(f);
}

var Maybe = function(x) {
@RyanCCollins
RyanCCollins / ex1-prototype-style.js
Created September 30, 2016 03:47 — forked from getify/ex1-prototype-style.js
OLOO (objects linked to other objects) pattern explored (with comparison to the prototype style of the same code)
function Foo(who) {
this.me = who;
}
Foo.prototype.identify = function() {
return "I am " + this.me;
};
function Bar(who) {
Foo.call(this,"Bar:" + who);
@RyanCCollins
RyanCCollins / oolo.md
Last active September 30, 2016 03:38
OOLO
var Foo = {
  init: function(who) {
    this.me = who;
  },
  identify: function() {
    return "I am " + this.me;
  }
}

Node configuration.

Update NPM version with the following command

npm update -g npm

Download NVM (Node Version Manager), which will help you to use the correct version of NodeJS

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh | bash
@RyanCCollins
RyanCCollins / this-binding.md
Created September 26, 2016 04:42
This binding, how JavaScript does it.
  1. Was the object called with the new keyword, if so use the newly created object.
  2. Was the object called with Call or Apply? If so, use that object.
  3. Was the object called by a containing / owning object? If so, use it.
  4. Default to the global.
@RyanCCollins
RyanCCollins / array-from-range.md
Created September 2, 2016 02:57
Create an array of 1 through n numbers in one line of JS

Create an array of numbers 1 to N

const N = 20;
Array.apply(null, { length: N }).map(Number.call, Number)

Another option

const arrayOfRange = (n) =&gt; Array(n).join().split(',').map((_, i) =&gt; i);