Skip to content

Instantly share code, notes, and snippets.

View hogihung's full-sized avatar

John F. Hogarty hogihung

  • Left Foot Media, Inc.
  • Jacksonville, FL
View GitHub Profile
@hogihung
hogihung / practice_blocks-new_map
Created March 16, 2014 19:31
Practice with blocks - new_map method
class Array
def new_map
a = []
self.each do |item|
a << yield(item)
end
a
end
@hogihung
hogihung / show.html.erb
Created March 24, 2014 01:14
Bloccit Posts#Show
<h1><%= markdown @post.title %></h1>
<div class="row">
<div class="col-md-8">
<small>
<%= image_tag(@post.user.avatar.tiny.url) if @post.user.avatar? %>
submitted <%= time_ago_in_words(@post.created_at) %> ago by
<%= @post.user.name %>
</small>
<p><%= markdown @post.body %></p>
<%= image_tag(@post.image) if @post.image? %>
@hogihung
hogihung / topics_show.html.erb
Created March 24, 2014 01:31
Bloccit Topic#Show
<h1><%= @topic.name %></h1>
<% if policy(@topic).update? %>
<%= link_to "Edit Topic", edit_topic_path, class: 'btn btn-success' %>
<% end %>
<div class="row">
<div class="col-md-8">
<p class="lead"><%= @topic.description %></p>
<% @posts.each do |post| %>
@hogihung
hogihung / populate.rake
Last active March 31, 2016 20:29
A rake Task for importing data via CSV files
require 'csv'
baytechs_file = "/path/to/file/baytechs.CSV"
devices_file = "/path/to/file/devices.CSV"
namespace :oob_import do
task :baytechs => :environment do
Baytech.delete_all
CSV.foreach(baytechs_file, headers: true) do |row|
p row
@hogihung
hogihung / title_case.rb
Created March 27, 2014 15:45
Bloc Exercise - Title Case
class String
def title_case
articles = ["of", "and", "the", "a"]
s = self.downcase
a = s.split(' ')
a.each do |i|
i.capitalize! unless articles.include? i
end
a.first.capitalize!
@hogihung
hogihung / pop_posts_refactor
Created March 30, 2014 13:27
Bloc - Popular Post Refactor
mkdir app/controllers/topics/
mv app/controllers/posts_controller.rb app/controllers/topics/posts_controller.rb
mkdir app/views/topics/posts/
mv app/views/posts/_form.html.erb app/views/topics/posts/_form.html.erb
mv app/views/posts/edit.html.erb app/views/topics/posts/edit.html.erb
mv app/views/posts/new.html.erb app/views/topics/posts/new.html.erb
mv app/views/posts/show.html.erb app/views/topics/posts/show.html.erb
AWS_ACCESS_KEY_ID: "XXXXXXXXXXXXXXXXXXXXX"
AWS_SECRET_ACCESS_KEY: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
development:
SENDGRID_USERNAME: "yourappname@heroku.com"
SENDGRID_PASSWORD: "yourPW"
AWS_BUCKET: myname-bloccit-dev
production:
AWS_BUCKET: myname-bloccit-prod
@hogihung
hogihung / make_equip_files.rake
Created May 5, 2014 13:48
Rake task to export records to formatted : delimited CSV files.
require 'csv'
equip_dom = "/tmp/equip.db_new"
equip_mow = "/tmp/equip.db.mow_new"
namespace :oob_export do
task :domestic => :environment do
puts "Building equip.db file."
CSV.open(equip_dom, 'w+', col_sep: ':') do |csv|
Baytech.where(region: "USA").all.each do |baytech|
@hogihung
hogihung / user_registration_login.feature
Last active August 29, 2015 14:01
User Registration and Login Feature
Feature: Registration
Scenario: User provides valid information
Given a unique email, password and matching password confirmation
When the user clicks the Sign up button
Then the output should be "A message with a confirmation link has been sent to your email address. Please open the link to activate your account."
Scenario: User supplies email, but no password
Given a unique email, but no password or password confirmation
When the user clicks the Sign up button
@hogihung
hogihung / Base-Gemfile
Last active August 29, 2015 14:04
Base Gemfile for Ruby 2.1.2 and Rails 4.1.4 app with RSpec and Capybara testing.
source 'https://rubygems.org'
ruby '2.1.2'
gem 'rails', '4.1.4'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'jbuilder', '~> 2.0'