Skip to content

Instantly share code, notes, and snippets.

@mikesjewett
mikesjewett / create.js.erb
Created October 16, 2012 19:38
Ajax example
$("#follow_form").html("<%= escape_javascript(render('users/unfollow')) %>")
$("#followers").html('<%= @user.followers.count %>')
@mikesjewett
mikesjewett / gist:3907373
Created October 17, 2012 18:53
Error Handling for Meatup
def rollback_packages
self.lines.each do |l|
l.packages each do |p|
puts "INside the nested deal"
begin
ActiveRecord::Base.transaction do
p.update_attributes(:sold => false, :line_id => nil)
end
rescue => e
self.errors[:base] << e.message
@mikesjewett
mikesjewett / gist:3933129
Created October 22, 2012 18:18
Summing several numbers
# these all accomplish the same goal.
def sum(numbers=[])
sum = 0
numbers.each { |i| sum += i }
sum
end
def sum(numbers=[])
numbers.inject(0) { |sum,element| sum += element }
@mikesjewett
mikesjewett / general_explanation.rb
Created October 24, 2012 16:08
Each Method Explained
# The each method is an iterator. It invokes a block of code a certain amount of times. The amount of times
# it will invoke the block of code depends on the size of the collection (array or hash) it is called on.
# for example, calling each on an array could be done like this:
[1,2,3].each do |num|
puts num
end
# this returns:
1
@mikesjewett
mikesjewett / activerecord_validations.md
Created December 10, 2012 16:11
Bloc Rails Cheatsheet

Common validation helper methods (called in model)

Presence: ensures that a field is present upon submission

validates :name, :email, presence: true

Acceptance: ensures that a checkbox has been checked

validates :terms_of_service, acceptance: true

Format: validates against regexp and returns message if it doesn't pass

validates :email, format: { with: /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i, message: "Valid email required" }

@mikesjewett
mikesjewett / update_path_for_pg.md
Created December 11, 2012 20:16
Postgresql Troubleshooting - updating PATH variable

For anyone using a Mac (Lion) and running into issues with Postgres as your database (with Postgres.app):

If you are using Postgres.app and getting errors…

  1. Type into terminal: which psql

If the the result is /usr/bin/psql you are using the Mac's built in postgres (not the one you want)

  1. You will need to update your .bash_profile
@mikesjewett
mikesjewett / unix_commands.md
Created December 11, 2012 20:42
Unix Commands Explained

which

which prints out the full path of the command it's passed. For example, try typing which pwd into your command line. You should see /bin/pwd as the result. This simply means that the executable command for pwd is stored in the /bin directory.

Like Mike noted, if you run which psql, and the result is /usr/bin/psql it means that the executable command for your Postgresql database server is in the /usr/bin directory, which means Bash isn't going to run the Postgres.app database server.

Bash

Bash is an old Unix acronym, which stands for 'Bourne-Again Shell' As you can probably guess, it's just a pun on the name of Stephen Bourne, who authored the original Bourne shell, which is the foundation for the command line interface in Unix. (Mac OS is based on Unix).

The .bash_profile is a file that states which commands will be executed when you open your terminal. (aka Bash).

@mikesjewett
mikesjewett / gist:5596011
Created May 16, 2013 23:49
Heroku logs - email error
2013-05-15T20:35:41.399417+00:00 app[web.1]: Rendered devise/shared/_links.erb (0.6ms)
2013-05-15T20:35:41.399417+00:00 app[web.1]: Rendered devise/registrations/new.html.erb within layouts/application (6.3ms)
2013-05-15T20:35:41.399417+00:00 app[web.1]: Completed 200 OK in 12ms (Views: 11.0ms | ActiveRecord: 0.0ms)
2013-05-15T20:35:41.400658+00:00 heroku[router]: at=info method=GET path=/users/sign_up host=bloccit.herokuapp.com fwd="65.206.21.165" dyno=web.1 connect=0ms service=25ms status=200 bytes=3289
2013-05-15T20:35:41.399417+00:00 app[web.1]: Processing by Devise::RegistrationsController#new as HTML
2013-05-15T20:35:41.882902+00:00 heroku[router]: at=info method=GET path=/assets/application-770fe5755077bd5022e97daf1c747e09.js host=bloccit.herokuapp.com fwd="65.206.21.165" dyno=web.1 connect=5ms service=357ms status=304 bytes=0
2013-05-15T20:35:49.243880+00:00 app[web.1]: Started POST "/users" for 65.206.21.165 at 2013-05-15 20:35:47 +0000
2013-05-15T20:35:50.492979+00:00 heroku[router]: at=info met
@mikesjewett
mikesjewett / gemfile
Last active December 17, 2015 17:19
New Relic Logging
source 'https://rubygems.org'
gem 'rails', '3.2.12'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'bootstrap-sass', '~> 2.3.1.0'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
@mikesjewett
mikesjewett / sidekicker.md
Last active December 28, 2015 19:49 — forked from eladmeidar/bloc.md

Purpose

Build an application that allows users to manage Sidekiq services. We'll call this application "Sidekicker", but you can name it anything you want.

Use case

Sidekiq is a background processing service that can be integrated into Rails applications. Basically, Sidekiq can make Rails applications much faster and more efficient. When you're maintaining many applications that use Sidekiq, it's cumbersome to manage each Sidekiq instance separately. Therefore we'll build the Sidekicker app, which will present a central location to manage Sidekiq services for all the apps that you are maintaining.

We'll assume that all of our applications will be built using Amazon's AWS servers, so the Sidekicker app will need a way to communicate with AWS, and run Sidekiq services on Amazon servers.

Requirements

  • As a user I should be able to sign in and out of Sidekicker.