View articles_search.rb
module ArticlesSearch
def articles_search(search_criteria, state = nil)
@articles = Article.includes(:categories).where('title LIKE ? OR categories.name LIKE ?', "%#{search_criteria}%", "%#{search_criteria}%")
if state
@articles = @articles.where(state: state)
end
@articles
View articles_controller.rb
class Api::Private::ArticlesController < Api::Private::BaseController
before_filter :find_or_create_article, except: [:index]
def index
@articles = Article.scoped
if params[:state] == Article::PENDING
@articles = Article.pending.order(:published_at)
elsif params[:state] == Article::APPROVED
@articles = Article.approved.order('approved_at DESC')
View article.rb
class Article < ActiveRecord::Base
include Categorizable
APPROVED = 'approved'
PENDING = 'pending'
REJECTED = 'rejected'
attr_accessible :approved_at, :url, :body, :image, :rating, :state, :title
validates :url, :uniqueness => true
View CollectionTest.java
/**
*
*/
/**
* Smart Cloud, Inc. Nov 14, 2013.
* @author Alex Bush
*
*/
public class CollectionTest {
View AndroidWeakRefExample.java
public class ExampleWeak {
private WeakReference<Context> weakContext;
public ExammpleWeak(Context context) {
this.weakContext = context;
}
public Context getContext() {
return weakContext.get();
}
View factories.rb
FactoryGirl.define do
factory :post do
sequence(:post_title) {|n| "Post#{n}"}
post_date { Time.now - 10.days }
post_date_gmt { (Time.now - 10.days).gmtime }
post_modified { Time.now - 10.minutes }
post_modified_gmt { (Time.now - 10.minutes).gmtime }
post_status {"publish"}
factory :artist, :class => 'Artist' do
View UIAlertViewPopupExample.m
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Some Title Here"
message:@"And some description message here"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles: nil] autorelease];
[alert show];
View calculate_folder_size.rb
if ARGV.count != 1 || !File.directory?(ARGV[0])
p 'Please specify a folder.'
exit
end
def calculate_size(file)
#p 'calculating ' + file
if File.directory? file
View ActivityImplementsOnClickListener.java
public class AndroidOnClickDefinitionInXMLActivity extends Activity implements OnClickListener {
private Button buttonWithActivityAsListener;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View Activity's Inner Class implements View.OnClickListener.
package com.smartcloudcompany.onclickinxml;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class AndroidOnClickDefinitionInXMLActivity extends Activity implements OnClickListener {