Skip to content

Instantly share code, notes, and snippets.

View adammcarth's full-sized avatar

Adam McArthur adammcarth

View GitHub Profile
@adammcarth
adammcarth / example.rb
Last active August 29, 2015 13:57
Using ("dynamic"?) classes in ruby...
# Active Record lets you do things like:
Post.find(3).title
#=> "Hello, world!"
# Cool. So my question is, how exactly do you setup a class that allows the
# programmer to use there own keyword? My use case:
def get(type, id)
module Get
def get()
# Code not necessary
end
end
class JTask
extend Get
end
require "ostruct"
# Actual value obtained from elsewhere, must
# be in this format up until now.
required_records = {"1" => { "name" => "Adam" }, "2" => { "name" => "John" }}
# Loop through each required record and
# assemble each key-value into the open structure output.
output = Array.new
# Option 2: Save true or false into the database
# This is the model file
before_save :verify_use_card
def verify_use_card
if self.use_credit_card == 1
self.use_credit_card = true
else
self.use_credit_card = false
end
@adammcarth
adammcarth / comparison.rb
Created April 23, 2014 09:56
comparing 2 files
class Comparison
def self.new(string_one, string_two)
# Define variables to manipulate later on
unchanged, addition = "", ""
all_unchanged, all_additions = [], []
# Determine which file has the largest amount of characters
if (string_one <=> string_two) < 0
num_chars = string_two.length
else
# Must be defined as a blank array for "<<" to work later on
array = Array.new
number = 5
number.times do |n|
array << n + 1
end
puts array
@adammcarth
adammcarth / josiah.rb
Last active August 29, 2015 14:00
Ruby.
names = ["beautiful", "stunning", "elegant", "object orientated", "fun", "engaging", "easy", "pragmatic"]
names.each do |name|
puts "Ruby is #{name}"
end
#=> Ruby is beautiful
#=> Ruby is stunning
#=> Ruby is elegant
#=> Ruby is object orientated
@adammcarth
adammcarth / notes.md
Last active August 29, 2015 14:01
Inch Pages Badge Notes
@adammcarth
adammcarth / pseudocode.md
Created May 19, 2014 01:16
Algorithm for umm... Rockon
prices_hash = { "large" => 12, "medium" => 10, "small" => 8 }

Function calculate_cost(num_rocks, rock_sizes=[])
  // Workout base cost
  cost = 0
  For Each (rock_sizes) as |size|
    cost = cost + prices_hash[size]
  End Loop
@adammcarth
adammcarth / edit.html
Last active August 29, 2015 14:01
Editing content with Aloha Editor and saving it to a database
<!-- target aloha editor to edit this div -->
<div class="editable_content">
<!-- <?php echo $content_from_database ?> -->
<p>Hello, world!</p>
</div>
<!-- Edit away, and then users click this button to save their changes -->
<button class="update_content">Update Content</button>
<script src="http://code.jquery.com/jquery-git1.min.js"></script>