Skip to content

Instantly share code, notes, and snippets.

Hoping I don't break anything

Brian Goff cpuguy83

Hoping I don't break anything
Block or report user

Report or block cpuguy83

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
cpuguy83 / gist:4512161
Last active Dec 10, 2015
I noticed in my models I had several methods that could use some caching to speed things up a bit, especially because lots of joins were involved to make it happen. I got tired of calling "Rails.cache.fetch __method__, self" over and over and over. Taking a cue from the ActionView::Helpers::CacheHelper 'cache' call and the whole Russian-doll cac…
View gist:4512161
module CacheHelper
extend ActiveSupport::Concern
included do
extend Cacher
include Cacher
cattr_accessor :updated_column_name
self.updated_column_name ||= :change_time
cattr_accessor :file_location
cattr_accessor :file_digest
cpuguy83 / base_pusher.rb
Last active Jan 23, 2016
Server Push based controller
View base_pusher.rb
class BasePusher < AbstractController::Base
include AbstractController::Logger
include AbstractController::Rendering
include AbstractController::Layouts
include AbstractController::Helpers
include AbstractController::Translation
include AbstractController::AssetPaths
include AbstractController::Callbacks
include Rails.application.routes.url_helpers if defined? Rails
View gist:4946806
@ServiceLocalTime =
time_calc: (selector) ->
date = new Date()
local_offset = date.getTimezoneOffset() * 60000
utc = date.getTime() + local_offset
offset = parseInt(selector.attr('data-tz-offset'))
time = utc + offset
new_date = new Date(time)
update_time: (time_element = $('span#service_local_time')) ->
cpuguy83 /
Last active Dec 18, 2019
Simple loading spinner for long requests with turbolinks and bootstrap modal
@PageSpinner =
spin: (ms=500)->
@spinner = setTimeout( (=> @add_spinner()), ms)
$(document).on 'page:change', =>
spinner_html: '
<div class="modal hide fade" id="page-spinner">
<div class="modal-head card-title">Please Wait...</div>
<div class="modal-body card-body">
<i class="icon-spinner icon-spin icon-2x"></i>
cpuguy83 /
Last active Dec 14, 2015
Endless Scroll with turbolinks support
@EndlessScroll =
load_next: ->
unless (@loading == true) || @next_button().hasClass('disabled')
@loading = true
setTimeout((=>@request()), 50)
active_pager: ->
$('.pagination ul')
next_pager: ->
next_button: ->
cpuguy83 / amphibian.rb
Last active Dec 16, 2015
Case for class inheritance... AND THE SKARKTAPOUS!
View amphibian.rb
class Amphibian
include Fishy
def walk
# on the ground
cpuguy83 / get_json_names.thml
Created Apr 24, 2013
Bad call? This stuff is loaded after the page is loaded. Why are they making 4 separate requests to pull a name for something they already had an ID for?
View get_json_names.thml
<script type="text/javascript">
$(function () {
$.post('/Juice/Global/JsonGetDivisionName', { id: '2117fcab-7dd1-45a2-8404-aa0c56d9ed43' }, function (data) {
$('.ref_loader_' + '2117fcab-7dd1-45a2-8404-aa0c56d9ed43').html(data);
<script type="text/javascript">
$(function () {
$.post('/Juice/Advertisers/JsonGetName', { id: 'b6e16bd0-3f92-4d11-9b9b-ce572e33edc2' }, function (data) {
cpuguy83 / sidekiq.log
Last active Dec 16, 2015
rubinius rc1 sidekiq crash - Uncaught C++ internal exception
View sidekiq.log
Rubinius Crash Report #rbxcrashreport
Error: signal �SIGSEGV
cpuguy83 / rbx_sidekiq_crash.log
Created May 7, 2013
Another sidekiq crash in Rubinius
View rbx_sidekiq_crash.log
Rubinius Crash Report #rbxcrashreport
Error: signal SIGSEGV
cpuguy83 / gist:5652408
Created May 26, 2013
libssl RBX crash with Sidekiq
View gist:5652408
You can’t perform that action at this time.