Author: heridev

Hey there, Here you can find some examples using regular expression if you want to test your own regular expression you could use the following website to do it: http://rubular.com/ Regular expresion if you want for example match a exact word and that word is inside a full sentence sometimes and sometimes the first word or sometimes is the last word in the sentence you could use the following expression to get the correct matches: [ruby] ( |^)404( |$) or (^|\s)404(\s|$) [/ruby]

Hello guys, when you are working at crowdint.com, one of the most appreciated skills in a developer is when you enjoy to refactor your code all the time and in this little example I'm will share with all of you, about how to stop or avoid using if else conditionals in Ruby, so let's start.

Before the refactor
[ruby]
class Calculator
  attr_accessor :number_one, :number_two
  def initialize number_one, number_two
    @number_one = number_one
    @number_two = number_two
  end

 def calculate
   if @number_one == 5 and @number_two == 8
     puts "Are equal to 5 and 8: #{@number_one} and #{@number_two}"
   else
     puts "Are different to 5 and 8: #{@number_one} and #{@number_two}"
   end
 end

end
calculator = Calculator.new 5, 8
calculator.calculate
[/ruby]


My test file content: [ruby] describe ProductsService do describe '#valid?' do context 'when is successfully' do let(:result) { mock 'Result', object: {'errors' => ''}} before do subject.instance_variable_set(:@result, result) end specify do expect(subject.valid?).to be_true end end context 'when there is an error' do let(:result) { mock 'Result', object: {'errors' => 'error example'}} before do subject.instance_variable_set(:@result, result) end specify do expect(subject.valid?).to be_false end end end [/ruby]

In this case I want to show the method wich a created because I need to convert in camel case format "DebitCard" into  snake case (underscore) format "debit_card" and here you can find what I did: Coffeescript [javascript] snakeCase: (clazz)-> unless clazz is '' or clazz is undefined clazz.replace /([A-Z])/g, ($1) -> if clazz.charAt(0) is $1 $1.toLowerCase() else "_" + $1.toLowerCase() [/javascript]

If you want to add forgotten files into the previous commit git amend to the rescue: [shell] git commit --amend –C HEAD [/shell] How to search files name from command shell [shell] find . | grep nameoffileyouwanttofind [/shell] (You can use this for example when you want to migrate to another server and you need to move all your information in the database) Export database