Skip to content

Instantly share code, notes, and snippets.

@mattslay
mattslay / gist:2406616
Created April 17, 2012 15:06
Devise_Admin_Create_User_Account
# When you do not want Users to be able to sign up for your site, rather, you want the admin to create the account and send them the login info.
class User < ActiveRecord::Base
def self.create_new_user(email, password)
user = User.new({ :email => email, :password => password })
return user.save
end
end
# This requires the admin to choose a password, so you could create a an algorithm to create
@mattslay
mattslay / gist:2408397
Created April 17, 2012 19:18
Devise-Sign-In-Sign-Out-Links
<% if user_signed_in? %>
<%= link_to 'Sign out', destroy_user_session_path, :method => :delete %>
<% else %>
<%= link_to 'Sign in', new_user_session_path %>
<% end %>
@mattslay
mattslay / Example.md
Created April 27, 2012 02:20
View helper generates html output for a Twitter Bootstrap styled control group

Twitter Bootstrap control_container method

This view helper generates html output for a Twitter Bootstrap styled control-group
(input fields and check_boxes).

Basic usage in a view html.erb file (pass in the Model and the Attribute name):

<%= control_container(@user, :name) %>

It renders the following:

@mattslay
mattslay / capybara_example.rb
Created June 11, 2012 04:22
My collection of Capybara examples
# This is an example of various ways I use Capybara to test the Submit button on my crud forms.
# I am using these tests to:
# 1. Confirm the form has a submit/commit button
# 2. Confirm that the submit/commit button has a particular css class ('btn-primary' from twitter bootstrap)
# 3. Confirm that the displayed value (or caption, if you will) of the submit/commit says "Save"
# Given this html inside of a form tag:
#
# <input class="btn btn-primary" id="submit" name="commit" type="submit" value="Save" />
@mattslay
mattslay / bootstrap.rb
Created July 30, 2012 13:19 — forked from allard/bootstrap.rb
Form builder for Twitter Bootstrap v2 form elements
# This file goes in config/initializers
require 'bootstrap_form_builder'
# Make this the default Form Builder. You can delete this if you don't want form_for to use
# the bootstrap form builder by default
ActionView::Base.default_form_builder = BootstrapFormBuilder::FormBuilder
# Add in our FormHelper methods, so you can use bootstrap_form_for.
ActionView::Base.send :include, BootstrapFormBuilder::FormHelper
@mattslay
mattslay / gist:03a09ec1911fba88a03b
Last active August 29, 2015 14:00
Helpful Sql Server scripts
-- See lots of settings the DB is currently using
select * from sys.databases
-- Count rows in each table
select t.name TableName, i.rows Records
from sysobjects t, sysindexes i
where t.xtype = 'U' and i.id = t.id and i.indid in (0,1)
order by Records desc;
-- Find Foreign Key References
@mattslay
mattslay / gist:46629f1f645d76800c4d
Created February 3, 2015 06:31
Asp.Net MVC controller pattern for typical CRUD actions
namespace {{lcControllersNameSpace}}
{
[Authorize]
public class {{lcClassPlural}}Controller : {{lcAppBaseController}}
{
[HttpGet, Route("{{lcClassPlural}}")]
public ActionResult List()
{
var model = CreateViewModel<{{lcViewModelClass}}>();
@mattslay
mattslay / Index.md
Last active June 27, 2016 00:54
Basic getting started with html and javascript.md

This a small collection of getting-started-with-html-and-javascript samples that I created for coding beginners. Each link takes you to a code page hosted on jsFiddle where you can see the html/javascript code and how it renders on the screen. You can also play with the code in the jsFiddle editor to begin your own exploration and tinkering with html/javascript.


(Look for comments on each example in the lower javascript panel of the jsFiddle page.)

[00.0 - Basic HTML web page layout] (https://jsfiddle.net/mattslay/eq03yybz/)

  • the most basic sections of an html page: DOCTYPE, html, body

[00.1 - Introducing a few basic HTML elements] (https://jsfiddle.net/mattslay/9t4g5h4p/)

  • h1, h2, p, strong, em, u
import math
class cylinder(object):
feature_type = "cylinder"
def __init__(self, diameter, length):
self.diameter = diameter
self.length = length
self._start_z = 0.00
@mattslay
mattslay / msUtils.prg
Last active October 17, 2016 19:13
Matt Slay general FoxPro utils, aka msUtils
*=======================================================================================
Functions:
AddCR
AddSpace
AddWorkingDays
BuildHtmlPage
cd
CloseCursor
ConvertTimeStringToDecmalHours
ConveretoDate