Does anyone know a practical use for the third `fetch` in ruby.
puts a.fetch(3) { |i| "using the number #{i} for something" }
Does anyone know a practical use for the third `fetch` in ruby.
C Style comments
C style multiline curly braces (this actually works, but didn’t think it would due to following conventions, but in some case could make code easier to read)
Modula 3 style named end blocks (possible activated via a strict mode)
Pascal style “with” blocks
can you think of anything you’d like borrow from another language into your favourite language?
I had a problem, whenever I turned my mac on Steam would tell me that I didn’t have an internet connection but immediately clicking on retry would connect successfully.
So the problem was that Steam doesn’t give the computer time to get a wifi connection or even silently retry after a second or two before notifying the user.
How to fix this?
go to Applications -> Automator
Find run Applescript
and type this script
Save it as StartSteam or any other name you deem suitable (I saved it in my home folder) and also be sure to save the script as an application rather than a .workflow
Now in Preferences -> Accounts -> Login Items add the script and remove Steam from the list.
Now Steam will start a little later than it used to and will allow your mac to gain a wifi connection before it logs in.
You should email the administrator with a message to that effect.
I have noticed that when as user tells the site that they have forgotten their password, that the site will send the password to their email address.
This is not good practice, when your data gets compromised (one day it will) every password will be there in plain text in the database.
This is bad as come users may use that email address and password combination on other sites.
You should look into SHA-2 hashing of passwords and salting.
And rather than send the password in an email you should send a reset key.
I know that the current specification for the site may have come from someone not as security conscious who thinks that sending a password is more user friendly (although it seems it) but it is a security flaw.
Have you ever had to work with an external API such as twitter or facebook, those two should be pretty easy to interface with by now as there are plenty of wrappers such as koala.
But let’s say the API we are working on is a client’s API or the API for an obscure service.
What we want is for JSON requests to relate to ruby objects.
This is where ostruct comes along, ostruct takes a hash and converts that to methods that can be accessed as they were from an activerecord object for example.
What you can do is something similar to this.
In this example i used curb to send an x-auth header to the “secret” api, and then passed the parsed json hash to ostruct.
Now rather than having to handle the json api like this in your views
You can use you json data like so
This way if your boss falls out with the api company and wants you to re-implement the data in your rails app, all your view logic will be compatible with activerecord for example.
In my production code the post, get (other CRUD actions if needs be) and login actions are abstracted into a separate class and is inherited by each model.
I was initially an admirer of Ruby on Rails quite early on (2005), and did a few examples but carried on working on classic asp then asp.net whilst still following Rails. The main reason for not having used Rails earlier on is that the jobs market was full of asp.net and php shops, and I liked Ruby much more than the other languages but had given myself enough time to use it.
But now I have used Ruby On Rails for fully featured applications and I am looking to work under a team which can help me develop further in my Ruby On Rails career, rather than the lone programmer role; who has to justify not only Myself but Ruby On Rails.
Captain Scarlett is said be indestructible altho almost towards the end of episode he performs an act of courage that causes him to die, but that’s ok because he will always regenerate.
What is this regeneration? Regeneration comes from the Mysterons. Mysterons are some myterious creatures of which we never see their appearance, they only manifest themselves by using destructive, copying and regenerative beams which they blast through the earth’s atmosphere.
Here is the key to why Captain Scarlet is permanently regenerating; the earth’s atmosphere. The atmosphere is what prevents the Mysterons from having a permanent hold on Captain Scarlets mind. When they killed the original captain scarlet and replaced him with a copy the Mysterons made an error getting the dosage right on the regenerative beam, either giving him the inherent ability to regenerate after death, which was only meant to be for one use only. Or making a mistake with the control beam, and it not being strong enough to control an indestructible agent after the first death.
The second theory could explain why Captain Black is so insidious and never really puts himself in harms way; were he to die he would become another indestructible asset for humanity.
Following their failure with creating an indestructible agent (or failure to regenerate Captain Scarlet for single use), the Mysterons have always used hit and run attacks. Often similar to acts of terrorism.
This leads me the believe that the powerful beams that the Mysterons use are severely restricted by the earth’s atmosphere, as when the Mysterons were first introduced they could literally blast everything to shreds, but not from the distance of the moon to earth, this is why they only seems to focus on destroying and regenerating one target per episode.
My conclusion is that there are two heros in Captain Scarlet, The Captain and the Earth’s Atmosphere.
Maybe like this:
*following a few posts below, we agree that something like this should be in the controller instead
or
i’ve not specified the value for the ‘:user’ and ‘:house’ hashes as their path should be implied by the route setup and passing them should not be needed.
Maybe creating a backbone app as default, by having api and backbone model generation.
Backward compatibility for decoupled webapps; for example using v8 or therubyracer to create an old school app for when the user’s browser fails a certain prerequisite, i.e. serverside backbone.
I should be able the structure my views like this; “app/views/users/books/chapters/index.html”
Those nested resources would probably have to work like partials.
Routing errors should be more descriptive, show the previous view, current view and controller in the error, the glaring error might just be obvious immediately.
How about adding a queries to routes as a replacement for path helpers.
Instead of something like this
as you noticed the first two parameters are just taken from the last parameter in that instance and should just be “implied”, maybe we should have something like this:
Or maybe like this:
In this example the path could be based on the order of the system in a galaxy and the planet number in a solar system instead.
But instead if using path helpers, we could have a path “finder”
But if the last parameter is :id, then the galaxy id, and system coords would be surplus to requirements and the path finder should be able to figure that out and shorten the url (if that route is defined in routes.rb or defined in a controller) and probably show a warning.
Or what about just adding a `path` method to models for example you can do
so why not have a path method like
or something to that effect.
I am trying to implement shallow routes (being able to list the index of a model through the parent model but without have to access child records through the parent on other actions than index)
the following routes should now be usable,
/books/1/chapters
and
/chapters/6
/chapters/6/edit
/chapters/6/delete
but I get a routing error
No route matches {:controller=>”chapters”}
What am I doing wrong?
I can code it to do /books/1/chapters/6/edit for example but I would rather it use shallow routes.
SEO is something of a dirty word, particularly for many legitimate web developers. It’s no wonder, with so many ‘black hatters’ out there clogging up the internet with their rubbish content.
Thankfully, Google is well aware of black hat and is constantly revising its algorithm in order to prevent this sort of trickery. In this post, Martin Harrison of copywriting agency Copify takes a look at some of the common black hat tricks employed by SEO copywriters and the reasons why they no longer work.
Keyword stuffing
Time was, the only thing you needed to do in order to rank on Google was stuff your targeted keyword in there a dozen or so times and bingo, first page ranking. This resulted in a lot of poorly written, spammy copy like this:
“Do you like spammy SEO copy? Well you’ve come to the right place, because here at spammySEOcopy.com we are spammy SEO copy experts. This is a one stop shop for all of your spammy SEO copy needs.”
Thankfully, this is no longer considered SEO best practice as Google has become much more advanced in the way that it indexes content, looking at aspects such as semantic relevance and domain authority to establish whether or not a page is relevant to a query.
Excessive linking
Exact match anchor links are still a big factor in SEO, but some people take it to the extreme, linking every second word on their site. This technique may have worked once, but nowadays Google is wise to it, and the more links you put on a page the less valuable they become.
Hidden text
White text on a white background used to be a common black hat trick to get a page to rank, without offending anybody with rubbish copy. Now, it’s likely to lead to your page, if not your whole site being taken out of Google’s index.
Write for humans first, spiders second
If you want to create a great website, it’s important to remember the golden rule, write for humans first and foremost. That way, you will have copy that sells your products and services effectively and provides real value for visitors. As a result, you are much more likely to create something that people will naturally want to share and return to, which is far more valuable than any black hat SEO.