Skip to content

Instantly share code, notes, and snippets.

View skwp's full-sized avatar

Yan Pritzker skwp

View GitHub Profile
" This function is trying to pass a grep pattern to Ag
" but it seems that the grepPattern is not well escaped
function! AgCurrentPartial()
let fileNameWithoutExtension = expand('%:t:r')
let fileNameWithoutUnderscore = substitute(fileNameWithoutExtension, '^_','','g')
let grepPattern = "render.*[\'\"].*" . fileNameWithoutUnderscore
echom renderInvocationGrepPattern
exec 'Ag "' . grepPattern . '"'
endfunction
@skwp
skwp / _sublayout.haml
Created November 18, 2014 22:56
Sublayouts
.sublayout
.this-is-a-partial
= yield # this will render the content inside the sublayout
@skwp
skwp / logger_spec.rb
Last active August 29, 2015 14:11
Logger that logs to a string
describe "something with a logger" do
let(:logger) { TestLogger.new }
before { Rails.logger = logger }
specify do
# ... call your code ...
logger.messages.should include("my message")
end
end
@skwp
skwp / roar_nil_defaults.rb
Created January 23, 2015 17:15
roar_nil_defaults.rb
require 'roar/decorator'
# Ok..get ready for a fun one:
#
# We use Roar::Decorator to serialize into our search engine (ElasticSearch)
# Example: app/reverb/search/serializers/product.rb
#
# When we serialize fields that are false or nil (booleans), they are omitted
# from the json by default.
#
Fixture.class_eval do
def find
if model_class
if model_class.respond_to?(:find_with_deleted)
model_class.find_with_deleted(self[model_class.primary_key])
else
model_class.find(self[model_class.primary_key])
end
else
raise FixtureClassNotFound, "No class attached to find."
class YamlErb
# Loads a yaml file that contains erb
def self.load_file(path)
YAML.load(ERB.new(File.read(path)).result)
end
end
class BlocksAreProcs
def try_to_invoke_block
foo do
puts "start here"
return
end
end
def foo
yield
class MyController < ApplicationController
class SomeWisperThing
include Wisper::Publisher
def execute
publish :foo
end
end
def create
class BatchStatusPaginator
include Sidekiq::Paginator
def initialize(page_size=25)
@page_size = page_size
end
# Get all batch statuses
def all
current_page, total_size, items = batches(1)
class ThreadFactory
if ENV['RAILS_ENV'] == 'development'
class FakeThread
def initialize(&block)
block.call
end
end
def initialize(&block)
FakeThread.new(&block)