Skip to content

Instantly share code, notes, and snippets.

View covard's full-sized avatar
💾

Curtis Ovard covard

💾
  • Salt Lake City, Utah
View GitHub Profile
require 'roo'
# Spreadsheet courtesy of the A List Apart 2010 Web Design Survey:
# http://www.alistapart.com/articles/survey2010
workbook = Excel.new('a-list-apart-web-design-survey-sample.xls')
# Set the worksheet you want to work with as the default worksheet. You could
# also iterate over all the worksheets in the workbook.
workbook.default_sheet = workbook.sheets[0]
@covard
covard / roo_row_data.rb
Last active December 15, 2015 16:09
Get roo row data in a hash with headers as the key
workbook.default_sheet = workbook.sheets.first
header = workbook.row(1)
(2..workbook.last_row).each do |i|
row_data_hash = Hash[[header, workbook.row(i)].transpose]
end
@covard
covard / roo_headers.rb
Created April 3, 2013 18:41
How to get headers using roo gem
def self.get_headers(workbook)
headers = Hash.new
workbook.row(1).each_with_index { |header,i| headers[header] = i }
end
@covard
covard / transform_arry_hashes_to_hash.rb
Last active December 17, 2015 04:18
Transform array of hashes into a hash
# how to take an array of hashes and transform it into a hash
ary = [{a: :b}, {c: :d}]
ary.reduce Hash.new, :merge
# output {:a=>:b, :c=>:d}
# Happy Rubying =)
@covard
covard / terminal_notifier.rb
Last active December 17, 2015 15:19
Example on how to use terminal-notifier gem. Great gem for when running ruby scripts and you want an alert of when it has completed.
require 'terminal-notifier'
message = 'Script has completed'
title = 'Hey You!'
TerminalNotifier.notify message, title: title
# Happy Rubying =)
@covard
covard / Rakefile.rb
Last active December 17, 2015 22:59
Example of a custom rake file in a ruby app with out rails.
require 'active_record'
require 'yaml'
require 'logger'
require 'database_cleaner'
require_relative 'models/market'
CONFIG = YAML::load(File.open('config/database.yml'))
task :default => :migrate
namespace :db do
@covard
covard / strong_paramaters_example.rb
Last active October 16, 2019 21:53
Using ActiveRecord (> 4.0) outside of Rails. Since you can't use attar_accessible anymore you have to do it like this.
# when using ActiveDirectory outside of rails need to do it like this for ActiveRecord 4.0
require 'action_controller'
raw_parameters = { :email => "[email protected]", :name => "John", :admin => true }
parameters = ActionController::Parameters.new(raw_parameters)
user = User.create(parameters.permit(:name, :email))
# Happy Rubying =)
@covard
covard / array_diff.rb
Last active December 19, 2015 05:29
How to diff two arrays in ruby and get just the values that are different between the two arrays.
first_hdr = ["hello", "world"]
second_hdr = ["hello", "world", "!"]
new_columns = second_hdr - first_hdr # changed the code to use the way Morgan found, seems more ruby to me ;)
# output
# new_columns => ["!"]
# can also use reject! and that will reject on the second_hdr so then it would be
# second_hdr => ["!"]
@covard
covard / install_postgres.md
Last active December 19, 2015 08:49
Install PostgreSQL with Homebrew and brew services. This is a step by step instruction on installing postgres.

This gist is for installing PostgreSQL using Hombrew and the luncy gem.

$ brew install postgresql

When you install Postgres, you will see a bunch of output in your Terminal. The important sections are Build Notes, Create/Upgrade a Database, and Start/Stop PostgreSQL. Make sure to follow those instructions to the letter.

Create and upgrade a DB

@covard
covard / quarantine.sh
Created July 5, 2013 17:19
This is the command to get OSX to stop asking if you want to run application "X" in this case adium
# stop OSX from asking if you want to run application
sudo xattr -d com.apple.quarantine /Applications/Adium.app