Skip to content

Instantly share code, notes, and snippets.

View maxx-coffee's full-sized avatar
💭
Coding for funsies

Maxx Coffee maxx-coffee

💭
Coding for funsies
View GitHub Profile

Keybase proof

I hereby claim:

  • I am joshualcoffee on github.
  • I am jcoffee (https://keybase.io/jcoffee) on keybase.
  • I have a public key whose fingerprint is CD80 91A1 EB6A 9C74 646D 41A0 FF4D 5558 FA6C 6316

To claim this, I am signing this object:

@maxx-coffee
maxx-coffee / TextFormatter.js
Created November 9, 2017 19:10
Dependency injection via javascript
export default (text) => text;
@maxx-coffee
maxx-coffee / boostrap_inline_errors.rb
Last active February 12, 2016 02:01
Rails bootstrap inline errors
module FormHelper
def bootstrap_errors_for(attr, form, &block )
errors = form.errors[attr]
error_messages = errors.map{|error| content_tag(:span, error)}
content = block_given? ? capture(&block) : "".html_safe
noko_content = Nokogiri::HTML::DocumentFragment.parse(content)
noko_content.css('.form-group')[0]['class'] = "#{noko_content.css('.form-group')[0]['class']} has-error" if errors.present?
if error_messages.present?
@today_tasks = @incomplete_tasks.where('scheduled_at < ?', Time.zone.now.end_of_day).paginate(per_page: 30, page: params[:today_tasks_page])
@upcoming_tasks = @incomplete_tasks.where('scheduled_at > ?', Time.zone.now.end_of_day).paginate(per_page: 30, page: params[:upcoming_tasks_page])
@past_tasks = @complete_tasks.paginate(per_page: 30, page: params[:past_tasks_page]).reorder('scheduled_at desc')
@job_tags = current_account.tags.where(tag_type: 'Job')
respond_to do |format|
format.html
format.js do
@param_name = params.keys.keep_if { |name| name =~ /_page/ }.first
@maxx-coffee
maxx-coffee / gist:34eae2e11e8a54b0d416
Created June 23, 2014 20:54
calculate table columns in javascript
calculate_summary = ($el) ->
$cells = $("td", $el)
$cells.each (i, v) ->
val = parseInt($(this).text())
int = if isNaN(val) then 0 else val
if !sums[i]?
sums[i] = 0
sums[i] = sums[i] + int
return sums
$ ->
@maxx-coffee
maxx-coffee / angular pagination
Last active August 29, 2015 13:57
will_paginate with angular
$scope.buildPagination = () ->
c = $scope.current_page
padded = $scope.pagination_padding*2
arr = []
if c <= $scope.total_pages
min = c - $scope.pagination_padding
max = c + $scope.pagination_padding
show_next = true
@maxx-coffee
maxx-coffee / gist:5605717
Created May 18, 2013 20:40
Pinterest style image scraping using Nokogiri & FastImage
def scrape_images(url)
doc = Nokogiri::HTML(open(url))
url = url.slice( /\A(http|https)(:\/\/){1}[a-z0-9\-\.]{1,}/i )
images = []
doc.css("img").each do |img|
img = img['src']
if img =~ /\A\/.*/
src = url + img
# Check for complete link