Skip to content

Instantly share code, notes, and snippets.

View mguterl's full-sized avatar

Mike Guterl mguterl

View GitHub Profile
@JoelQ
JoelQ / tally.rb
Last active April 13, 2024 16:27
Demonstration of using a rich object to represent a composite count and how it makes the math easier to deal with
class Tally
def self.empty
new({})
end
def initialize(raw)
@raw = empty_hash.merge raw.slice(:small, :medium, :large)
end
# Accessors

Estimation

This document is an attempt to pin down all the things you don't think about when quoting for a project, and hopefully provide a starting point for some kind of framework to make quoting, working and delivering small-medium jobs more predictable and less stressful.

Contents

@theorygeek
theorygeek / association_loader.rb
Last active October 31, 2023 07:15
Preloading Associations with graphql-batch
# frozen_string_literal: true
class AssociationLoader < GraphQL::Batch::Loader
attr_reader :klass, :association
def initialize(klass, association)
raise ArgumentError, "association to load must be a symbol (got #{association.inspect})" unless association.is_a?(Symbol)
raise ArgumentError, "cannot load associations for class #{klass.name}" unless klass < ActiveRecord::Base
raise TypeError, "association #{association} does not exist on #{klass.name}" unless klass.reflect_on_association(association)
@klass = klass

2015-01-29 Unofficial Relay FAQ

Compilation of questions and answers about Relay from React.js Conf.

Disclaimer: I work on Relay at Facebook. Relay is a complex system on which we're iterating aggressively. I'll do my best here to provide accurate, useful answers, but the details are subject to change. I may also be wrong. Feedback and additional questions are welcome.

What is Relay?

Relay is a new framework from Facebook that provides data-fetching functionality for React applications. It was announced at React.js Conf (January 2015).

@squarism
squarism / english_is_terrible.md
Last active January 2, 2023 18:59
English is Terrible

I'm sad that the world has adopted English as the language of science and business. It's insane. It's like adopting a psychotic murdering robot to clean your house. English is a mutt language that has never been redone, reworked or even designed. It's a combination of ice cream, meatballs and wine. All fine things by themselves but terrible when combined.

There are more English learners than there are native English speakers in the world. I'm really sorry world. I'm just so so sorry that you have to learn Germanic-French-Latin nonsense. It's terrible. It's a terrible language.

Update: I wrote this before I read Mother Tongue by Bill Bryson. It's fantastic and a better write-up of what I'm trying to say here.


Prepositional phrases

.
├── actions
├── stores
├── views
│   ├── Anonymous
│   │   ├── __tests__
│   │   ├── views
│   │   │   ├── Home
│   │   │   │   ├── __tests__
│   │   │   │   └── Handler.js
@mattvv
mattvv / credit_card_helper.rb
Created March 17, 2014 19:15
Include this in your test_helper.rb to stub your stripe checkout.js
#this is a very simple, work in progress helper method for stubbing the stripe checkout.js
#this creates a fake server that will generate stripe token as if it's coming from stripe. So we can test credit card input
class FakeStripe < Sinatra::Base
def self.boot
instance = new
Capybara::Server.new(instance).tap { |server| server.boot }
end
get '/checkout.js' do

Organizing your codes

A few notes on how I organize my code lately. It's not the sexiest topic in the world but it matters, especially given that I keep about 160 repos cloned on my system at any given time.

Directory Layout

I've spent a couple years now trying to avoid the urge to mirror my personal code working space after github repo pathnames, but I'm a weak man and have given in.

When I want to clone a repo, I'll give it a directory matching the pattern ~/code/<owner>/<repo>.

@branneman
branneman / better-nodejs-require-paths.md
Last active April 8, 2024 00:22
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions