Skip to content

Instantly share code, notes, and snippets.

View tncbbthositg's full-sized avatar

D. Patrick Caldwell tncbbthositg

View GitHub Profile
@tncbbthositg
tncbbthositg / element_extensions.rb
Created May 14, 2015 19:41
Detecting visibility of element in viewport
module Watir
class Element
def on_screen?
windowHeight = browser.execute_script('return window.innerHeight')
elementRect = browser.execute_script('return arguments[0].getBoundingClientRect()', self)
elementTop = elementRect["top"]
return elementTop >= 0 && elementTop < windowHeight
end
end
@tncbbthositg
tncbbthositg / regex.txt
Created March 25, 2015 19:16
Regex to convert hibernate single line sql into something useful
(?:Hibernate: )|(( )(?:(?:\S)+ as (?:\S)+,?|\b(and|or|on))|\b(select|from|where|(?:inner|left) ?(?:outer )?join)\b)
@tncbbthositg
tncbbthositg / .irbrc
Created March 2, 2015 17:08
pbcopy support for irb
def pbcopy input
input.to_s.tap do |value|
IO.popen('pbcopy', 'w') { |clipboard| clipboard << value }
end
end
def pbpaste
puts `pbpaste`
end
@tncbbthositg
tncbbthositg / .pryrc
Last active August 29, 2015 14:16
Configuring Pry
# see .irbrc here: https://gist.github.com/tncbbthositg/96bfaf644172595960eb
current_directory = File.dirname __FILE__
file = File.join current_directory, ".irbrc"
load file
Pry.config.commands.command 'pbcopy', 'Copy value to clipboard' do |input|
pbcopy input.to_s
end
Pry.config.commands.command 'pbpaste', 'Paste value from clipboard' do
@tncbbthositg
tncbbthositg / .bash_profile
Last active August 29, 2015 14:13
A place to keep my bash profile helpers here and there
alias st="git status"
alias be="bundle exec"
alias ber="be rake"
alias srsly='eval "sudo `history -p \!\!`"'
alias yolo='srsly'
kill_all() {
ps aux | grep $1 | grep -v grep
[core]
safecrlf = true
pager = "less -FX"
excludesFile = ~/.gitignore
[alias]
co = checkout
ci = commit
st = status
pr = pull --rebase
@tncbbthositg
tncbbthositg / flexbox_mixins.scss
Last active August 29, 2015 14:07
Various Flexbox SASS Mixins
@mixin flex($flex-type: flex) {
$flex-type: unquote($flex-type);
@include experimental-value(display, $flex-type, not -moz, -webkit, not -o, -ms, not -khtml, official);
}
@mixin align-items($alignment) {
$alignment: unquote($alignment);
@include experimental(align-items, $alignment, not -moz, -webkit, not -o, -ms, not -khtml, official);
}
#Put this in application.rb, or in a rake task initialize code
if defined?(Rails) && (Rails.env == 'development')
Rails.logger = Logger.new(STDOUT)
end
@tncbbthositg
tncbbthositg / gist:4350639
Created December 21, 2012 04:24
Extension method for combining predicates and extension method for or conditions in linq queries.
public static IQueryable<T> WhereAny<T>(this IQueryable<T> source, params Expression<Func<T, bool>>[] predicates)
{
Expression<Func<T, bool>> filter = t => false;
foreach (var predicate in predicates)
filter = filter.Combine(Expression.OrElse, predicate);
return source.Where(filter);
}
@tncbbthositg
tncbbthositg / gist:2973839
Created June 22, 2012 16:26
XSS Attack Test Script
<script>alert('');</script>