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 / 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 / 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_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 / 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 / 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:
# 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 / 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
@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 / rails_find_unused_model.bash
Last active November 11, 2015 19:07
rails find unused model
#
find app/models/ -name "*.rb" | xargs grep -h --color -e ^class | cut -d ' ' -f 2 | sort | uniq | while read k; do echo model 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 / rails_unicorn_start_fg.bash
Created July 26, 2015 18:08
start rails unicorn web server in foreground
#!/usr/bin/env bash
# Run unicorn in the foreground and customize how it runs.
#
# Usage: ./script/start_rails_fg.bash
# ./script/start_rails_fg.bash --help
# supports these env variables: UNICORN_PID
# UNICORN_LISTEN
# UNICORN_STDERR_PATH
# UNICORN_STDOUT_PATH