This file contains 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 User < ApplicationRecord | |
validates_length_of :first_name, :last_name, minimum: 2 | |
validates :refferal_code, presence: true, uniqueness: true | |
before_validation :set_referral_code | |
private | |
This file contains 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 'minitest/autorun' | |
class ValidPhoneNumberTest < Minitest::Test | |
def test_when_valid_phone_number | |
assert is_valid_phone_number("(123) 456-7890") | |
end | |
def test_extra_extra_number_missing_bracket | |
refute is_valid_phone_number("1111)555 2345") | |
end |
This file contains 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 AnythingController < ApiController | |
def index | |
raise ApiError.new("My custom message", 401) | |
end | |
end |
This file contains 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
puts 'Hello World!' | |
greeting = 'Good morning!' | |
puts greeting | |
forecast = "rainy" # string | |
temperature = 32 # number | |
is_summer = true # boolean | |
# overwrite the existing value with a new one | |
forecast = "sunny" |
This file contains 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
first_name = nil | |
print "Hello, what's your name?" | |
# read what the user types in | |
first_name = gets | |
puts "Welcome, #{first_name}" | |
puts "It's really nice to meet you." | |
This file contains 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
# ruby socket.rb | |
require 'socket' # Sockets are in standard library | |
class Server | |
def initialize(socket_port) | |
@server_socket = TCPServer.new(socket_port) | |
puts 'Started server.........' | |
end |
This file contains 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
namespace :csv do | |
desc "TODO" | |
# to run: rake csv:match | |
task match: :environment do | |
puts "Starting..." | |
csv_text = File.read('./tmp/exported-report.csv') | |
csv = CSV.parse(csv_text, :headers => true, :return_headers => true) |
This file contains 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
PHP_VER="5.5.14" | |
# Check if extension exists first | |
php -m | grep pgsql | |
# Update brew and install requirements | |
brew update | |
brew install autoconf | |
# Download PHP source and extract |
This file contains 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
/* | |
* | |
* / --------------------------------[ NUIM CS141 Java Revision ]------------------------------- \ | |
* || Designed to easily revise everything covered in CS141 by just reading through this code. || | |
* || Comments accompany almost every line of code to explain its purpose. || | |
* || Some theory we need to know are included in the bottom... || | |
* \ ------------------------------------------------------------------------------------------- / | |
* | |
* | |
* ____ _ __ ____ __ |