Skip to content

Instantly share code, notes, and snippets.

@mynameispj
mynameispj / Props
Created July 24, 2012 14:55
Estimated reading time in PHP, by Brian Cray
Total props to Brian Cray: http://briancray.com/posts/estimated-reading-time-web-design/
@mynameispj
mynameispj / application_helper.rb
Created June 2, 2013 00:24
Rails - Easy "active" classes for menu links in Rails
module ApplicationHelper
def current_class?(test_path)
return 'active' if request.path == test_path
''
end
end
@mynameispj
mynameispj / props.txt
Created February 8, 2013 22:05
Simple sticky elements with no jQuery plugin
http://daigo.org/2011/09/quick-and-dirty-sticky-elements-when-scrolling-using-jquery/
@mynameispj
mynameispj / .gitignore
Last active January 2, 2021 02:37
Git Ignore SASS cache files
# Ignore docs files
styles/.sass-cache
styles/.sass-cache/*
# Not working?
# Try: http://stackoverflow.com/questions/11451535/gitignore-not-working
# Try: http://stackoverflow.com/questions/1139762/gitignore-file-not-ignoring
@mynameispj
mynameispj / orientationChange.js
Last active September 3, 2020 19:39
jQuery event that fires when the orientation (portrait, landscape) of a mobile device changes
window.addEventListener("orientationchange", function() {
alert(window.orientation);
//do whatever you want on orientation change here
}, false);
@mynameispj
mynameispj / dropdown.html
Last active December 22, 2019 16:05
Simple jQuery dropdown boxes that disappear when you click outside of them
<a class="drop-down-toggle">Click me to reveal drop down box below...</a>
<div class="drop-down-wrapper">
Hello, I will be revealed!
</div>
@mynameispj
mynameispj / view.html.erb
Created June 11, 2013 08:26
Rails - each do loop with message if the loop is empty
<% if @project_quantity.each do |quantity| %>
<%= quantity.quantity %>
<% end.empty? %>
0
<% end %>
@mynameispj
mynameispj / css-triangle-mixin.sass
Last active June 13, 2017 20:38
SASS mixin to help build CSS triangles (CSS triangle hat-tip to CSS-Tricks: http://css-tricks.com/snippets/css/css-triangle/)
@mixin css-arrow($color:#000, $size:'5px', $direction:'up')
width: 0
height: 0
@if $direction == 'up'
border-right: $size solid transparent
border-left: $size solid transparent
border-bottom: $size solid $color
@if $direction == 'down'
@mynameispj
mynameispj / node.tpl.php
Created April 5, 2012 19:45
Drupal 7 - $messages in node.tpl.php
global $global_messages;
print $global_messages;
@mynameispj
mynameispj / htmlspecialchars.js
Created February 3, 2013 20:35
HTML Special Characters in jQuery
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}