Skip to content

Instantly share code, notes, and snippets.

View spacecowb0y's full-sized avatar

Diego spacecowb0y

View GitHub Profile
#<ActiveMerchant::Billing::PaypalExpressResponse:0x007fd3a2667178 @params = {
"timestamp" = > "2012-02-18T15:00:36Z", "ack" = > "Success", "correlation_id" = > "fd42c44f29d95", "version" = > "62.0", "build" = > "2571254", "token" = > "EC-08B34690L3027751N", "transaction_id" = > "1Y616105WY000492X", "parent_transaction_id" = > nil, "receipt_id" = > nil, "transaction_type" = > "express-checkout", "payment_type" = > "instant", "payment_date" = > "2012-02-18T15:00:34Z", "gross_amount" = > "750.00", "gross_amount_currency_id" = > "USD", "fee_amount" = > "22.05", "fee_amount_currency_id" = > "USD", "tax_amount" = > "0.00", "tax_amount_currency_id" = > "USD", "exchange_rate" = > nil, "payment_status" = > "Completed", "pending_reason" = > "none", "reason_code" = > "none", "protection_eligibility" = > "Eligible", "seller_details" = > nil, "success_page_redirect_requested" = > "false", "Token" = > "EC-08B34690L3027751N", "PaymentInfo" = > {
"TransactionID" = > "1Y616105WY000492X", "ParentTransactionID" = >
alias slt='open -a "Sublime Text 2"'
alias mate='open -a "Textmate"'
PS1="┌──[ \e[0;33m\u\e[0m ] ─ [ \e[0;34m\w\e[0m ]\n└─> $ "
@spacecowb0y
spacecowb0y / user.rb
Created April 4, 2012 20:52
User active scope
class User < ActiveRecord::Base
has_many :projects
scope :active, User.joins(:projects).where('projects.id in (?)', Project.active.collect(&:id)).group('user_id')
end
@spacecowb0y
spacecowb0y / parameters.json
Created October 18, 2012 12:48
This is what the form is submitting
Parameters: {
"utf8" => "✓", "authenticity_token" => "59+EhGAWCZ05Lz/DRso/AiEJI+4s1g/84RRxxsVpF0w=", "order" => {
"due_date(1i)" => "2012", "due_date(2i)" => "10", "due_date(3i)" => "23",
"order_item_lines_attributes" => {
"0" => {
"order_item_option_id" => "1"
},
"1" => {
"order_item_option_id" => "3"
},
[
{ "keys": ["super+v"], "command": "paste_and_indent" },
{ "keys": ["super+shift+v"], "command": "paste" }
]
@spacecowb0y
spacecowb0y / gist:f5b2a4a12d26cb1fad72
Created December 1, 2015 12:59 — forked from ebuildy/gist:5d4ad0998848eaefdad8
Setup sentry logger on a fresh Ubuntu server
sudo apt-get update
sudo apt-get install python-virtualenv
sudo apt-get install python-dev
sudo apt-get install postgresql
sudo apt-get install postgresql-server-dev-9.3
sudo apt-get install redis-server
sudo -u postgres createuser -s sentry
sudo -u postgres psql -c "alter user sentry with password 'sentry';"
@spacecowb0y
spacecowb0y / activity.rb
Created January 3, 2013 22:52
Quick code to get the most active days by hour.
week = Time.now.beginning_of_week - 1.week
days = [week.strftime('%Y-%m-%d')]
1.upto(6) do |i|
days << (week + i.days).strftime('%Y-%m-%d')
end
data = days.map do |day|
by_hour = Array.new(24) { 0 }
Activity.
where('date(created_at) = ?', day).
Mysql2::Error: Unknown column 'orders.projects' in 'where clause': SELECT COUNT(*) FROM `invoices` INNER JOIN `orders` ON `orders`.`id` = `invoices`.`order_id` INNER JOIN `projects` ON `projects`.`id` = `orders`.`project_id` WHERE `orders`.`projects` = '---\n:user_id: 283\n' AND `invoices`.`status` = 1
@spacecowb0y
spacecowb0y / order.rb
Created January 18, 2013 04:02
God bless AR!
class Order < ActiveRecord::Base
## Setup accessible (or protected) attributes for your model
attr_accessible :project_id, :developer_id, :due_date, :status, :notes, :is_delivered, :deliveted_at, :completed_at
## Virtual attributes
attr_accessor :pages
## Associations
belongs_to :project
@spacecowb0y
spacecowb0y / examples.rb
Last active December 11, 2015 17:48
Sexy methods for AR objects.
def unread_comments
readable_comments.delete_if {|c| c.created_at < c.discussion.assignments.find_by_user_id(id).updated_at }
end
def create_new_invoice!
invoice = invoices.build
order_item_options.delete_if{ |o| o.price == 0 }.map{ |o| invoice.invoice_lines.build(:order_item_id => o.order_item.id, :description => o.order_item.name, :unit_price => o.price) }
invoice.save!
end