Skip to content

Instantly share code, notes, and snippets.

View bobbytables's full-sized avatar
🔥
Putting out fires

Robert Ross bobbytables

🔥
Putting out fires
View GitHub Profile
@bobbytables
bobbytables / search_log.php
Created April 20, 2011 17:12
We needed a way to Map/Reduce our search queries in CakePHP shells. This is our result. Built off of the incredible plugin, https://github.com/ichikaway/cakephp-mongodb
<?php
public function startup(){
App::import('Datasource', 'Mongodb.Mongodb');
$this->mongo = ConnectionManager::getDataSource($this->SearchLog->useDbConfig);
}
public function main(){
$map = 'function () { emit(this.slug, {count:1}); }';
$reduce = 'function (key, values) { var count = 0; values.forEach(function (v) {count += v.count;}); return count; }';
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Folder>
<name>House of Blues</name>
<Placemark>
<name>HOB San Diego</name>
<description />
<Point>
<coordinates>-117.160118,32.716254</coordinates>
<description>1055 5th Ave, San Diego, CA 92101, USA</description>
export GIT_EDITOR="subl -w"
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
c_reset=`tput sgr0`
c_user=`tput setaf 6`
c_path=`tput setaf 7; tput bold`
c_black=`tput setaf 0`
c_git_clean=`tput setaf 2`
c_git_dirty=`tput setaf 1`
else
@bobbytables
bobbytables / README.md
Created September 10, 2012 03:59
Some general steps that I use with turnip to help crank out feature specs

I find that writing features can get really repetitive. So to get rid of writing steps over and over again for multiple models I decided to create a pretty simple solution. It's not big enough to yield a gem so it's here for your use / modification. Comments or questions are welcome, would love to add to this as well.

The steps

step 'I modify the :model :attribute with/to :value' do |model_name, attribute, value|
  id = "#{model_name}_#{attribute}"
  fill_in "#{id}", with: value
@bobbytables
bobbytables / questions.md
Created November 27, 2012 00:24
Repository Pattern questions

Attempting to find a good way to give a wrapper around AR objects to give them Repository pattern effects.

  • Do validations stay on the ActiveRecord model or do they move to the Repository object?

  • Is delegating attributes / errors / finders to the AR object bad?

    For example: UserRepository.new.errors => Calls user.errors ?

  • When calling associations (User => Comments), does the Repository return CommentRepository objects, or Comment objects?

@bobbytables
bobbytables / temporary_table.rb
Created December 1, 2012 01:08
Temporary Table class for creating a join table
class TemporaryTable
attr_reader :name_prefix, :attributes
def initialize(name_prefix, attributes)
@name_prefix = name_prefix
@attributes = attributes
create_temp_table!
end
def table_name
@bobbytables
bobbytables / query.sql
Created December 3, 2012 19:42
Problem query
Here's my query:
SELECT SQL_BUFFER_RESULT SQL_BIG_RESULT users.id, users.email,
COUNT(av.user_id) AS article_views_count,
COUNT(af.id) AS article_favorites_count,
COUNT(lc.user_id) AS link_clicks_count,
COUNT(ai.user_id) AS ad_impressions_count,
COUNT(ac.user_id) AS ad_clicks_count
FROM users
@bobbytables
bobbytables / explain.md
Created December 3, 2012 19:49
Problem query explain
+----+-------------+-------+------+------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------+---------+----------------------------------+---------+---------------------------------+
| id | select_type | table | type | possible_keys                                                                                                                            | key                                           | key_len | ref                              | rows    | Extra                           |
+----+-------------+-------+------+------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------+---------+----------------------------------+---------+---------------------------------+
|  1 | SIMPLE      | users | ALL  | NULL                                            
class BobbyTables
  attr_accessor :tied_shoes

  def tied_shoes?
    !!tied_shoes
  end

  def tie_shoes!
 self.tied_shoes = true
gem "capybara", "~> 2.0.1"
gem "database_cleaner", "~> 0.9.1"

# We're using this version until it gets merged in to support Capybara v2
# https://github.com/jonleighton/poltergeist/pull/208
gem "poltergeist", git: "https://github.com/brutuscat/poltergeist.git"