Skip to content

Instantly share code, notes, and snippets.

View JamesDullaghan's full-sized avatar
🎯
Focusing

James D JamesDullaghan

🎯
Focusing
View GitHub Profile
code = request.params[:code]
hmac = request.params[:hmac]
shop = request.params[:shop]
no_values_present = code.nil? && hmac.nil? && shop.nil?
if no_values_present
shopify_session = ShopifyAPI::Session.new(current_franchise.shopify_store_url)
scope = ["read_customers"]
uri = URI(permission_url)
@JamesDullaghan
JamesDullaghan / copy_task_list_templates_only.md
Created January 10, 2018 20:12
Copy task list templates from one team to a group of other teams

To Only remove task templates and recreate

# find source team
src_team = Team.find 836
# find each org
iserve = Organization.find 575
idirect = Organization.find 574

idirect_operable_teams = idirect.teams.where.not(id: 836)
@JamesDullaghan
JamesDullaghan / calendar.html
Created October 1, 2013 23:18
Calendar html
<div class="row">
<div class="large-12 columns calendar-container">
<h3 class="month">
<a href="/admin/analytics?class=cal-larr&amp;date=2013-11-01">&lt;</a>
December 2013
<a href="/admin/analytics?class=cal-rarr&amp;date=2014-01-01">&gt;</a>
</h3>
<section class="calendar" role="main">
<ul class="day-row">
<li class="day">SUN</li>
def sticker_image_path
src = "data:image/png;base64,"
src += ActiveSupport::Base64.encode64(File.read("#{Rails.root}/app/assets/images/courses/#{self.slug}-sticker.png"))
src
end
@JamesDullaghan
JamesDullaghan / calendar_helper.rb
Created October 1, 2013 23:10
calendar helper
module CalendarHelper
def calendar(date = Date.today, &block)
Calendar.new(self, date, block).table
end
class Calendar < Struct.new(:view, :date, :callback)
HEADER = %w[SUN MON TUE WED THU FRI SAT]
START_DAY = :sunday
delegate :content_tag, to: :view
@JamesDullaghan
JamesDullaghan / _calendar.scss
Created October 1, 2013 23:11
calendar helper scss
.month {
font-family: 'ProximaCond';
background: $primary-color;
font-size: 28px;
letter-spacing: 2px;
text-align: center;
padding: 10px 0;
margin-bottom: 0;
color: #fff;
a {
var PurdyPercent = function (num, options) {
this.settings = {
hide_decimal_on_whole : true,
decimals : 2,
truncate : false, // (soon)
match_decimals: true, // forces floats to match defined decimal count
rounding : 'default', //default, up, down (soon)
postfix : '%'
};
@JamesDullaghan
JamesDullaghan / foundation_willpaginate.rb
Created September 19, 2013 21:32
Foundation will_paginate
require 'will_paginate/view_helpers/link_renderer'
require 'will_paginate/view_helpers/action_view'
module WillPaginate
module ActionView
def will_paginate(collection = nil, options = {})
options[:renderer] ||= FoundationLinkRenderer
super.try :html_safe
end
@JamesDullaghan
JamesDullaghan / sleep_counter_irc_help.md
Created June 24, 2013 23:02
sleep counter irc help

How would I go about mapping an array of hashes that are nested inside of an array??? I need to get an array returned for each :hours for each month, so I can then use the median method and get an average for each month. I can do it in the views, but using

<% @sleep_months.each do |month, sleep| %>
  <ul><%= month.strftime("%B") %>
  <% for sleeps in sleep %>
    <li><%= sleeps.hours %></li>
  <% end %>
  </ul>
<% end %>
def index
# Sleep.all for current_user
@sleeps = current_user.sleeps
# Sleep grouped and sorted in order by month
@sleep_months = @sleeps.group_by { |s| s.beginning_of_month }.sort { |a,b| a[0] <=> b[0] }
@array_for_average_sleep_months = @sleep_months.map { |month, sleep| month.strftime("%b") }
@array_for_hours_slept_per_month = ?????