> Our Blog, Mobile Application Development Singapore - Page 126

Ruby on Rails 3 and escaped HTML

Rails 3 assumes that everything is NOT html safe (a change of opinion from Rails 2). Now, all strings are html escaped by default: <%= h some_string %> is now the same as <%= some_string %> To unescape the HTML (i.e you already know that the string is OK to render out), you need to mark it as html_safe or use keyword raw : <%= some_string.html_safe %> or <%=raw some_string...

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...

Ruby underscore and classify methods

These are two Rails helpers that could be very useful when injecting new instance methods in a class. underscore Converts from a class name to a underscore attribute. ‘MyClassName’.underscore => my_class_name classify Inverse method from underscore. >> “cool_articles”.classify => “CoolArticles” >> “comment”.classify => “Comment” Both, combined with singularize and pluralize, allows us to handle parent/child methods in a very handy way. For example: elements_in_ = self.send(parent).send(self.class.to_s.pluralize.underscore) or things like Kernel.const_get(table_model.to_s.classify).find(:all) #Kernel.const_get gets an string and retrieves the class. source:...

Link Building for SEO

Most people know that incoming links are an important part of improving your websites ranking, but should you focus your link building SEO efforts on obtaining a large quantity of easily obtainable links from wherever you can get them, or focus on obtaining high quality links that are typically harder to get? Most link building experts would agree that both quantity and quality are important, and in most cases (although there are exceptions), any link to your website helps. However, because of the way Google and other search engines value links, focusing your link building SEO efforts on quality is more often than not the better choice. So what makes a link a “quality link” and why is quality more important than quantity? To best understand why quality is more important than quantity we need to see link building SEO from the perspective of Google. Google places a value on every website and every webpage that it indexes. The most famous measure of a website and webpage’s value is Google’s PageRank. Google assigns each webpage a ranking from 0 to 10 as a measure of its authority. Webpages with a ranking of zero are typically very new and insignificant. Webpages with a ranking of ten carry an unprecedented amount of authority. An example of a webpage or website with a rank or zero might be a new blog or a new small website for a pet store. An example of a PageRank of ten would be the Google.com or USA.gov. Google considers links that come from websites with a higher PageRank to be more important than links that come...

Testing for javascript alerts with Cucumber & Capybara

Using Cumcumber + Capybara to run automated testing is a TRENDY now. But you might have trouble finding a way to assert a javascript alert, for e.g. a link created by the link_to … :confirm => “Are you sure?” and similar. Don’t worry, here is a work around to confirm Javascript alert and dialog in your Capybara tests, simply override alert and confirm methods: Given /^I will confirm on next step$/ do begin evaluate_script(“window.alert = function(msg) { return true; }”) evaluate_script(“window.confirm = function(msg) { return true; }”) rescue Capybara::NotSupportedByDriverError end end Rescue here is added in case, you run want to run your tests without javascript (e.g. default capybara driver). If you run feature without javascript simply nothing will happen. Moreover, using this technique you can simulate moving mouse over some elements. It is useful, when you have links that appears when certain div is under the mouse cursor. Then /^I move mouse over “([^”]*)”$/ do |label| begin Capybara.current_session.driver.browser.execute_script(“$(‘#{label}’).mouseover();”) rescue Capybara::NotSupportedByDriverError end end That’s it. Happy testing...

Five Steps to Building an Interdependent Team

1. Know what kind of game you are playing and if you’re all playing the SAME game. Get your team on the same page. If the game you were playing was basketball, it wouldn’t work and you wouldn’t win if 3 of your teammates thought the game was tennis, football, and volleyball. Find out where everyone is at and bring everyone up to speed. 2. Move from activity-based thinking to outcome-based thinking. It’s not “do more” equals “achieve more”. The equation is “do less” equals “achieve more” by taking actions that directly correspond with the outcome you are out to produce. My team and I call this the DPO (Daily Primary Outcome) for each position, team member, and the practice as a whole. 3. Shift from “surviving” to “thriving.” In order for your practice, team, and you to thrive, you have to do what I call, Raise Your HDL™. In life you don’t get what you deserve. You get what you THINK you deserve. Nothing more. Nothing less. Consider that we all have an imaginary container that we have built in our minds that limits the capacity of all the things we can have in practice and in life. Imagine how removing that limit on what’s possible for you, your team, and your practice could impact the BIG game you are all playing. 4. Communicate only with facts and outcomes. I like to call this Managing By Agreement, or MBA. What has worked for my clients and for my own team is to only deal in facts and outcomes. This doesn’t mean that all deadlines will be met. What...

Malcare WordPress Security

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

Mobile App Developer Singapore
Rated 4.95/5 based on 68 reviews