Skip to content

Instantly share code, notes, and snippets.

Avatar

Larry Scott lscott3

View GitHub Profile
@lscott3
lscott3 / main.tf
Created Apr 12, 2018
Terraform example for an aws_vpc resource
View main.tf
provider "aws" {
access_key = ""
secret_key = ""
region = "us-east-1"
}
resource "aws_vpc" "default" {
cidr_block = "10.0.0.0/16"
tags {
@lscott3
lscott3 / wp-user.sql
Created Dec 3, 2013
Create user in wordpress mysql
View wp-user.sql
INSERT INTO `database`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('4', 'test', MD5('test@1'), 'Test User', 'test@gmail.com', 'http://www.google.com/', '2011-06-07 00:00:00', '', '0', 'Test User');
INSERT INTO `database`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `database`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_user_level', '10');
View le_coffee_while_drinking_coffee.js.coffee
calculatePrice = (selector) ->
total = 0.00
$.each $(selector), (index, value) ->
num = parseFloat($(this).html(), 10)
total = Math.round((total + num) * 1e10) / 1e10
total
View user_import.rake
user_id = connection.insert("INSERT INTO users (prefix, first_name,
middle_name, last_name, suffix, nick_name, email, password,
individual_id, account_id, avectra_id) VALUES (#{prefix},
#{first_name}, #{middle_name}, #{last_name}, #{suffix}, #{nick_name},
#{email}, #{password}, #{individual.id}, #{Account.first.id},
#{row['ind_cst_key']}) RETURNING id")
View authority.php
$authority->allow('manage', 'License', function($self, $user){
return $self->company()->id === $user->company()->id;
});
@lscott3
lscott3 / application_controller.rb
Created May 31, 2013
Rails 4 rc1 CanCan work around for strong params
View application_controller.rb
# Rails 4 CanCan work around for strong params
before_filter do
resource = controller_name.singularize.to_sym
method = "#{resource}_params"
params[resource] &&= send(method) if respond_to?(method, true)
end
# Can't remember where I found this. Probably in the cancan github issue list.
View header.html
<!-- this is an example using the bootstrap grid -->
<div class='span12'>
<div class='row'>
<div class='span4'>
<!-- this is where the logo markup would go -->
</div>
<div class='span6'>
<!-- this is where the slogan markup would go -->
</div>
<div class='2'>
View README.markdown

Behold, the nav_link:

The nav_link helper works just like the standard Rails link_to helper, but adds a 'selected' class to your link (or its wrapper) if certain criteria are met. By default, if the link's destination url is the same url as the url of the current page, a default class of 'selected' is added to the link.

<%= nav_link 'My Page', my_path %>

When my_path is the same as the current page url, this outputs:

<a class="selected" href="http://example.com/page">My Page</a>
View alias
alias project='cd ~/path/to/project/; rm log/test.log && rm log/development.log; touch log/test.log && touch log/development.log && git branch'
@lscott3
lscott3 / deploy.rb
Created Jan 18, 2013
Run rake task from capistrano
View deploy.rb
desc 'Run the sqlite dump after deploy'
task :sqlite_dump_dev do
rake = fetch(:rake, 'rake')
rails_env = fetch(:rails_env, 'development')
run "cd '#{current_path}' && #{rake} sqlite_dump RAILS_ENV=#{rails_env}"
end