Skip to content

Instantly share code, notes, and snippets.

class ProductSearch < ScopeBuilder::Scope
param :name, :string
param :category, :integer
param :status, :string
order_by :name, :created_at
private
def apply_name_param(scope, value)
defmodule Broker.Workers.Appsignal do
@moduledoc false
alias Appsignal.Error
alias Appsignal.Transaction
def handle_event([:oban, event], measurement, meta, _) when event in [:success, :failure] do
transaction = record_event(measurement, meta)
if event == :failure && meta.attempt >= meta.max_attempts do
{reason, message, stack} = normalize_error(meta)
defmodule MyApp.Delegator do
defmacro __using__(opts) do
quote do
def unquote(:"$handle_undefined_function")(name, args) do
apply(Keyword.get(unquote(opts), :target), name, args)
end
end
end
end
@lucasmazza
lucasmazza / dabblet.css
Created August 28, 2018 00:19
Slide up menu
/**
* Slide up menu
*/
.thing {
box-sizing: border-box;
position: absolute;
bottom: 0;
left: calc(50% - 200px);
height: 50px;
$ ruby thing.rb
[Calculator::LoggerDecorator, Calculator, Object, Kernel, BasicObject]
Calculator#div(10, 2) => 5
# frozen_string_literal: true
module Airbrake
module Sidekiq
# Internal: Airbrake filter that ignores exceptions from Sidekiq Jobs that
# will be retried.
class RetryableJobsFilter
def call(notice)
job = notice[:params][:job]
# Rewrite VCR Cassettes to move the URL:PASSWORD pair from
# the 'uri' to the 'Authorization' header.
# This is required when moving from WebMock 1 to 2+.
require 'yaml'
require 'uri'
require 'base64'
Dir["spec/fixtures/vcr_cassettes/*.yml"].each do |path|
cassette = YAML.load_file(path)
@lucasmazza
lucasmazza / picture_helper.rb
Created September 15, 2016 18:30
Helper method to generate `picture` tags.
module PictureHelper
# Public: Generate a `picture` tag with multiple sources for different formats
# (JPG, WEBP, PNG, etc) and with support for high density displays. An `img`
# element will also be created, so the User Agent can display it's selected
# source and use as a fallback if it doesn't support the `picture` element yet.
#
# Examples
#
# # => picture_tag('blankslate', formats: %(webp png))
# This call will return a `picture` element with two `source` children
# cleanup existing assets and cached files
rm -rf public/assets tmp/cache/assets
# Stop and start Spring to ensure we have a pristine process
# and to remove the Rails boot time from the benchmark.
bin/spring stop
bin/rake secret > /dev/null
time bin/rake assets:precompile
@lucasmazza
lucasmazza / assets.rake
Created May 10, 2016 03:06
`rake assets:stats`
namespace :assets do
# Display all precompiled assets and their included
# dependencies.
#
# Arguments:
# * '--sort' sort the included deps list by their file size.
#
# bin/rake assets:stats [-- --sort]
desc 'List file size for precompiled assets'
task stats: :environment do