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 / 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 / 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 / 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 / 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++) {
@teeparham
teeparham / log.txt
Last active April 19, 2017 17:38
rails rendering analysis
$ time { render "haml" }
Rendered _haml.html.haml (0.5ms)
----> 1.51 ms
$ time { render "erb" }
Rendered _erb.html.erb (0.4ms)
----> 1.78 ms
# using hamlit
# there is little difference in rendering erb & haml
@teeparham
teeparham / test.rb
Created October 4, 2016 16:11
Don't put your tests in modules
class X
def x
"X"
end
end
module Y
class X
def x
"Y::X"