Skip to content

Instantly share code, notes, and snippets.

Avatar

Tee Parham teeparham

View GitHub Profile
@teeparham
teeparham / stats.rake
Created Nov 9, 2018
Add directories to rake stats
View stats.rake
# 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 Jan 29, 2019
Ruby multi-line string performance
View strings.rb
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 Feb 26, 2018
optimize jpeg images for web
View web-image.sh
# -colorspace Gray/sRGB
convert in.jpg -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG out.jpg
@teeparham
teeparham / combine.sh
Created Feb 26, 2018
ffmpeg video conversion for browsers
View combine.sh
# -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 Jan 18, 2018
rails log grep
View grep.sh
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 Nov 8, 2017
CircleCI config for rails + postgis
View config.yml
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:
View win-paperclip.js
// 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 Apr 19, 2017
rails rendering analysis
View log.txt
$ 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 Oct 4, 2016
Don't put your tests in modules
View test.rb
class X
def x
"X"
end
end
module Y
class X
def x
"Y::X"
View pg_arrays.rb
# migrate
add_column :doges, :friends, :text, array: true, default: []
# add an index
add_index :doges, :friends, using: :gin
# create a Doge
Doge.create(name: "Doge", friends: ["snoop", "snoopy"])
# any Doge contains a friend snoop