Skip to content

Instantly share code, notes, and snippets.

Terence Ponce terenceponce

Block or report user

Report or block terenceponce

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@terenceponce
terenceponce / omniauth_macros.rb
Created Mar 20, 2012 — forked from kinopyo/omniauth_macros.rb
Integration test with Omniauth. This example is using twitter, and assume you've installed rspec and capybara. Official document is here: https://github.com/intridea/omniauth/wiki/Integration-Testing
View omniauth_macros.rb
# in spec/support/omniauth_macros.rb
module OmniauthMacros
def mock_auth_hash
# The mock_auth configuration allows you to set per-provider (or default)
# authentication hashes to return during integration testing.
OmniAuth.config.mock_auth[:twitter] = {
'provider' => 'twitter',
'uid' => '123545',
'user_info' => {
'name' => 'mockuser',
@terenceponce
terenceponce / Console
Created Apr 3, 2012
Unit testing validatable module of Devise
View Console
Failures:
1) User when email address is already taken
Failure/Error: it { should_not be_valid }
expected valid? to return false, got true
# ./spec/models/user_spec.rb:73:in `block (3 levels) in <top (required)>'
@terenceponce
terenceponce / _article.html.erb
Created Apr 6, 2012
Link appears in the browser, but the test says it's not there
View _article.html.erb
<% if user_signed_in? %>
<% if current_user.id == article.author.id %>
<%= link_to 'Edit article', edit_article_path(article) %>
<% end %>
<% end %>
@terenceponce
terenceponce / _article.html.erb
Created Apr 10, 2012
Having trouble in testing CanCan
View _article.html.erb
<% if can? :update, article %>
<%= link_to 'Edit', edit_article_path(article) %>
<% end %>
<% if can? :destroy, article %>
<%= link_to 'Destroy', article_path(article), :confirm => 'Are you sure?', :method => :delete %>
<% end %>
@terenceponce
terenceponce / database.yml
Created May 17, 2012
Rails 3 MySQL2 sample config
View database.yml
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: projectname_development
pool: 5
host: localhost
username: username
password: password
@terenceponce
terenceponce / index.html
Created Jul 19, 2012
jQuery Sortable issue in IE9
View index.html
<!--
Error: Object doesn't support property or method 'attr'
-->
<div class='popover' id='playlist_menu'>
<ul class='toplay' style='overflow:auto'>
<li class='playlist_item' data-id='27' data-order='1' id='videos_27'></li>
<li class='playlist_item' data-id='1' data-order='2' id='videos_1'></li>
<li class='playlist_item' data-id='52' data-order='3' id='videos_52'></li>
</ul>
@terenceponce
terenceponce / problem.md
Created Aug 13, 2012
Twitter gem error: unauthorized
View problem.md

I can't follow/unfollow users with the Twitter gem because Twitter could not authenticate me.

I've written the Twitter app credentials in config/config.yml and I've loaded it in config/initializers/app_config.rb:

APP_CONFIG = YAML.load_file(Rails.root.join('config', 'config.yml'))

After I do Twitter.follow(username), I get a Twitter::Error::Unauthorized exception

Did I miss anything?

@terenceponce
terenceponce / something.rb
Created Aug 14, 2012
What's the best way to retrieve tweets that are on a given timeframe?
View something.rb
def live_tweets
tweets = Twitter.user_timeline(self.twitter_username, :include_entities => true)
max_id = nil
since_id = nil
last_id = nil
tweets.each do |tweet|
if tweet.created_at.utc <= self.time_end.utc
max_id = tweet.id
break
@terenceponce
terenceponce / database.yml
Created Aug 27, 2012
Rails 3 PostgreSQL sample config
View database.yml
development:
adapter: postgresql
encoding: unicode
database: applicationname_development
host: localhost
pool: 5
username: postgres
password: postgres
test:
@terenceponce
terenceponce / problem.md
Created Sep 5, 2012
Implementing a decent trending algorithm in Rails
View problem.md

I'm trying to implement a trending feature. The trending feature is based on searches that have become viral in a span of 4 hours. It will get the 6 latest popular searches.

Of course, to pull that off, I created a model called Search that has a keyword field. Every search done on the application will be stored as one row in the Search table.

At the moment, this is what I'm doing to retrieve the keywords to be classified as trending:

@popular_search = Search.where('created_at >= ?', 4.hours.ago).group(:keyword).order('count_keyword DESC').limit(6).count(:keyword)
You can’t perform that action at this time.