Skip to content

Instantly share code, notes, and snippets.

View xander-miller's full-sized avatar

Xander Miller xander-miller

View GitHub Profile

Checkpoint 15

Questions

  • Which version of Ubuntu should I use?
  • What is bash?

Comments

Concerns

@xander-miller
xander-miller / lamba.rb
Created June 25, 2015 19:19
Used a lamda to DRY up my code. Ruby skill up! 👍
res.sort! do |x,y|
archived = -> (z) {[:archived, 'archived'].include?(z.status)}
if archived.call(x) && archived.call(y)
0
elsif !archived.call(x) && archived.call(y)
-1
elsif archived.call(x) && !archived.call(y)
1
elsif !archived.call(x) && !archived.call(y)
0
@xander-miller
xander-miller / affirmations.md
Created April 2, 2015 14:40
My compassion meditation affirmations
  • X is an aspect of the Universe just like me.
  • May X be well and happy.
  • May X have no fears or sorrows.
  • May X be healthy and free from illness.
  • May X live calmly and peacefully.
  • When see wrong done to X I will try to right it.
  • When I see X suffering I will try to heal it.
  • When I see X at war I will try to end it.
  • X is just as deserving of compassion as myself or anyone.
@xander-miller
xander-miller / .rspec
Last active August 29, 2015 14:14
How to RSpec Controllers
--require spec_helper
--color
--format documentation
def scrub_uri
uri.strip!
unless uri.slice(0,4) == "http" do
uri = uri.prepend "http://"
end
end
<%= debug(params) if Rails.env.development? %>
<%= debug(session) if Rails.env.development? %>
@xander-miller
xander-miller / simple_form_post.html.erb
Created November 15, 2014 03:18
Untested example of post form in simple form
<%= simple_form_for [topic, post] do |f| %>
<%= f.input :title %>
<%= f.input :body, rows: 8 %>
<% if post.image? %>
<div class="form-group">
<p>Current image</p>
<%= image_tag( current_user.image.thumb.url ) %>
</div>
<% end %>
<%= f.input :image, as: :file %>
class Array
def new_any?(&block)
if block_given?
selected = self.select(&block)
else
selected = self
end
if selected.length == 0
false
class Array
def new_map
new_array = []
each do |item|
new_array << yield(item)
end
new_array
end
def new_select!(&block)
def new_map(array)
new_array = []
array.each do |item|
new_array << yield(item)
end
new_array
end