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 / 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_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
@ipoval
ipoval / http_authentication
Created February 23, 2011 17:51
Http basic authentication for padrino
module HttpAuthentication
module Basic
def authenticate_or_request_with_http_basic(realm = 'Application')
authenticate_with_http_basic || request_http_basic_authentication(realm)
end
def authenticate_with_http_basic
if auth_str = request.env['HTTP_AUTHORIZATION']
return 'login:password' == ActiveSupport::Base64.decode64(auth_str.sub(/^Basic\s+/, ''))
end
@ipoval
ipoval / unix_ipc.rb
Created September 25, 2015 04:34
Inter-process communication in UNIX
# IPC 1 - IO.pipe to set up the UNIX-pipe-based interprocess communication
in_r, in_w = IO.pipe; out_r, out_w = IO.pipe; err_r, err_w = IO.pipe
pid = spawn('cat -n', in: in_r, out: out_w, err: err_w)
[in_r, out_w, err_w].each(&:close)
in_w.puts("signal to process")
in_w.close