Skip to content

Instantly share code, notes, and snippets.

@bearded-avenger
bearded-avenger / do_something.rb
Created July 22, 2020 17:16
Simple Role based Authorization for Ruby on Rails
# Roles Table
Role.create([{name:'admin'},{name:'staff'}])
# Users Roles Table
UserRole.create(user: User.find_by_username('corndog'), role: Role.find_by_name('admin'))
# User Model
class User < ApplicationRecord
def role?(role)
role.kind_of?(Array) ? role.map { |role| has_role?(role) }.any? : has_role?(role)
@bearded-avenger
bearded-avenger / add_remove.html.erb
Last active July 2, 2020 15:50
Bookmarking in Rails
# In a View
<%= render 'bookmarks/add_remove', record: @lesson %>
# The Partial
<% if current_customer && current_customer.bookmarked_content?(record) %>
<%= button_to bookmark_path(current_customer.bookmark_for_content(record), bookmarkable_type:record.class.name, bookmarkable_id:record.id), method: :delete, class:'btn btn-sm btn-light box-shadow', form_class:'add-remove-bookmark', data:{disable_with:'Removing...'}, remote: true do %>
<%= ms_icon('minus-circle', title:'Unsave This') %>
<% end %>
<% else %>
<%= button_to bookmarks_path(bookmarkable_type:record.class.name, bookmarkable_id:record.id), method: :post, class:'btn btn-sm btn-light box-shadow', form_class:'add-remove-bookmark', data:{disable_with:'Adding...'}, remote: true do %>
module Checkups::Notify
require 'slack-notify'
class Dispatch
def initialize(params)
@message = params[:message]
@room = params[:room] || '#web-dev_events'
@botname = params[:botname] || 'EDU Bot'
@bearded-avenger
bearded-avenger / devise.rb
Last active January 11, 2022 17:04
Rails - SSO - WordPress - Authenticating against a WordPress install from a Rails site using oAuth
config.omniauth :wordpress_hosted, ENV['SSO_KEY'], ENV['SSO_SECRET'],
strategy_class: OmniAuth::Strategies::WordpressHosted,
client_options: { site: ENV['SSO_URL'] }
@bearded-avenger
bearded-avenger / lasso-sample-meta-plugin.php
Last active August 29, 2015 14:22
lasso sample meta plugin
<?php
/**
* Plugin Name: Lasso Sample Settings Addon
*
*/
add_filter('lasso_modal_tabs','try_tabs');
function try_tabs( $tabs ){
$tabs[] = array(
@bearded-avenger
bearded-avenger / social.php
Last active August 29, 2015 14:16
dead-simple-social-shit-4000-super-duper-beards-with-goats.php
<?php
/**
*
* This class holds all teh functionality for social sharing and social data so you dont need a plugin
* Ex: https://lasso.is/now-entering-the-arena/ (bottom)
*
* use social sharing like so:
* <a href="#" class="post-share__twitter">share twitter</a>
* <a href="#" class="post-share__fb">share fb</a>
.lead {
font-size: 1.3em;
font-weight: 200;
line-height: 1.6;
&.dropcap:first-letter {
float: left;
font-size: 3.4rem;
line-height: 2rem;
padding-top: 1.2rem;
@bearded-avenger
bearded-avenger / mixin.less
Created February 22, 2015 14:49
Grid Layout - CSS - nth child
// this targets 1,5,7,11,13,17,19...
.ale--66 {
&:nth-child(6n+1),
&:nth-child(6n+5){
width:66.666%;
}
}
// this targets - 2,4,8,10,14,16,20....
.ale--33 {
add_shortcode('ideas','ideas_shortcode');
function ideas_shortcode(){
ob_start();
$args = array(
'post_type' => 'ideas',
'posts_per_page' => -1
);
$q = new WP_Query($args);
@bearded-avenger
bearded-avenger / author-network-posts.php
Created November 7, 2014 19:36
Return a list of posts by a specific author no matter the site on the multisite network
/**
*
* Return a list of posts by a specific author no matter the site on the multisite network
*
* @param $userid int id of a user
* @param $limit int number of results to return
*
*
*/
function get_user_posts_on_network( $userid = 0, $limit = 9 ) {