Skip to content

Instantly share code, notes, and snippets.

View wheeyls's full-sized avatar

Michael Wheeler wheeyls

View GitHub Profile
@wheeyls
wheeyls / auth.rb
Last active September 20, 2017 22:16
require 'googleauth'
require 'googleauth/stores/file_token_store'
module SEO
class Auth
OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
USER_ID_KEY = 'GOOGLE_SEARCH_CONSOLE_USER_ID'
attr_reader :token_file, :secret, :id
@wheeyls
wheeyls / versioned_filename.rb
Last active April 14, 2017 18:58
Setting up Cache-Control for CarrierWave uploads - making sure that file names are updated to keep the cache fresh.
# This is for versioning files that we upload to S3.
#
# We want a unique time stamp in the name, so that we can cache files on browsers without
# worrying about cache-busting.
#
# The tricky part is deciding when to increment the version, this is accomplished
# by binding to the +before_cache+ hook.
#
# All you need to do to use this, is to call "has_versioned_filename" from an uploader,
# and add a string column "+mount_name+_version_token" to the model.
@wheeyls
wheeyls / intersection.rb
Last active December 23, 2015 13:49
Using ruby to grab an intersection of items in a list of categories.
class ManyToMany
def intersection(relation, cat_ids)
join = cat_ids.map do |cat_id|
outer_join_clause(cat_id)
end.join(' ')
where = cat_ids.map do |cat_id|
" cat#{cat_id}.id is not null "
end.join(' and ')
@wheeyls
wheeyls / basic-log.js
Last active December 19, 2015 11:08
Queue Example for my blog
function logEvent(eventData) {
$.ajax({
method: 'post',
url: '/analytics-endpoint',
data: eventData
});
}
@wheeyls
wheeyls / application_controller.rb
Last active May 15, 2022 07:04
A cached key-value store backend for Rails I18n. Designed to speed up translations when using a database like Redis or Mongo.
class ApplicationController < ActionController::Base
before_filter :ensure_fresh_i18n
private
def ensure_fresh_i18n
I18n.backend.ensure_freshness! I18n.locale
end
end
# inheritence question:
# When mixing in a module, how does super work?
# Does it behave the same for protected methods?
# And private methods?
class Parent
def log(name)
puts name
puts self.class
end
require 'stringio'
class RedisSubscribe < EM::Connection
def self.connect(host, port, pass = '')
Rails.logger.debug host
Rails.logger.debug port
client = EM.connect host, port, self
client.auth pass if pass.present?
@wheeyls
wheeyls / example.js
Last active December 14, 2015 20:40
Export a library for commonjs, nodejs, and browser.
function myLib() {
return {
code: function () {}
, goes: function () {}
, here: function () {}
}
}
exporter('myLib', myLib);
(function () {
var initializing = false
, superPattern = /xyz/.test(function () { xyz; }) ? /\b_super\b/ : /.*/;
Object.subClass = function (properties) {
var _super = this.prototype;
initializing = true;
var proto = new this();
initializing = false;
(function () {
var initializing = false
, superPattern = /xyz/.test(function () { xyz; }) ? /\b_super\b/ : /.*/;
Object.subClass = function (properties) {
var _super = this.prototype;
initializing = true;
var proto = new this();
initializing = false;