Skip to content

Instantly share code, notes, and snippets.

@ridget
ridget / right.md
Created February 7, 2012 10:56 — forked from radar/rules.md

Asking questions, the right way

When asking questions in the #rubyonrails channel, please follow these 10 simple rules:

  1. Do your research before hand. Your question may be answerable with a quick Google search.
  2. If you've tried Googling, explain what terms you've tried to use so people can better help you.
  3. Do not use pastebin.org or bin.cakephp.org (LOL!). Its font is tiny and it has ads on it which cause the page to load slowly. Use Gist (http://gist.github.com) instead!
  4. Remember that using English is preferable, as the majority of people in the channel speak it. Asking in other languages may give you a response, but English is best.
  5. Anything more than 2 lines goes in a Gist (http://gist.github.com) or a Pastie (http://pastie.org). Spamming the channel with walls of text is not welcome.
  6. Clearly explain what is happening and create a Gist (http://gist.github.com) or Pastie (http://pastie.org) of the code that is causing the problem you are encountering, as wel
@ridget
ridget / keyword module
Created April 15, 2012 06:12
testing for keywords
module Keywords
MAX_KEYWORDS = 8
def keywords_to_array(keywords)
@keywords = keywords
end
def assign_values(keywords)
keyword_values = Hash.new
MAX_KEYWORDS.downto(1){ |value, init=8|
keyword_assigned = keywords[init-value]
@ridget
ridget / CDbCommand.php
Created June 20, 2012 01:05
Adding an addPrimaryKey command to yii's db migrations -- supports composite primary keys
/**
* Builds a SQL statement for creating a primary key constraint.
* @param string $name the name of the primary key to be created. The name will be properly quoted by the method.
* @param string $table the table who will be inheriting the primary key. The name will be properly quoted by the method.
* @param string $column the column where the primary key will be effected. The name will be properly quoted by the method.
* @return integer number of rows affected by the execution.
* @since 1.1.6
*/
public function addPrimaryKey($name,$table,$columns)
{
@ridget
ridget / gist:3162048
Created July 23, 2012 05:12
parametizes scope.
public function allInCategory($categoryIds){
$this->getDbCriteria()->mergeWith(array(
'with' => array(
'courseCategories' => array(
'condition' => 'categoryID in (:categoryIds)'
)
),
'params' => array(':categoryIds' => $categoryIds),
));
return $this;
@ridget
ridget / Foo.php
Created November 12, 2012 00:54
File protected/controllers/user/Foo.php not loading why..?
<?php
class ChangePassword extends CAction {
... action code here
}
@ridget
ridget / gangnam.sh
Last active December 13, 2015 16:39
gangnam
echo "Oppan Gangnam Style Gangnam Style Op op op op oppan Gangnam Style Gangnam Style Op op op op oppan Gangnam Style hay Sexy lady Op op op op oppan Gangnam Style hay Sexy lady Op op op op Eh eh eh eh eh eh Oppan Gangnam Style" | say -v Junior
expect{
$SELECTION$
}.to change($MODEL$, :$ATTR$).by($AMOUNT$)
@ridget
ridget / group_by_and_map.rb
Last active August 29, 2015 14:04
group by and map on values in group thanks @mattc
# works in ruby 1.9
count.group_by { |o| o.site.name }.inject({}) { |m, (k,v)| m[k] = v.map(&:user_id); m }
# works in ruby 2.0 and above
count.group_by { |o| o.site.name }.map{ |k,v| [k, v.map(&:user_id)]}.to_h
@ridget
ridget / view_spec.rb
Created January 30, 2015 04:43
view spec sample
# spec/views/products/_product.html.erb_spec.rb
describe 'products/_product.html.erb' do
context 'when the product has a url' do
it 'displays the url' do
assign(:product, build(:product, url: 'http://example.com')
render
expect(rendered).to have_link 'Product', href: 'http://example.com'
@ridget
ridget / 20120625030355_add_deleted_at_to_user.rb
Last active September 16, 2015 05:00 — forked from TimFletcher/20120625030355_add_deleted_at_to_user.rb
Trashable 'concern' for Rails models
# db/migrate/20120625030355_add_deleted_at_to_user.rb
class AddDeletedAtToUser < ActiveRecord::Migration
def change
add_column :users, :deleted_at, :datetime
end
end