Skip to content

Instantly share code, notes, and snippets.

View stratigos's full-sized avatar
🧑‍🔬
Building the Internet

Todd stratigos

🧑‍🔬
Building the Internet
View GitHub Profile
@stratigos
stratigos / rspec_shared_example_with_shoulda_matchers_for_booleans.rb
Created April 19, 2018 16:46
RSpec Boolean Matcher Shared Example with Shoulda Matchers
# Shared specs for models with the `:validates_inclusion_of` validators, where
# Boolean values are specified. This is for use cases where Booleans are used
# in non-null DB columns, and validation errors need to be returned to actors
# attempting to store a NULL value (e.g., a IoT unit's firmware uploading a
# NULL value for an On/Off sensor reading).
# Additionally, `shoulda` will complain if `validate_inclusion_of` is used
# with the Booleans, and instead of turning off warnings, its best to just
# approach these specs differently. See
# [this github comment](https://github.com/thoughtbot/shoulda-matchers/issues/922#issuecomment-225752673)
# for more info.
@stratigos
stratigos / ruby_memory_profile_example.rb
Last active January 9, 2017 21:40
Example Tool for Profiling Memory Use in Ruby Scripts and Applications
#################################
# GEMFILE: gem 'get_process_mem'
#################################
require 'get_process_mem'
def profile_mem(description=nil)
mb = GetProcessMem.new.mb
puts "\n\n---- #{ description } - MEMORY USAGE(MB): #{ mb.round } ----\n\n"
end
@stratigos
stratigos / .rspec
Created January 9, 2017 21:39
RSpec Configuration
--color
--require spec_helper
# 'ls' without ignoring dotfiles, using long list format, in human readable form, and display long ISO format for time
alias lsa="ls -alh --time-style=long-iso"
# view 'git diff' in vim
alias gdif="git diff | vim -R -"
@stratigos
stratigos / .bash_func_lame-encode-dir
Created November 12, 2015 14:17
Call a function to use lame to encode an entire directory of MP3s to ~200Kbps VBR
# lame encode mp3s in directory to ~200 kbs
function lamev2 { for f in *.mp3; do lame -h -V 2 "$f" tmp && mv tmp "$f"; done }
@stratigos
stratigos / .bash_alias_git-diff-ruby-debug
Created November 12, 2015 14:15
Check for debug code / leftover TODO notes in Ruby/Rails code
alias gdifrd="git diff | egrep -i '(puts)|(abort)|(debug)|(byebug)|(alert)|(console.log)|(TODO)'"
@stratigos
stratigos / Apache Error Log with Newlines
Last active October 29, 2015 22:07
View apache error log with newlines for each entry, formatted with sed
# place in .bash_aliases or similar shell setup file
alias elog="tail -f /var/log/httpd/your-error_log | sed -e 's/\\\n/\n/g'"
@stratigos
stratigos / Check for PHP debug code in an SVN diff
Last active October 29, 2015 22:06
Check SVN Working Copy for Debug Code
# place in ~/.bash_aliases or ~/.profile or something similar
alias svndiffd="svn diff | egrep '(print_r)|(die\()|(error_log)|(debug)|(DEBUG)|(todo)|(TODO)|(console.log)|(alert\()'"
@stratigos
stratigos / searchReplaceStatLint.sh
Created January 9, 2015 17:51
Bash Search Replace Text in Files in a Directory, SVN stat the Files, and PHP Lint each modified file.
#!/bin/bash
if [[ $# -ne 3 ]];
then
echo "USAGE: sh $0 {search_string} {replace_string} {dirname}"
exit 1
else
echo Searching for $1 and replacing with $2 in all files in directory $3 ...
ack -Q -l "$1" $3 | xargs sed -i 's/'"$1"'/'"$2"'/g'
echo checking 'SVN stat' of each modified file, and running a PHP lint on each...
echo ----------------------------------------------------------------------------