Skip to content

Instantly share code, notes, and snippets.

View sfcgeorge's full-sized avatar
🦔

Simon George sfcgeorge

🦔
View GitHub Profile
@sfcgeorge
sfcgeorge / scenic_view_sort_patch.rb
Created December 16, 2019 11:05
Patch 1 method in Scenic's schema dumper so that views are sorted first alphabetically, and then have any dependencies resolved.
# frozen_string_literal: true
require 'rails'
require 'scenic'
module Scenic
# @api private
module SchemaDumper
private
@sfcgeorge
sfcgeorge / wcg_ascii.txt
Last active January 11, 2022 09:09
Classic river crossing problem with both Python and Ruby implementations and ASCII output.
_##_
(..)
/ ~ \
|| ||
m|||m
|||
n^n
_.
)''
# This is the original algorithm with some renaming for clarity.
# DFS recursive function returns true if a matching for a_index is possible
def mcbm_can_match(graph, a_index, matches, seen):
# Try every resource one by one
for r_index in range(len(graph[0])):
# If resource at r_index can do assignment and assignment is not seen
if graph[a_index][r_index] and seen[r_index] == False:
# Mark resource as visited
seen[r_index] = True
@sfcgeorge
sfcgeorge / packed-pixels-switchresx.md
Created December 9, 2015 16:13
Packed Pixels HiDPI Retina using SwitchResX

On OS X the Packed Pixels display won't automatically show up as "Retina" or "HiDPI" resolution, instead the OS will use the full resolution of the display making everything tiny. This can be changed using the 3rd party app (non-free) SwitchResX.

First, download SwitchResX.

You can play with the resolutions for the Packed Pixels which is probably listed as Color LCD (2). However not all of the HiDPI resolutions work due to an OS X bug. If you are happy with any of the ones that do work then stop here, else continue.

If you're on El Capitan or later you need to disable System Integrity Protection (temporarily) to add a custom resolution for Packed Pixels. Follow the instructions from SwitchResX creator.

Now add a Custom Resolution that is "scaled". It must be 2 pixels bigger or smaller than the native resolution in one direction (this is the OS X quirk). I found bigger makes it slightly blurry so go w

@sfcgeorge
sfcgeorge / buttons.java
Created June 2, 2015 14:25
Different ways to add an ActionListener to a JButton.
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Buttons {
public static void main(String[] args) {
new JFrame("Different ways of creating JButtons") {{
@sfcgeorge
sfcgeorge / keybase.md
Created October 9, 2019 10:29
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 September 20, 2019 14:43
GraphQL Ruby Chain Loader
# 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 19:14
Mobile Frameworks Comparison
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 September 14, 2018 09:02
Faster PostgreSQL COUNT function for large result sets by using query planner estimates.
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;

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!