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
@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 / 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]
@cpuguy83
cpuguy83 / gist:5653837
Created May 26, 2013 19:55
New crash on Rbx commit# 2dc4bdaa
Backtrace:
rbx[0x81bb41a]
[0xb7863400]
rbx(jit_stub_string_equal+0x5e)[0x82115be]
[0xa0340d54]
rbx(_ZN8rubinius12CompiledCode20specialized_executorEPNS_5StateEPNS_9CallFrameEPNS_10ExecutableEPNS_6ModuleERNS_9ArgumentsE+0x92)[0x82fd9b2]
rbx(_ZN8rubinius15MonoInlineCache11check_cacheEPNS_5StateEPNS_8CallSiteEPNS_9CallFrameERNS_9ArgumentsE+0x4f)[0x8323d8f]
rbx(_ZN8rubinius11MachineCode11interpreterEPNS_5StateEPS0_PNS_20InterpreterCallFrameE+0x1fc5)[0x81dbbf5]
rbx(_ZN8rubinius11MachineCode19execute_specializedINS_16GenericArgumentsEEEPNS_6ObjectEPNS_5StateEPNS_9CallFrameEPNS_10ExecutableEPNS_6ModuleERNS_9ArgumentsE+0x5ac)[0x8227c2c]
rbx(_ZN8rubinius15PolyInlineCache11check_cacheEPNS_5StateEPNS_8CallSiteEPNS_9CallFrameERNS_9ArgumentsE+0xd1)[0x834dce1]
@cpuguy83
cpuguy83 / gist:5663189
Created May 28, 2013 14:34
With JIT disabled?
Error: signal SIGSEGV
[[Backtrace]]
rbx[0x81bb41a]
[0xb7868400]
rbx(_ZN8rubinius4Data8finalizeEPNS_5StateEPS0_+0xd6)[0x8300636]
rbx(_ZN8rubinius16FinalizerHandler8finalizeEPNS_5StateE+0x248)[0x8394b58]
rbx(_ZN8rubinius16FinalizerHandler7performEPNS_5StateE+0xa4)[0x83963e4]
rbx(_ZN8rubinius23finalizer_handler_trampEPNS_5StateE+0x27)[0x8396707]
rbx(_ZN8rubinius6Thread13in_new_threadEPv+0x3d8)[0x8361928]