Skip to content

Instantly share code, notes, and snippets.

View bradylove's full-sized avatar

Brady Love bradylove

  • Pivotal
  • Highlands Ranch, CO
View GitHub Profile
[alias]
com = commit
co = checkout
br = branch
# Log display from screencast, with train tracks.
l = log --graph --pretty=format':%C(yellow)%h%Cblue%d%Creset %s %C(white) %an, %ar%Creset'
# Alternate log display from Scott Chacon
lol = log --pretty=oneline --abbrev-commit --graph --decorate
# Other useful aliases:
new_button :home_button do |b|
b.title = "Home Button"
b.titleColor = ....
b.target = ....
end
# Wouldn't first_name equal the array?
def test_parallel_assignment_with_one_variable
first_name = ["John", "Smith"]
assert_equal "John", first_name
end
# Pry
[1] pry(main)> first_name = ["Brady", "Love"]
=> ["Brady", "Love"]
@bradylove
bradylove / spec_helper.rb
Created June 19, 2012 04:08 — forked from pauljamesrussell/spec_helper.rb
RSpec matcher for ensuring a model is accepting nested attributes for an association, and accepting/rejecting the right values.
# Use: it { should accept_nested_attributes_for(:association_name).and_accept({valid_values => true}).but_reject({ :reject_if_nil => nil })}
RSpec::Matchers.define :accept_nested_attributes_for do |association|
match do |model|
@model = model
@nested_att_present = model.respond_to?("#{association}_attributes=".to_sym)
if @nested_att_present && @reject
model.send("#{association}_attributes=".to_sym,[@reject])
@reject_success = model.send("#{association}").empty?
end
model.send("#{association}").clear
@bradylove
bradylove / custom_logger.rb
Created June 27, 2012 05:18 — forked from kinopyo/custom_logger.rb
Custom logger file in Rails
# lib/custom_logger.rb
class CustomLogger < Logger
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
end
end
logfile = File.open("#{Rails.root}/log/custom.log", 'a') # create log file
logfile.sync = true # automatically flushes data to file
CUSTOM_LOGGER = CustomLogger.new(logfile) # constant accessible anywhere
@bradylove
bradylove / seed.rb
Created July 2, 2012 04:11
Recipe Data
{ name: "Basic Crepes",
prep_time: 10,
cook_time: 10,
servings: 4,
short_description: %q(These crepes are awesome!),
ingredients_attributes: [{ amount: "1/3",
measurement: "Cup",
ingredient: "Flour" },
{ amount: "2",
measurement: "",
development:
adapter: postgresql
encoding: unicode
database: RecipEasy_development
pool: 5
username: brady
password:
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
$(filelist).delegate(".send", "click", function() {
var li = $(this).closest("li");
var fileID = parseInt(li.attr("data-fileid"), 10);
var groupID = parseInt(li.attr("data-groupid"), 10);
var file = FileReaderJS.output[groupID].files[fileID];
if (file.size < o.maxSize) {
sendFile(file, li);
}
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ansi-color-faces-vector [default bold shadow italic underline bold bold-italic bold])
'(ansi-color-names-vector (vector "#eaeaea" "#d54e53" "#b9ca4a" "#e7c547" "#7aa6da" "#c397d8" "#70c0b1" "#000000"))
'(blink-cursor-mode nil)
'(column-number-mode t)
'(custom-enabled-themes (quote (sanityinc-tomorrow-night)))

Learning Emacs

Commands

CommandWhat it do

-------------------------------------+

C-h rEmacs Help
C-/Undo
C-h kShow definition of command
C-x C-oDelete all blank lines
M-5 C-nPerform the action 5 times
M-%Search and replace (Query)