Skip to content

Instantly share code, notes, and snippets.

@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 / controller.rb
Created March 23, 2013 21:38
In Rails, redirect a logged in user from the home page to another page
def home
if current_user.present?
redirect_to projects_url
end
end
@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 / responsive-iframe.css
Created April 13, 2013 21:44
Responsive Youtube embeds
.videoWrapper {
position: relative;
padding-bottom: 56.25%;
padding-top: 25px;
height: 0;
}
.videoWrapper iframe {
position: absolute;
top: 0;
@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 / default.rb
Last active December 16, 2015 12:38
Prettier Rails confirm dialogs
<%= link_to 'Delete this junk', junk_path(j), :method => :delete, :confirm => 'You sure you want to delete this junk?' %>
@mynameispj
mynameispj / menu.html.erb
Created June 1, 2013 06:28
Rails ".active" link method approach
<%= link_to "account stats", account_path, :class => current_page?(:controller => 'experiments') ? 'active':'' %>
@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 / module.module
Created June 10, 2013 05:52
Drupal 7: add a custom View Mode
/**
* Implements hook_entity_info_alter().
*/
function MYMODULE_entity_info_alter(&$entity_info) {
$entity_info['node']['view modes']['another_teaser'] = array(
'label' => t('Another teaser'),
'custom settings' => TRUE,
);
}
@mynameispj
mynameispj / node.tpl.php
Created June 11, 2013 06:30
Print a Drupal 7 Block programmatically
// block_load docs: https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_load/7
// Get the arguments from the second- and third-to-last segments of a block's configure URL
// For instance: /#overlay=admin/structure/block/manage/webform/client-block-150/configure
$block = block_load('webform','client-block-150');
print drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));