Skip to content

Instantly share code, notes, and snippets.

@teeparham
teeparham / cx.js
Last active January 17, 2024 18:15
classnames & clsx replacement
// https://dev.to/gugaguichard/replace-clsx-classnames-or-classcat-with-your-own-little-helper-3bf
export function cx(...args: unknown[]) {
return args
.flat()
.filter((x) => typeof x === "string")
.join(" ")
.trim();
}
@teeparham
teeparham / rdoc2md.rb
Last active November 7, 2023 00:47
Convert rdoc to markdown
require 'rdoc'
converter = RDoc::Markup::ToMarkdown.new
rdoc = File.read(ARGV[0] || 'README.rdoc')
puts converter.convert(rdoc)
# ruby rdoc2md.rb > README.md
# ruby rdoc2md.rb ABC.rdoc > abc.md
@teeparham
teeparham / strings.rb
Last active January 29, 2019 19:26
Ruby multi-line string performance
require "benchmark"
require "active_support/core_ext/string/strip"
n = 10_000
Benchmark.bm do |bm|
bm.report("string") do
n.times do
"hello\nthere\nbear"
end
@teeparham
teeparham / stats.rake
Created November 9, 2018 18:17
Add directories to rake stats
# lib/stats.rake
require "rails/code_statistics"
task stats: :more_stats
task :more_stats do
%w[Forms Policies Presenters Serializers Services].each_with_index do |type, i|
STATS_DIRECTORIES.insert i + 5, [type, "app/#{type.downcase}"]
STATS_DIRECTORIES.insert i * 2 + 13, ["#{type} tests", "test/#{type.downcase}"]
@teeparham
teeparham / web-image.sh
Created February 26, 2018 23:36
optimize jpeg images for web
# -colorspace Gray/sRGB
convert in.jpg -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG out.jpg
@teeparham
teeparham / combine.sh
Created February 26, 2018 23:35
ffmpeg video conversion for browsers
# -movflags +faststart
# combine series of pngs into a mp4 movie
# frame-0001.png
# frame-0002.png
ffmpeg -framerate 0.3 -i frame-%04d.png -vf scale=752:424 -vcodec h264 -pix_fmt yuv420p -an -crf 15 -r 24 -y out.mp4
@teeparham
teeparham / self.rb
Created February 9, 2015 18:10
Why you should use implicit self in ruby
class X
# implicit self
def get
value
end
# explicit self does not work when you call a private method
def get_self
self.value
end
@teeparham
teeparham / grep.sh
Last active January 18, 2018 22:20
rails log grep
grep -C500 --group-separator=================== some/url production.log |
grep -v "^[Read|Write|Completed|Processing|Act|\/usr|\-]" |
grep -v "^[[:space:]][[:space:]]Re" |
more
@teeparham
teeparham / config.yml
Created November 8, 2017 21:05
CircleCI config for rails + postgis
version: 2
jobs:
build:
parallelism: 1
working_directory: ~/yourapp
environment:
DATABASE_URL: postgis://postgres@localhost/yourapp_test
docker:
- image: circleci/ruby:2.4-node-browsers
env:
@teeparham
teeparham / win-paperclip.js
Last active October 12, 2017 16:27
Win Paperclip
// moved to https://github.com/teeparham/win-paperclip
// http://www.decisionproblem.com/paperclips/index2.html
function click (id) {
document.querySelector(id).click();
}
function multiClick (id, n) {
for (i = 0; i < n; i++) {