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
-- in mysql, create "shop" table with article, dealer, and price | |
CREATE TABLE shop (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, article INT, dealer VARCHAR(100), price DOUBLE); | |
-- populate some records | |
-- article 1 | |
INSERT INTO shop (article, dealer, price) VALUES (1, "jeff", 100.0); | |
INSERT INTO shop (article, dealer, price) VALUES (1, "bill", 101.0); | |
-- article 2 | |
INSERT INTO shop (article, dealer, price) VALUES (2, "jeff", 30); | |
INSERT INTO shop (article, dealer, price) VALUES (2, "bill", 30); |
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
describe User do | |
it { should validate_presence_of :email } | |
describe :full_name do | |
subject { User.new(:email => "[email protected]") } | |
context "when first and last name are present" do | |
before { subject.first_name, subject.last_name = "Jeff", "Iacono" } | |
its(:full_name) { should eq("Jeff Iacono") } | |
end |
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
// For a collection "things" that has multiple documents of the form: | |
// { "_id" : ObjectId("4e5c47d1b0207a1ad3000001"), | |
// "filename" : "uploads/development/user/4dbf2b0ab0207a2e8a000001/avatar/avatar.png", | |
// "other_data" : "foo" | |
// }, etc. | |
// we want to replace "development" in "filename" with "production". | |
// Run via mongo shell: | |
db.things.find().forEach(function(e) { | |
var parts = e.filename.split('development'); | |
e.filename = parts[0] + 'production' + parts[1]; |
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
Public Function tell_if_odd_or_even(num As Integer) As String | |
Dim parity As String | |
If num Mod 2 = 0 Then | |
parity = "even" | |
Else | |
parity = "odd" | |
End If | |
tell_if_odd_or_even = num & " is " & parity & "!" |
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
// via: http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/ | |
jQuery(function($) { | |
// create a convenient toggleLoading function | |
var toggleLoading = function() { $("#loading").toggle() }; | |
$("#tool-form") | |
.bind("ajax:loading", toggleLoading) | |
.bind("ajax:complete", toggleLoading) | |
.bind("ajax:success", function(event, data, status, xhr) { | |
$("#response").html(data); |
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
-- To get started, create the database (load sql below, stop after dump completion) | |
-- | |
-- command to dump db: jfi@mac:~$ mysqldump -u root -p dbclass | |
-- | |
-- Table structure for table `apply` | |
-- | |
DROP TABLE IF EXISTS `apply`; | |
/*!40101 SET @saved_cs_client = @@character_set_client */; |
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
# written after reading: | |
# http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html | |
# moderator class so we can encapsulate everything and if we need to change the | |
# moderation (#moderate) algo, we can easily do that without messing with the rest | |
# of the program | |
class Moderator | |
# moderate algo: | |
# if number is divisible by 3 and 5, return "FizzBuzz" | |
# else if number is divisible by only 3, return "Fizz" |
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 AvatarImage | |
GRAVATAR_IMAGE_BASE_URL = 'http://www.gravatar.com/avatar/' | |
GRAVATAR_IMAGE_DEFAULT_SIZE = '32' | |
DEFAULT_URL = 'http://your-awesome-domain.com/images/your-awesome-default-image.png' | |
attr_accessor :email | |
def self.default_url | |
DEFAULT_URL | |
end |
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
module Avatarable | |
extend ActiveSupport::Concern | |
GRAVATAR_IMAGE_BASE_URL = 'http://www.gravatar.com/avatar/' | |
GRAVATAR_IMAGE_DEFAULT_SIZE = '32' | |
DEFAULT_URL = 'http://your-awesome-domain.com/images/your-awesome-default-image.png' | |
# Avatarable assumes the class (or other module) that includes this module has an email attribute | |
# if the email attribute is named something other than email, use alias_attribute to map it to email | |
# alias_attribute :email, :your_email_attribute |
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
// requires Underscore.js | |
var helpers = { | |
// Takes object and converts key / values to a sentence | |
// | |
// Sample usage: | |
// | |
// obj = {"this" : "is good", "that" : "is bad", "those" : "are great"} | |
// | |
// helpers.to_sentence(obj) | |
// # "this is good, that is bad, and those are great" |