Skip to content

Instantly share code, notes, and snippets.

View adamlogic's full-sized avatar

Adam McCrea adamlogic

View GitHub Profile
@adamlogic
adamlogic / scout.rb
Created February 22, 2024 16:22
Scout APM sampling
# Apply a sample rate to Scout so it only instruments a portion of requests
# or jobs. Here's an example of how to use it in a controller action or job:
# ScoutApm::Transaction.use_sample_rate 0.001
module ScoutApm
module Transaction
# Set SCOUT_SAMPLING=false to disable sampling. This will send all transactions to Scout,
# and very quickly use up our monthly transaction limit.
USE_SAMPLING = ENV["SCOUT_SAMPLING"] != "false"
def self.use_sample_rate(rate)
@adamlogic
adamlogic / adapter_setup_component.rb
Created January 23, 2024 16:07
GoRails Phlex Demo
# frozen_string_literal: true
class AdapterSetupComponent < ApplicationComponent
def initialize(app, process_type)
@app = app
@process_type = process_type
end
def template
render ModalComponent.new do |modal|
@adamlogic
adamlogic / components.foo-bar.js
Last active February 14, 2020 15:05 — forked from givanse/components.foo-bar.js
Ember runloop demonstration with a computed property and an observer
import Ember from 'ember';
export default Ember.Component.extend({
sourceInternal: 'default',
logs: [],
source: Ember.computed('sourceInternal', {
get: function() {
this._log(`[source getter] sourceInternal=${this.get('sourceInternal')}`);
return this.get('sourceInternal');
@adamlogic
adamlogic / In the beginning, there was require.md
Created November 24, 2019 01:45
Presentation given at RubyConf 2019. This is the source for my slides, used with Deckset (paid Mac app).

build-lists: true

In the beginning
there was require


confession

Event.where(date_end: (Time.current.midnight .. Time.parse('2020-01-01'))).cache_key
#=> "events/query-38261fed1ce8f823ec1c05f19e0123fb-0"
Event.where(date_end: (Time.current .. Time.parse('2020-01-01'))).cache_key
#=> "events/query-a5aea4fdf9842521af708f1d663a710b-0"
@adamlogic
adamlogic / Procfile
Created September 8, 2018 14:51
Sample Procfile using parameter expansion
release: RAILS_MAX_THREADS=1 rails db:migrate
web: RAILS_MAX_THREADS=$PUMA_THREADS rails c
worker: RAILS_MAX_THREADS=$SIDEKIQ_THREADS bundle exec sidekiq
# heroku config:add RAILS_MAX_THREADS=1 so one-off dynos don't consume more than necessary
@adamlogic
adamlogic / pgpull
Last active January 17, 2018 15:13
Wrapper script around `heroku pg:pull` for loading a local database
#!/bin/bash
# Example:
# pgpull -r production
#
# Options are passed through to `heroku pg:pull`, so this would look for a git branch
# named "production".
opts=$*
# Replace this with your local database name
# This is a simple script to convert an XML file exported
# from Evernote into a bookmarks file that can be imported
# into Pinboard. In my case, all I cared about were notes
# that had a source-url, and all I'm retaining is the title
# and URL. I'm adding a fixed "evernote" tag for all notes.
require 'nokogiri'
def note_attributes(note)
{
@adamlogic
adamlogic / extracting.md
Created November 19, 2012 18:26
Extracting to a Gem

Extracting to a gem

Notes for a Columbus Ruby Brigade live-coding talk on 11-19-2012.

  1. Compartmentalize the feature within your project
    • define your API
    • use bundle open and undefined method errors to discover "hooks" for your feature
  2. Create gem skeleton
    • bundle gem gemname
  • add info to gemspec
@adamlogic
adamlogic / ghpreview.sh
Created November 9, 2012 17:14
Preview a Markdown file using Github's conversion and styling
#!/bin/bash
md_filename=$1
html_filename=/tmp/ghpreview.html
url=https://api.github.com/markdown/raw
# Markdown to HTML
html=`curl --data-binary @$md_filename -H 'Content-Type:text/plain' $url`
# Grab Github's fingerprinted stylesheets