Skip to content

Instantly share code, notes, and snippets.

View peterclark's full-sized avatar
🏠
Working from home

Peter Clark peterclark

🏠
Working from home
View GitHub Profile
@peterclark
peterclark / _table.html.haml
Last active August 21, 2023 12:21
Rails drag and drop using HTML5 and acts_as_list
%table.table
%thead.table-active
%tr
%th Position
%th Name
%tbody
- @fruits.each do |fruit|
%tr.draggable{ draggable: true, id: "fruit-#{fruit.id}", data: { position: fruit.position, url: reorder_fruit_path(fruit, format: :js) }}
%td= fruit.position
@peterclark
peterclark / rails_collection_checkboxes.html.haml
Last active December 21, 2018 18:01
rails collection checkboxes
# for has_and_belongs_to_many, required true
= f.collection_check_boxes :ethnicity_ids, Ethnicity.all, :id, :name, {}, { required: true } do |e|
= e.label do
= e.check_box
= e.text
# or for has_many through with different wrappers
= f.collection_check_boxes :health_goal_ids, HealthGoal.ordered, :id, :name, boolean_style: :inline, item_wrapper_tag: nil do |goal|
xcode-select --install
gem uninstall libv8
gem uninstall therubyracer
brew rm v8
brew tap homebrew/dupes
brew install apple-gcc42
brew tap homebrew/versions
brew install v8-315
brew link --force v8-315
gem install libv8 -- --with-system-v8
@peterclark
peterclark / ruby-google-api-analyticsv3.rb
Last active May 1, 2020 02:19
Authentication with the Ruby Google API Client and Google Analytics API
# Create credentials json file
# 1. Go to Google API Console
# 2. Create credentials (Service Account Key). Note 'Service account ID'
# 3. Download key as 'google_auth.json'
# 4. Go to Google Analytics -> Admin -> View Settings. Note 'View ID'
# 5. Go to User Management -> Add permissions for: (Service account ID) [Read & Analyze]
# Terminal
export GOOGLE_APPLICATION_CREDENTIALS='config/google_auth.json'