Skip to content

Instantly share code, notes, and snippets.

View pelted's full-sized avatar

Chris Born pelted

  • Seattle, WA
  • 07:10 (UTC -07:00)
View GitHub Profile
@jcypret
jcypret / ruby.yml
Created October 29, 2019 03:06
Ruby CI (RSpec + CodeClimate) using GitHub Actions
name: build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
@scottharvey
scottharvey / stimulus.md
Last active October 8, 2021 19:57 — forked from mrmartineau/stimulus.md
Stimulus cheatsheet
@dcuadraq
dcuadraq / ch_01.md
Last active November 10, 2023 02:39
Rails Antipatterns: Best practice Ruby on Rails Refactoring notes

Chapter 1. Models

The Model layer should also contain the business logic of your application.

ANTIPATTERN: VOYEURISTIC MODELS

Class: A class defines the characteristics of an object, including the details of what it is (its attributes) and what it can do (its methods).

Method: A method exists on a class and defines what the class can do.

Encapsulation: Ideally, the code for a class should be relatively self-contained through encapsulation, which is the concealment of functional details of a class from the other objects that call its methods. This is typically done by limiting the methods other objects are allowed to call and exposing a public interface through which an object is exposed to the world. In Ruby, this is done with the public, protected, and private keywords.

@iscott
iscott / simple_authentication_rails_5_bcrypt_and_has_secure_password.md
Last active March 15, 2024 03:23
Cheat Sheet: Simple Authentication in Rails 5 with has_secure_password

Cheat Sheet: Simple Authentication in Rails 6 with has_secure_password

The goal of this cheatsheet is to make it easy to add hand-rolled authentication to any rails app in a series of layers.

First the simplest/core layers, then optional layers depending on which features/functionality you want.

Specs
AUTHOR Ira Herman
LANGUAGE/STACK Ruby on Rails Version 4, 5, or 6
@somebox
somebox / presenters.md
Last active March 26, 2022 02:12
Thoughts About Rails Presenters

Thoughts about Rails Presenters

This is a collection of links, examples and rants about Presenters/Decorators in Rails.


The "Decorator" pattern slowly started gaining popularity in Rails several years ago. It is not part of core Rails, and there's many different interpretations about how it should work in practice.

Jay Fields wrote about it in 2007 (before he switched back to Java and then Clojure): http://blog.jayfields.com/2007/03/rails-presenter-pattern.html

@tcannonfodder
tcannonfodder / test_assertions.rb
Created August 24, 2014 22:09
Helpful test assertions for MiniTest suite in Rails
# Some very helpful asserts to add on top of MiniTest, includes ordered array
# and set comparison, ActiveRecord attribute validation, and layout assertions
# This was originally written by @madrobby for Freckle: https://letsfreckle.com
module MiniTest
module Assertions
def assert_layout(layout, message=nil)
assert_equal "layouts/#{layout}", @response.layout, message
end
@thatfunkymunki
thatfunkymunki / application_helper.rb
Created November 9, 2011 08:21 — forked from purcell/application_helper.rb
Make will_paginate generate HTML that bootstrap.less will render nicely, fixed for will_paginate 3.0.2
# Based on https://gist.github.com/1205828, in turn based on https://gist.github.com/1182136
class BootstrapLinkRenderer < ::WillPaginate::ActionView::LinkRenderer
protected
def html_container(html)
tag :div, tag(:ul, html), container_attributes
end
def page_number(page)
tag :li, link(page, page, :rel => rel_value(page)), :class => ('active' if page == current_page)
require "rest-client"
begin
exists = RestClient.head("http://google.com").code == 200
rescue RestClient::Exception => error
exists = (error.http_code != 404)
end
puts "exists=#{exists}"
@akagomez
akagomez / gist:1025933
Created June 14, 2011 21:26 — forked from hunterloftis/gist:1025903
Install Git, Node, NPM, Nginx, PHP (Fast CGI), CouchDB, and MySQL on Ubuntu 10.04 LTS
# This should be run on a new Linode Ubuntu 32-bit 10.04 image as root to prepare it for Nginx, PHP, MySQL, Node, CouchDB environment
# To start, something like this works:
# scp prepare_server.sh root@123.456.789.10:/root
# First, install basic linux utilities (compilers, git, libssl)
cd /root
mkdir /src
cd src