Skip to content

Instantly share code, notes, and snippets.

View ipoval's full-sized avatar

ipoval ipoval

  • Microsoft, Atlassian
  • Sydney, Australia
View GitHub Profile
@ipoval
ipoval / rails_find_unused_libs.bash
Created March 31, 2015 17:55
rails find unused libs
#
find lib/ -name "*.rb" | xargs grep -h --color -e ^class | cut -d ' ' -f 2 | sort | uniq | egrep -v "^Time" | egrep -v "^Hash" | egrep -v "^UserMailer" | while read k; do echo lib class: "$k"; grep -r -l -w -m 1 --color "$k" ./app ./config ./lib ./script --exclude-dir=*assets* | head -n 2 | wc -l | grep 1; done
@ipoval
ipoval / README.md
Last active August 29, 2015 14:16
Array#to_proc # [ { name: "A" }, { name: "B" } ].map(&[:name]) # => [ "A", "B" ]

INSTALLATION

echo "gem 'array_to_proc', git: 'git://gist.github.com/bf95dedd5a2a6046ada7.git'" >> Gemfile

or

git clone git@gist.github.com:/bf95dedd5a2a6046ada7.git
gem build array_to_proc.gemspec
gem install --local array_to_proc-0.0.1.gem
# USAGE IN RAILS APP
# config.middleware.insert_before(ActionDispatch::Static, TracePoint::Middleware)
#
class TracePoint
class Middleware
def initialize(app)
@app = app
end
def call(env)
@ipoval
ipoval / null_object_dp.rb
Created October 14, 2014 22:31
null object dp
# encoding: utf-8
# Null-Object pattern.
# - has no state by definition and can be Singleton dp
# Prevent code from cluttered if condition checks to find that object is present and is not nil.
# Naught class also has a good examples of ruby conversion operators
class Georgian
def make_it_so(logger = nil)
# HAVING THIS PROBLEM:
@ipoval
ipoval / pre-commit
Last active August 29, 2015 14:03
pre-commit hook - check trailing white-spaces, unicode chars, jshint, rubocop
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
if git rev-parse --verify HEAD >/dev/null 2>&1
@ipoval
ipoval / find_unused_rails_endpoints.sh
Last active August 29, 2015 14:03
find_unused_rails_endpoints.sh
grep "^Started " api-310?.log | \
egrep -o "\"/\w+/\w+[/\"]" | \
sed -E "s/^\"|[\"\/]$//g" | \
sort | \
uniq > api_routes.txt
be rake routes > /tmp/api/rails_routes.txt
\grep -v -h -F -f api_routes.txt rails_routes.txt | grep api
@ipoval
ipoval / rails_find_unused_partials.sh
Last active November 11, 2015 19:07
find_unused_partials_in_views.sh
ruby -e "
'`find ./app/views -name _*`'
.split
.map { |f| f.split('/').last[1..-1][/[^\.]+/] }
.each { |f| system( %Q(fgrep -rq #{f} ./app/views/) ) ? nil : p(f) }
"
@ipoval
ipoval / find_unused_images.sh
Last active August 29, 2015 14:01
find_unused_images.sh
# ! dynamically generated image names exist
# ! watch nginx logs for image requests to find unused images
find ./app/assets/images/ -type f -exec basename {} \; |
while read line; do $(grep -r $line ./app/views/ >/dev/null) ||
echo $line; done > ~/.Trash/res.txt
@ipoval
ipoval / README.md
Last active December 20, 2015 22:19
Add a custom method definition to Test Blueprints in Machinist::Mongoid. It is very handy in the tests to have extra helper methods directly on the Test Blueprints without defining those in the corresponding Model class.

INSTALLATION

echo "gem 'machinist_blueprint_with_method',\
      git: 'git://gist.github.com/6204150.git',\
      group: 'test'" >> Gemfile

EXAMPLE OF USAGE

@ipoval
ipoval / ruby_fabric.rb
Last active October 2, 2015 02:47
DP: Fabric Class
class Blog
attr_writer :post_source
def new_post
post_source.call.tap do |p|
p.blog = self
end
end
private