Skip to content

Instantly share code, notes, and snippets.

View anoldguy's full-sized avatar

Nathan Anderson anoldguy

View GitHub Profile

User

  has_many :role_assignments
  has_many :roles, :through => :role_assignments

Role

  has_many :role_assignments
  has_many :users, :through => :role_assignments
@anoldguy
anoldguy / Example.md
Created December 10, 2012 16:19
Transform to AR or AR + Squeel?

Can this be transformed into AR/Squeel?

  select students.shirt as size, count(students.shirt) as quantity
    from students, memberships, teams
    where students.shirt is not NULL
    and  students.id = memberships.student_id
    and memberships.team_id = teams.id
    and teams.id = #{team.id}
 group by students.shirt
@anoldguy
anoldguy / create_dzi.rb
Created December 12, 2012 02:19
Example code from past projects. The ruby is from 2008-ish. The puppet is current, but sparse, as I'm just learning it.
#!/usr/bin/env ruby
$:.push("lib")
require 'image_science.rb'
require 'deep_zoom.rb'
file_options = { :format => 'png',
:quality => 80 }
slice_options = { :tile_size => 256,
:overlap => 4 }

Setup

which ruby
(should return something like: ruby 1.9.3p194)
which gem
(should return something like: 1.8.23)

Installation

.datepicker {
background-color: $white;
border-color: #999;
border-color: rgba(0, 0, 0, 0.2);
border-style: solid;
border-width: 1px;
@include border-radius(4px);
@include box-shadow(0 2px 4px rgba(0,0,0,.2));
@include background-clip(padding-box);
{
"id": "rubygems",
"application": {
"staging": {
"rails_postgresql_host" : "33.33.33.12",
"rails_postgresql_db": "rubygems_staging",
"rails_postgresql_user": "rubygems",
"rails_postgresql_password": "totally insecure",
"s3_key": "",
"s3_secret": "",
@anoldguy
anoldguy / Fish-proposal.md
Last active December 14, 2015 00:19
My 10 year old writes a proposal for a pet fish.

May I Please Have a Fish?

Oh Dearest Mother and Father,

I would like to be responsible for owning six Neon Tetras.

I am world's most responsible 10 ½ year old boy. I work with Pop. I lift boards, hold boards when he is cutting and install lights. I also run my own business, Fox Trail Trash Service. I go around the block and I take out peoples large trash cans on Thursday and bring them back in after the trash truck comes on Friday. I spend my money wisely. I think about things before I start saving for them. I've thought about saving for fish for a long while and I thing it's a good idea.

All my siblings have owned pets. My older sister, for example, had a hermit crab named Scaredy Cat when she was nine. She begged and begged and begged for a long, long, long time for a rabbit and finally bought – with her own money – a rabbit that she named Star when she was 10. My younger brother and sister got hermit crabs when they were four and five. My younger sister has also had a rabbit named Easter when she was

@anoldguy
anoldguy / dummy.rb
Last active December 14, 2015 17:39
Rails Scope Blocks
class User < ActiveRecord::Base
# New way recommended by rails
has_many :membership_seasons, -> { uniq }, :through => :season_memberships, :source => :season
# The Deprecated Way, which seems much easier to read
has_many :membership_seasons, :through => :season_memberships, :source => :season, :uniq => true
end
@anoldguy
anoldguy / gist:5256748
Created March 27, 2013 18:21
IE Compatibility Mode Fix
<!--[if HTML5]><![endif]-->
<!DOCTYPE html>
<!--[if lt IE 9]><html class="ie"><![endif]-->
<!--[if gte IE 9]><!-->
<html>
<!--<![endif]-->
<head></head>
<body></body>
</html>
@anoldguy
anoldguy / test.rb
Created May 29, 2013 17:42
SQL Injection?
# Is the following safe from SQL injection?
Model.where(Model.arel_table[:name].matches("%#{params[:q]}%"))