Skip to content

Instantly share code, notes, and snippets.

station_id stationname date daytype rides
40680 Adams/Wabash 01/04/2016 W 8163
40680 Adams/Wabash 01/05/2016 W 8665
40680 Adams/Wabash 01/06/2016 W 8852
40680 Adams/Wabash 01/07/2016 W 9005
40680 Adams/Wabash 01/08/2016 W 8260
40680 Adams/Wabash 01/11/2016 W 8326
40680 Adams/Wabash 01/12/2016 W 8280
40680 Adams/Wabash 01/13/2016 W 8633
40680 Adams/Wabash 01/14/2016 W 9321
array_of_numbers = [1, 2, 3, 4, 8, 9, 10, 12, 14, 18]
def rewrite_array(array)
answer_string = ""
first_of_range = nil
array.each_with_index do |value, index|
previous_value = array[index-1]
# outputs last of range with dash
@villanuv
villanuv / gist:3ecd1e2f397553f60cdd
Created February 10, 2016 03:31
Company Model Thoughts for New Coast
# app/models/company.rb
class Company < ActiveRecord::Base
has_many :taggings
has_many :tags, through: :taggings
include TagMethods
end
# app/models/user.rb
@villanuv
villanuv / gist:41bafef769e3cd260a69
Created February 10, 2016 03:26
Migration Thoughts for New Coast
# rails generate migration AddUserIdToTaggings user:integer:index
# rails generate migration AddInvestorIdToTaggings investor:integer:index
class AddUserIdToTaggings < ActiveRecord::Migration[5.0]
def change
add_index :taggings, :user
end
end
class AddInvestorIdToTaggings < ActiveRecord::Migration[5.0]
@villanuv
villanuv / gist:a735dc7dee085bdb21f1
Created May 21, 2015 17:48
For QDL Tumblr Post #3 Pt.2
{% if totalPages == 0 or totalPages == 1 %}
{% assign startNum = 1 %}
{% assign endNum = collection.products_count %}
{% elsif current_page < totalPages %}
{% assign endNum = current_page | times:paginate.page_size %}
{% assign startNum = endNum | minus:paginate.page_size | plus: 1 %}
{% elsif current_page == totalPages %}
{% assign endNum = collection.products_count %}
{% assign startNum = current_page | minus: 1 | times:paginate.page_size | plus: 1 %}
{% endif %}
@villanuv
villanuv / gist:0d479c24bb09e134f795
Last active August 29, 2015 14:21
For QDL Tumblr Post #3 Pt.3
{% if totalPages > 1 %}{{ startNum }}-{{ endNum }} of {% endif %}{% if collection.products_count == 0 %}No{% else %}{{ collection.products_count }}{% endif %} {{ collection.products_count | pluralize: 'result', 'results' }}{% if collection.products_count == 0 %} found. <span>[ <a href="javascript:history.back();" style="text-decoration:underline;">Unselect last filter</a> ]</span>{% endif %}
@villanuv
villanuv / gist:55bbecf5fff1f52307cf
Last active August 29, 2015 14:21
For QDL Tumblr Post #3
{% if collection.products_count < paginate.page_size %}
{% assign totalPages = 1 %}
{% elsif collection.products_count | modulo: paginate.page_size > 0 %}
{% assign totalPages = collection.products_count | divided_by: paginate.page_size | plus: 1 %}
{% else %}
{% assign totalPages = collection.products_count | divided_by: paginate.page_size %}
{% endif %}
@villanuv
villanuv / gist:7b1bb66b55c060c26c43
Created May 20, 2015 19:40
For QDL Tumblr Post #3
function getCartCount(count) {
var oldTotal = $('#totalCartCount').text();
var newTotal = parseInt(oldTotal) + parseInt(count);
$('#totalCartCount').text(newTotal);
}
@villanuv
villanuv / gist:2d386fe831e8d80ab0f1
Created May 15, 2015 19:42
For QDL Tumblr Post #2 Pt.4
<ul class="selectedFilters">
{% assign curr_tags_count = current_tags | size %}
{% assign collTitleArr = collection.title | split: ' ' %}
{% assign collTitleStr = '' %}
{% for word in collTitleArr %}
{% assign collTitleWord = word | capitalize %}
{% assign collTitleStr = collTitleStr | append: ' ' | append: collTitleWord %}
{% endfor %}
@villanuv
villanuv / gist:2e0efe3d56ec9f27e759
Created May 15, 2015 19:40
For QDL Tumblr Post #2 Pt.3
// javascript
$('#select-price').insertAfter('#select-brand');
$('#select-light-source').insertAfter('#select-finish');
$('#select-height').insertAfter('#select-width');
$('li.price-100-200').insertAfter('li#select-price ul li:last-child');
$('li.price-200').insertAfter('li#select-price ul li:last-child');
{% for tag in collection.all_tags %}{% if current_tags contains tag %}
{% if tag contains 'brand' %}$('#select-brand').hide();