Skip to content

Instantly share code, notes, and snippets.

View pingortle's full-sized avatar
🤝
nice to meet you

Kaleb Lape pingortle

🤝
nice to meet you
View GitHub Profile
thing.audio.open do |file|
input = file.path
output = "#{file.path}.mp3"
filename = "#{thing.audio.filename}.mp3"
system("ffmpeg", "-i", input, output, exception: true)
thing.audio_mp3.attach(io: File.open(output), filename:, content_type: "audio/mpeg")
ensure
File.delete(output) if File.exist?(output)
end
@pingortle
pingortle / lint.yml
Last active April 6, 2023 16:12
GitHub action to create linter fix PRs against your PRs
name: lint
on:
pull_request:
push:
branches: [ master ]
jobs:
lint-js:
if: ${{ !startsWith(github.head_ref, 'dependabot/') }}
@pingortle
pingortle / net_http_follow_redirects.rb
Created March 21, 2023 19:45
Here's a little snippet that follows redirects up to a limit.
max_redirects = 3
# Follow redirects
response = max_redirects.times.lazy.filter_map {
puts "Requesting #{url}…"
response = Net::HTTP.get_response(URI(url))
case response
when Net::HTTPRedirection
url = response["location"]
nil
github_keys = accounts.map { |account|
Net::HTTP.get(URI("https://github.com/#{account}.keys"))
.lines(chomp: true)
.map { |line| "#{line} @#{account}" }
}.flatten
class RawQueryParam < SimpleDelegator
def to_query(key)
"#{key}=#{value}"
end
end
# …
whatever_url(@whatever, host: "bogus.dev", blah: RawQueryParam.new("{test}"))
# => "http://bogus.dev/whatever?blah={test}"
class WishlistFlowsTest < ActionDispatch::IntegrationTest
setup do
@builder = Builder.new
end
test "can make a wish" do
wisher = @builder.users(name: "George Wishington").create!
sign_in_as(wisher)
assert_changes "Wish.count" do
module Seeders
class Base
def seed!(builder, findable_attributes, unstable_attributes = {})
builder.find_or_create_by!(findable_attributes) do |config|
config.assign_attributes(unstable_attributes)
end
end
end
class Builder
@pingortle
pingortle / README.md
Last active October 6, 2020 14:25
Experimental Minitest around_each hook

Characteristics

  • Completely wraps the minitest test lifecycle (setup, teardown, and friends…). This may lead to surprising results.
  • Supports multiple calls to around_each. Each subsequent around_each call wraps around the previous one. Is this unintuitive? I don't know. 🤷‍♂️
@pingortle
pingortle / apps.txt
Last active September 6, 2020 02:08
My brews as of now.
1Password 7.app
Alacritty.app
App Store.app
Atom.app
Audacity.app
Automator.app
Basecamp 3.app
Be Focused Pro.app
Be Focused.app
Beaker Browser.app
@pingortle
pingortle / compose.rb
Created September 1, 2020 16:45
Playing with functional composition in ruby.
if Gem::Version.new("2.6") <= Gem::Version.new(RUBY_VERSION)
def compose(*funcs)
funcs.map(&:to_proc).reduce(:<<)
end
else
def compose(*funcs)
funcs.map(&:to_proc).reduce { |f, g| ->(*x) { f.call(g.call(*x)) } }
end
end