Skip to content

Instantly share code, notes, and snippets.

View randyleighton's full-sized avatar
☺️
Build It! Release It!

Randy Leighton randyleighton

☺️
Build It! Release It!
  • G5
  • Bend
View GitHub Profile
@randyleighton
randyleighton / kube_commands.rb
Created February 1, 2019 23:10 — forked from levibrown/kube_commands.rb
a cli for common g5 kube commands
#!/usr/bin/env ruby
# Setup:
# 1) `gem install highline`
# 2) save this file to a local folder
# 3) rename the file to remove extension `mv kube_commands.rb kube_commands`
# 4) change permissions `chmod 755 kube_commands`
# 5) link to your /usr/local/bin `ln -s $PWD/kube_commands /usr/local/bin/`
# 6) in a new shell you should now be able to run `kube_commands`
# 7) add new commands and add to this gist
@randyleighton
randyleighton / gist:fbc20356d12fac68e4f3
Created January 5, 2015 05:23
Rails collection select use first name AND last name for the value in the list
Here is the code for the form, this is setup to look nice on a horizontal bootstrap form. Note the prompt:true, it puts a message in the select for the user to pick something, instead of forcing a default value.
<div class="form-group">
<%= f.label "Choose a Contact", class: "col-xs-12 col-sm-2"%>
<div class="col-xs-3 col-sm-3">
<%= f.collection_select :contact_id, @company.contacts, :id, :full_name, prompt: true, class: 'form-select' %>
</div>
</div>
How do you make this work? In the contact model add this:
@randyleighton
randyleighton / gist:c66afcfd41507b072546
Created January 1, 2015 07:07
Rails form submit button partial, support for new/edit record detect and font awesome icons
So at the top of the form helper you have something like this..
this is your _form partial you are using for new and edit.
<%= form_for(@company, html: { class: 'form-horizontal' }) do |f| %>
..
..
Put some stuff in your form (this has some bootstrap 3 niceness)
..
<div class="form-group">
<%= f.label "Name", class: "col-sm-2 control-label"%>
@randyleighton
randyleighton / gist:9358b566416ec791e341
Created December 29, 2014 00:59
HAML/Rails submit button for shared new/edit form partial with font awesome and detection for create or update on text and title
This just keeps getting better!
This is a rails submit button for your form partial you use for new and edit. This will detect if it is a new record and use the right wording on your button and on your title. It also supports font awesome icons so you can have a cool checkmark circle on your button.
= button_tag(type: 'submit', class: "btn btn-default btn-float", title: f.object.new_record? ? "Create Drug" : "Update Drug") do
%i.fa.fa-check-circle.fa-fw
= f.object.new_record? ? "Create Drug" : "Update Drug"
@randyleighton
randyleighton / gist:7ae7eb50d509db9fef8c
Created December 27, 2014 07:19
Set title for Rails submit button on shared partial with Ruby ternary.
This one was fun to figure out.
If you like to be DRY and use the same _form partial for your new and edit you run into a small problem if you set the title on the submit button. (title is used for text popping up when hovering over the element)
If you set title to "Create Reminder" then when your reminder new renders the form your title is right. But when you render the form from your edit page, the title is the same.
How to fix it? What to do? How about this:
<%= f.submit(class: "btn btn-default", title: f.object.new_record? ? "Create Reminder" : "Update Reminder") %>
Check to see if it is creating a new object, if so use the "Create Reminder" (true), if not use "Update Reminder" (false)
@randyleighton
randyleighton / gist:bfde5b4aadc9285d24d7
Created December 26, 2014 23:13
Javascript Popup that follows mousemove
In the HTML page:
<div id="alert" class="alert"> <-- This is div used in the popup
<p>Click to see Reminder</p>
</div>
In the script file:
var moveLeft = 0;
var moveDown = 0;
$('a .fa-reminder').hover(function(e) { <-- This is the element on page to show the hover on
@randyleighton
randyleighton / gist:2973f0979b05631418a7
Created December 25, 2014 03:18
HAML collapse menu for Navigation
.collapse.navbar-collapse
%ul.nav.navbar-nav
%li= link_to "About", "#"
%li= link_to "Contact", "#"
%ul.nav.navbar-nav.navbar-right
- if user_signed_in?
%li= link_to "Prescriptions", prescriptions_path
%li= link_to "Drugs", drugs_path
%li.dropdown
@randyleighton
randyleighton / gist:529acd00f2b60b092643
Created December 25, 2014 03:17
HAML button Group for Navigation
.btn-group
%button.btn.btn-primary.dropdown-toggle{type: "button", 'data-toggle'=> "dropdown"}
Action
%span.caret
%ul.dropdown-menu{role: "menu"}
%li= link_to "View", '#'
%li= link_to "Edit", '#'
@randyleighton
randyleighton / Ajax More Button for Tumblr v2 api posts
Created November 23, 2014 07:31
Create AJAX button to load 10 more posts from Tumblr JSON - manage state
Create a more button to load 10 additional entries from the tumblr api
----------------------------------------------------------------------
Manage state by using Ajax and increment the offset value each time you click button. The offset is where it starts the posts number each time. ie. first time its 0-9, next time 10-19, etc. So each time you see 10 more posts.
Blog Model (to create blog object with all needed params with the jsonp data from Tumblr v2 Api)
Method to pull jsonp from tumblr:
def self.fetch(offset_value=0)
blogs = []
client = Tumblr::Client.new