Skip to content

Instantly share code, notes, and snippets.

View tncbbthositg's full-sized avatar

D. Patrick Caldwell tncbbthositg

View GitHub Profile
#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 / 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);
}
@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
@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 / .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 / 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 / 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
[1, 0, 2, 1, 0, 2, 1, 0, 2, 1]
[1, 0, 2, 1, 0, 2, 1, 0, 2, 1]
[1, 0, 2, 1, 0, 2, 1, 0, 2, 1]
user system total real
eager_map 0.370000 0.010000 0.380000 ( 0.373325)
lazy_map 1.130000 0.010000 1.140000 ( 1.142926)
composed 0.540000 0.000000 0.540000 ( 0.545507)
user system total real
@tncbbthositg
tncbbthositg / euler_1.rb
Created June 12, 2015 14:41
Solutions to Project Euler Problem #1
require 'benchmark'
def plain_map n
# Enter your code here. Read input from STDIN. Print output to STDOUT
three_or_five = -> i {i % 3 == 0 || i % 5 == 0}
total = (0...n.to_i).inject(0) do |sum, i|
next sum unless three_or_five.call(i)
sum + i
end
@tncbbthositg
tncbbthositg / ses_smtp_password.rb
Created August 13, 2015 15:50
Compute SES SMTP password from AWS secret key
#!/usr/bin/env ruby
require 'openssl'
require 'base64'
key = ARGV[0]
message = 'SendRawEmail'
version = 0x02
digest = OpenSSL::Digest.new('sha256')