> , Author at Vinova - Page 451

21 Ruby Tricks You Should Be Using In Your Own Code

In this post I present 21 different Ruby “tricks,” from those that most experienced developers use every day to the more obscure. Whatever your level, a refresh may help you the next time you encounter certain coding scenarios. Note to beginners: If you’re still learning Ruby, check out Beginning Ruby book. 1 – Extract regular expression matches quickly A typical way to extract data from text using a regular expression is to use the match method. There is a shortcut, however, that can take the pain out of the process: email = "Fred Bloggs <fred@bloggs.com>" email.match(/<(.*?)>/)[1] # => "fred@bloggs.com" email[/<(.*?)>/, 1] # => "fred@bloggs.com" email.match(/(x)/)[1] # => NoMethodError [:(] email[/(x)/, 1] # => nil email[/([bcd]).*?([fgh])/, 2] # => "g" Ultimately, using the String#[] approach is cleaner though it might seem more “magic” to you. It’s also possible to use it without including an extra argument if you just want to match the entire regular expression. For example: x = 'this is a test' x[/[aeiou].+?[aeiou]/] # => 'is i' In this example, we match the first example of “a vowel, some other characters, then another vowel.” 2 – Shortcut for Array#join It’s common knowledge that Array#*, when supplied with a number, multiplies the size of the array by using duplicate elements: [1, 2, 3] * 3 == [1, 2, 3, 1, 2, 3, 1, 2, 3] It’s not well known, however, that when given a string as an argument Array#* does a join! %w{this is a test} * ", " # => "this, is, a, test" h = { :name => "Fred", :age => 77 } h.map { |i| i...

Don’t let your programmers design the user interface

I’m a programmer, among other things. Like many in this profession. I suck at designing UIs (though sometimes I believe I don’t). When you let programming-focused people like me build your user interface, you will get things like this: Joseph Cooney calls this The Dialog: A developer needed a screen for something, one or two text boxes and not much more, so they created “the dialog”, maybe just to “try something out” and always with the intention of removing it before the product ships. They discovered they needed a few more parameters, so a couple more controls were added in a fairly haphazard fassion. “The dialog” exposes “the feature”, something cool or quite useful. Admittedly “the feature” is more tailored towards power users, but it’s still pretty cool. The developer thinks of new parameters that would make “the feature” even more powerful and so adds them to the dialog. Maybe a few other developers or power users see “the dialog” and also like “the feature”. But why doesn’t it expose this parameter? New controls are added. Pretty soon the technical team are so used to seeing “the dialog” the way it is that they become blind to its strange appearance. Ship time approaches and the product goes through more thorough testing, and “the dialog” is discovered, but it is too late to be heavily re-worked. Instead it is given a cursory spruce-up. Some people are naturally gifted at user interface design. They feel physically sick about adding a button that clutters the interface or messes up the user’s workflow. Make sure you have a gifted UI designer on your...

How to recognise a good programmer

How do you recognize good programmers if you’re a business guy? It’s not as easy as it sounds. CV experience is only of limited use here, because great programmers don’t always have the “official” experience to demonstrate that they’re great. In fact, a lot of that CV experience can be misleading. Yet there are a number of subtle cues that you can get, even from the CV, to figure out whether someone’s a great programmer. I consider myself to be a pretty good programmer. At the same time, I’ve spent a fair amount of time on the business side of the fence, filtering technical CVs for projects, interviewing people, etc. Thanks to this, I think I have a bit of experience in recognising good programmers, and I want to share it in this article, in the hope that it may help other “business guys” to recognise good programmers. And, who knows, perhaps some programmers who have the potential to be good but haven’t really exploited this can also read this and realise what they need to do to become good (although, as I’ll argue, that’s definitely not accessible to all programmers!). In his article The 18 mistakes that kill startups, Paul Graham makes the following point: “… what killed most of the startups in the e-commerce business back in the 90s, it was bad programmers. A lot of those companies were started by business guys who thought the way startups worked was that you had some clever idea and then hired programmers to implement it. That’s actually much harder than it sounds—almost impossibly hard in fact—because business guys can’t...

Link Building Strategies

You may have mixed feelings when it comes to building backlinks for your website. If you look around the internet you will get many different opinions of what is right and what is wrong when it comes to this. All the different opinions can make you feel really confused and you’ll never get your link building campaign started. The best advice I can offer you is that there is no one size fits all technique when it comes to building backlinks to your site. Everyone will have something different they feel works for them. If you take the time and energy to learn how to use link building techniques correctly then you will have no problem realizing the benefits. Here are a few link building techniques to help you get started: Contacting webmasters for links; This is a method that has been ripped to shreds by many people who claim that it doesn’t’ work anymore or that it is a waste of your time. It is never a waste of your time to have a good link pointing back to your site. Contacting webmasters for reciprocal links can still be an excellent way to build credibility within your niche. What people fail to realize is even if the search engines don’t pay that much attention to this technique anymore that the direct traffic you can get from the other persons site is astronomical. You never know just how much direct traffic someone gets, imagine being on their page to take advantage of some of that traffic. Manual link building: There are plenty of sites that will let you leave...

update_attribute vs. update_attributes

Object.update_attribute(:only_one_field, “Some Value”) Object.update_attributes(:field1 => “value”, :field2 => “value2”, :field3 => “value3”) Both of these will update an object without having to explicitly tell AR to update. Rails API says: for update_attribute Updates a single attribute and saves the record without going through the normal validation procedure. This is especially useful for boolean flags on existing records. The regular update_attribute method in Base is replaced with this when the validations module is mixed in, which it is by default. for update_attributes Updates all the attributes from the passed-in Hash and saves the record. If the object is invalid, the saving will fail and false will be returned. So if you don’t want to have the object validated you should use update_attribute. But wait.. there are some more things to note: update_attribute not only bypass the validation but also bypass the before_* callbacks Let check the source code: # File vendor/rails/activerecord/lib/active_record/base.rb, line 2614 2614:       def update_attribute(name, value) 2615:         send(name.to_s + ‘=’, value) 2616:         save(false) 2617:       end # File vendor/rails/activerecord/lib/active_record/base.rb, line 2621 2621:       def update_attributes(attributes) 2622:         self.attributes = attributes 2623:         save 2624:    end the difference between two is update_attribute use save(false) where as update_attributes uses save or you can say save(true) It’s rather long description but it is important to see that save(perform_validation = true)). If perform_validation is false it bypasses all the before_* callbacks associated with save. It doesn’t actually save the record. You can also save a record without triggering validations by using Model.save...
Malcare WordPress Security

ios app development singapore,website development singapore,app development singapore,design firms in singapore,graphic designer in singapore,singapore mobile application developer,web design singapore,app developer singapore,web development company singapore,developers in singapore,ios developer singapore,mobile developer singapore,website developer singapore,mobile game developer singapore,singapore app developer,website design singapore,singapore web design,mobile apps development singapore,web design company singapore,web application singapore,web development singapore,singapore web development,mobile app developer singapore,android developer singapore,design agency singapore,web design services singapore,developer in singapore,web designer singapore,mobile apps singapore,mobile app development singapore,mobile application developer singapore,website designer singapore,singapore website design,singapore web design services,singapore mobile app developer,ruby on rails developer singapore,mobile application development singapore