Skip to content

Instantly share code, notes, and snippets.

View lewispb's full-sized avatar

Lewis Buckley lewispb

View GitHub Profile
##
# Get the context for a search term and highlight the term itself
# text: string containing the search term and additional information
# term: string with the term you're looking for
# words: int for how many words to include total
# padding_left: int for characters to the left of the search term
# padding_right: int for characters to the right of the search term
#
# Only handles the first instance of a given term. Can be modified to take
# character positions denoting the start and stop of term(s).
@greendog
greendog / liquid.rb
Created January 23, 2013 12:54
Create a Liquid Handler for Rails 3.1 Use: require 'action_view/template/handlers/liquid' ActionView::Template.register_template_handler :liquid, ActionView::Template::Handlers::Liquid
class ActionView::Template::Handlers::Liquid
def self.call(template)
"ActionView::Template::Handlers::Liquid.new(self).render(#{template.source.inspect}, local_assigns)"
end
def initialize(view)
@view = view
end
def render(template, local_assigns = {})
@kizzx2
kizzx2 / post.rb
Last active June 26, 2021 12:14
A clean and elegant approach to partial object validation with Rails + Wicked wizards (using session to store the partial object)
class Post < ActiveRecord::Base
attr_accessible :body, :price, :title
validates_presence_of :title
validates_length_of :title, minimum: 10
validates_presence_of :body
validates_numericality_of :price, greater_than: 0
end
@mewdriller
mewdriller / ability.rb
Last active December 19, 2021 01:48
Serializing CanCan rules to JSON for use in a client-side application
class Ability
include CanCan::Ability
def initialize(user)
can :read, Comment
if user.valid?
can :create, Comment
can :manage, Comment, author_id: user.id
end
@JunichiIto
JunichiIto / alias_matchers.md
Last active June 24, 2024 21:02
List of alias matchers in RSpec 3

This list is based on aliases_spec.rb.

You can see also Module: RSpec::Matchers API.

matcher aliased to description
a_truthy_value be_truthy a truthy value
a_falsey_value be_falsey a falsey value
be_falsy be_falsey be falsy
a_falsy_value be_falsey a falsy value
@eliotsykes
eliotsykes / rails_new_help_output.md
Last active March 31, 2024 17:09
"rails new" options explained

Run rails new --help to view all of the options you can pass to rails new:

$ bin/rails new --help
Usage:
  rails new APP_PATH [options]

Options:
  -r, [--ruby=PATH]                                      # Path to the Ruby binary of your choice
                                                         # Default: /Users/eliot/.rbenv/versions/2.2.0/bin/ruby
@marick
marick / about_those_lava_lamps.md
Last active June 22, 2022 21:08
About Those Lava Lamps

Around 2006-2007, it was a bit of a fashion to hook lava lamps up to the build server. Normally, the green lava lamp would be on, but if the build failed, it would turn off and the red lava lamp would turn on.

By coincidence, I've actually met, about that time, (probably) the first person to hook up a lava lamp to a build server. It was Alberto Savoia, who'd founded a testing tools company (that did some very interesting things around generative testing that have basically never been noticed). Alberto had noticed that people did not react with any urgency when the build broke. They'd check in broken code and go off to something else, only reacting to the breakage they'd caused when some other programmer pulled the change and had problems.

@vasanthk
vasanthk / System Design.md
Last active July 3, 2024 08:38
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?

FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.


Effective Engineer - Notes

What's an Effective Engineer?

@troyfontaine
troyfontaine / 1-setup.md
Last active July 1, 2024 14:14
Signing your Git Commits on MacOS

Methods of Signing Git Commits on MacOS

Last updated March 13, 2024

This Gist explains how to sign commits using gpg in a step-by-step fashion. Previously, krypt.co was heavily mentioned, but I've only recently learned they were acquired by Akamai and no longer update their previous free products. Those mentions have been removed.

Additionally, 1Password now supports signing Git commits with SSH keys and makes it pretty easy-plus you can easily configure Git Tower to use it for both signing and ssh.

For using a GUI-based GIT tool such as Tower or Github Desktop, follow the steps here for signing your commits with GPG.