Skip to content

Instantly share code, notes, and snippets.

View cpuguy83's full-sized avatar
🐶

Brian Goff cpuguy83

🐶
View GitHub Profile
@cpuguy83
cpuguy83 / gist:4512161
Last active December 10, 2015 23:48
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…
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
cpuguy83 / base_pusher.rb
Last active January 23, 2016 03:02
Server Push based controller
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
@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
cpuguy83 / loading_spinner.coffee
Last active August 30, 2020 13:49
Simple loading spinner for long requests with turbolinks and bootstrap modal
@PageSpinner =
spin: (ms=500)->
@spinner = setTimeout( (=> @add_spinner()), ms)
$(document).on 'page:change', =>
@remove_spinner()
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
cpuguy83 / endless_scroll.coffee
Last active December 14, 2015 12:18
Endless Scroll with turbolinks support
@EndlessScroll =
load_next: ->
unless (@loading == true) || @next_button().hasClass('disabled')
@loading = true
setTimeout((=>@request()), 50)
active_pager: ->
$('.pagination ul li.active')
next_pager: ->
@active_pager().next('li')
next_button: ->
@cpuguy83
cpuguy83 / amphibian.rb
Last active December 16, 2015 14:58
Case for class inheritance... AND THE SKARKTAPOUS!
class Amphibian
include Fishy
def walk
# on the ground
end
end
@cpuguy83
cpuguy83 / get_json_names.thml
Created April 24, 2013 19:13
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?
<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>
<script type="text/javascript">
$(function () {
$.post('/Juice/Advertisers/JsonGetName', { id: 'b6e16bd0-3f92-4d11-9b9b-ce572e33edc2' }, function (data) {
@cpuguy83
cpuguy83 / sidekiq.log
Last active December 16, 2015 22:48
rubinius rc1 sidekiq crash - Uncaught C++ internal exception
Rubinius Crash Report #rbxcrashreport
Error: signal �SIGSEGV
[[Backtrace]]
rbx[0x594a60]
/lib/x86_64-linux-gnu/libpthread.so.0(+0xfcb0)[0x7fcf22d34cb0]
rbx(_ZN8rubinius11SharedState10vm_threadsEPNS_5StateE+0xbd)[0x650cad]
rbx(_ZN8rubinius10Primitives11thread_listEPNS_5StateEPNS_9CallFrameEPNS_10ExecutableEPNS_6ModuleERNS_9ArgumentsE+0x7d)[0x603d3d]
rbx(_ZN8rubinius11MachineCode11interpreterEPNS_5StateEPS0_PNS_20InterpreterCallFrameE+0x12d9)[0x5b7499]
@cpuguy83
cpuguy83 / rbx_sidekiq_crash.log
Created May 7, 2013 13:34
Another sidekiq crash in Rubinius
Rubinius Crash Report #rbxcrashreport
Error: signal SIGSEGV
[[Backtrace]]
rbx[0x594a60]
/lib/x86_64-linux-gnu/libpthread.so.0(+0xfcb0)[0x7f3a9295ecb0]
rbx(_ZN8rubinius15MonoInlineCache11check_cacheEPNS_5StateEPNS_8CallSiteEPNS_9CallFrameERNS_9ArgumentsE+0x12)[0x6c17b2]
rbx(_ZN8rubinius11MachineCode11interpreterEPNS_5StateEPS0_PNS_20InterpreterCallFrameE+0x12d9)[0x5b7499]
rbx(_ZN8rubinius16BlockEnvironment19execute_interpreterEPNS_5StateEPNS_9CallFrameEPS0_RNS_9ArgumentsERNS_15BlockInvocationE+0x22b)[0x698d4b]
@cpuguy83
cpuguy83 / gist:5652408
Created May 26, 2013 10:46
libssl RBX crash with Sidekiq
/lib/tls/i686/cmov/libc.so.6(+0x6e311)[0xb7565311]
/lib/tls/i686/cmov/libc.so.6(+0x6fb68)[0xb7566b68]
/lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0xb7569c4d]
/lib/i686/cmov/libcrypto.so.0.9.8(CRYPTO_free+0x3a)[0xb4eed06a]
/lib/i686/cmov/libcrypto.so.0.9.8(ERR_set_error_data+0x4f)[0xb4f5b83f]
/lib/i686/cmov/libcrypto.so.0.9.8(ERR_add_error_data+0xed)[0xb4f5c3dd]
/lib/i686/cmov/libcrypto.so.0.9.8(PEM_bytes_read_bio+0x339)[0xb4f8c629]
/lib/i686/cmov/libcrypto.so.0.9.8(PEM_ASN1_read_bio+0x57)[0xb4f8ed17]
/lib/i686/cmov/libcrypto.so.0.9.8(PEM_read_bio_X509_AUX+0x46)[0xb4f8ecb6]
/lib/i686/cmov/libcrypto.so.0.9.8(X509_load_cert_file+0x14e)[0xb4f99f9e]