Skip to content

Instantly share code, notes, and snippets.

View spacecowb0y's full-sized avatar

Diego spacecowb0y

View GitHub Profile
@spacecowb0y
spacecowb0y / application.js
Created October 14, 2011 18:21
JavaScript Template for Winners
// @author: Franco Laiuppa
try {
var home = {
log: function(data) {
// return false; // if you dont want messages to be logged
try {
if (typeof data != 'string') {
console.warn('Debug of variable ===>');
console.debug(data);
# lib/active_admin/comments.rb
# Always redirect to the resource on show
before_filter :only => :show do
flash[:notice] = flash[:notice].dup if flash[:notice]
comment = ActiveAdmin::Comment.find(params[:id])
resource_config = active_admin_config.namespace.resource_for(comment.resource.class)
# I don't know why this is not working... yet.
# redirect_to send(resource_config.route_instance_path, comment.resource)
# Customizing the form
form do |f|
f.inputs "Customer" do
f.input :user, :as => :select, :collection => User.find(:all, :order => "created_at ASC").map{ |u| [u.email, u.id] }
end
f.inputs do
f.input :category, :as => :select, :collection => Project.category_collection
f.input :status, :as => :select, :collection => Project.status_collection
f.input :due_date
end
@spacecowb0y
spacecowb0y / console.log
Created February 10, 2012 17:50
WTF!? Ruby error.
Rendered /Users/diegoperalta/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.6ms)
/Users/diegoperalta/.rvm/gems/ruby-1.9.2-p290/gems/execjs-1.3.0/lib/execjs/external_runtime.rb:181: [BUG] pthread_cond_signal: Resource temporarily unavailable (EAGAIN)
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]
-- control frame ----------
c:0159 p:---- s:0869 b:0869 l:000868 d:000868 CFUNC :popen
c:0158 p:0083 s:0864 b:0864 l:000863 d:000863 METHOD /Users/diegoperalta/.rvm/gems/ruby-1.9.2-p290/gems/execjs-1.3.0/lib/execjs/external_runtime.rb:181
c:0157 p:0044 s:0858 b:0858 l:000857 d:000857 METHOD /Users/diegoperalta/.rvm/gems/ruby-1.9.2-p290/gems/execjs-1.3.0/lib/execjs/external_runtime.rb:146
c:0156 p:0023 s:0853 b:0852 l:000843 d:000851 BLOCK /Users/diegoperalta/.rvm/gems/ruby-1.9.2-p290/gems/execjs-1.3.0/lib/execjs/external_runtime.rb:27
c:0155 p:0063 s:0849 b:0849 l:000848 d:000848 METHOD /Users/diegoperalta
#<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"
},
@spacecowb0y
spacecowb0y / readme.md
Created November 22, 2012 15:21
Setup your development environment Rails and MySQL on OSX using Homebrew and RVM
@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).