This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var d = new Date('yourDate'); | |
| d.setMinutes( d.getMinutes() + d.getTimezoneOffset() ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rails_helper' | |
| # The Custom controller is inherited from ResourceController | |
| # and does not have any custom action, which makes it the perfect | |
| # proxy for testing ResourceController | |
| # | |
| describe Admin::CustomersController, type: :controller do | |
| render_views | |
| let!(:customers) { create_list :customer, 3 } | |
| let!(:joe) do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Put this file into your .git/hooks directory and make it | |
| # executable. | |
| # | |
| # A hook script to verify what is about to be committed. | |
| # Called by "git commit" with no arguments. The hook exits | |
| # with non-zero status if the Rubocop check fails. | |
| # Redirect output to stderr. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Ref: https://stackoverflow.com/a/22131019/6220029 | |
| #!/usr/bin/env ruby | |
| File.open("your_file.md", 'r') do |f| | |
| f.each_line do |line| | |
| forbidden_words = ['Table of contents', 'define', 'pragma'] | |
| next if !line.start_with?("#") || forbidden_words.any? { |w| line =~ /#{w}/ } | |
| title = line.gsub("#", "").strip | |
| href = title.gsub(" ", "-").downcase |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| x = arr.inject(Hash.new(0)) { |h, e| h[e] += 1 ; h } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Price.where("'sat' = ANY (check_in_days)").count | |
| # https://coderwall.com/p/sud9ja/rails-4-the-postgresql-array-data-type | |
| Price.where("array_length(check_in_days, 1) > ?", 0) | |
| # https://www.postgresql.org/docs/9.1/static/functions-array.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results | |
| // | |
| // So, to answer the original asker's question directly, | |
| // "YYYY-MM-DD" is the short form of the ISO 8601 format "YYYY-MM-DDTHH:mm:ss:sssZ". | |
| // So, it is interpreted as UTC time while the other is interpreted as local. | |
| // | |
| // The bottom line is this for parsing date strings. | |
| // The ONLY ISO 8601 string that you can safely parse across browsers is the long form. | |
| // And, ALWAYS use the "Z" specifier. | |
| // If you do that you can safely go back and forth between local and UTC time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://stackoverflow.com/questions/1019939/what-is-the-best-method-of-handling-currency-money | |
| # You'll probably want to use a DECIMAL type in your database. In your migration, do something like this: | |
| # precision is the total number of digits | |
| # scale is the number of digits to the right of the decimal point | |
| add_column :items, :price, :decimal, :precision => 8, :scale => 2 | |
| # recommended use scale: 2, as we saw in Spree | |
| # when you have to do division, might worth it to do the rounding, float.round(2) | |
| # In Rails, the :decimal type is returned as BigDecimal, which is great for price calculation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AbilityDecorator | |
| include CanCan::Ability | |
| def initialize(user) | |
| if user.respond_to?(:has_spree_role?) && user.has_spree_role?('agent') | |
| can [:admin, :manage], CreditCard | |
| can [:admin, :manage], Spree::Address | |
| can [:admin, :manage], Spree::Order | |
| can [:admin, :manage], Spree::User | |
| can [:admin, :manage], Spree::Payment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # upload your local files to s3 | |
| brew install awscli | |
| aws configure # to add your aws key and secrets | |
| aws s3 cp your_dir s3://bucket_name/folder/ --recursive --acl public-read | |
| https://bucket_name.s3.amazonaws.com/folder/your_file.ext | |
| # ref: http://docs.aws.amazon.com/cli/latest/reference/s3/cp.html |