Skip to content

Instantly share code, notes, and snippets.

Avatar
🐰

Simon George sfcgeorge

🐰
View GitHub Profile
@sfcgeorge
sfcgeorge / scenic_view_sort_patch.rb
Created Dec 16, 2019
Patch 1 method in Scenic's schema dumper so that views are sorted first alphabetically, and then have any dependencies resolved.
View scenic_view_sort_patch.rb
# frozen_string_literal: true
require 'rails'
require 'scenic'
module Scenic
# @api private
module SchemaDumper
private
View keybase.md

Keybase proof

I hereby claim:

  • I am sfcgeorge on github.
  • I am sfcgeorge (https://keybase.io/sfcgeorge) on keybase.
  • I have a public key ASCbgmrBCz_87ERTRKj2j_VQgtSIRfLz4aUq7rXokPf-zwo

To claim this, I am signing this object:

@sfcgeorge
sfcgeorge / association_loader.rb
Created Sep 20, 2019
GraphQL Ruby Chain Loader
View association_loader.rb
# frozen_string_literal: true
# https://github.com/Shopify/graphql-batch/blob/master/examples/association_loader.rb
require 'graphql/batch'
class AssociationLoader < GraphQL::Batch::Loader
def initialize(association_name)
@association_name = association_name
end
@sfcgeorge
sfcgeorge / comparison.md
Created May 15, 2019
Mobile Frameworks Comparison
View comparison.md
Framework Multi platform Native code Native UI Native widgets Declarative UI Native UX
Native no yes yes yes no yes
Ruby Motion mobile yes yes yes no yes
Cordova mobile yes yes yes no yes
RNW yes no yes no yes with effort
NativeScript yes no yes no yes with effort
Flutter yes (web coming) yes yes no yes maybe
Cordova yes no no no yes no
@sfcgeorge
sfcgeorge / count_estimate.sql
Created Sep 14, 2018
Faster PostgreSQL COUNT function for large result sets by using query planner estimates.
View count_estimate.sql
CREATE FUNCTION count_estimate(query text) RETURNS integer AS $$
DECLARE
rec record;
rows integer;
row integer;
BEGIN
rows := 1;
FOR rec IN EXECUTE 'EXPLAIN ' || query LOOP
row := substring(rec."QUERY PLAN" FROM ' rows=([[:digit:]]+)')::integer;
IF (row != 0) THEN rows := rows * row; END IF;
View hyperloop_vs_rails_auth_example.md

Example Blog App with Auth

Pure Rails compared to Hyperloop

The purpose here is to show a high level overview of how Rails concepts map to Hyperloop concepts. It's not a full tutorial (I started doing that but it was way too long), but examples of key points.

Auth

Here's a simple auth example, with a comment showing all you have to add to hook it up to Hyperloop. In a production app you'd probably use Devise, but the Hyperloop acting_user bit would be the same!

@sfcgeorge
sfcgeorge / concern.rb
Last active Feb 7, 2018
Tweaked ActiveSupport::Concern to work around Opal issue
View concern.rb
module ActiveSupport
# A typical module looks like this:
#
# module M
# def self.included(base)
# base.extend ClassMethods
# base.class_eval do
# scope :disabled, -> { where(disabled: true) }
# end
# end
View telephone_words.rb
require "pp"
MAPPING = {
1 => [],
2 => %w(A B C),
3 => %w(D E F),
4 => %w(G H I),
5 => %w(J K L),
6 => %w(M N O),
7 => %w(P Q R S),
@sfcgeorge
sfcgeorge / json_slop.rb
Created Apr 11, 2017
Use JSON as a Ruby object like you just don't care, if you like OpenStruct you'll love JsonSlop!
View json_slop.rb
require "json"
class JsonSlop
def initialize(json)
@hash = json.is_a?(String) ? JSON.parse(json) : json
end
def call
JsonSlopProxy.new(@hash)
end
@sfcgeorge
sfcgeorge / opts_to_ivars.rb
Created Mar 17, 2016
Passing a lot of variables into a mailer that I want to access from the view, so decided to dynamically set the instance variables from opts
View opts_to_ivars.rb
class DynamicIvars
def greet(**options)
options.each { |k, v| instance_variable_set :"@#{k}", v }
p @hello
end
end
DynamicIvars.new.greet hello: "world"
# => "world"