Do a search on google for “youtube api javascript upload” and you’ll get
all kinds of results. There are a huge number of ways people try to get
around the document same origin
policy
to make an HTTP request using JavaScript. Lets go through some of them:
You can create a real HTML form and submit it with
JavaScript,
and you can avoid the page refresh by submitting to an iframe. You can
use
jsonp
to sneak by and load remote JavaScript using a script tag. You can
fruitlessly attempt to muck with
document.domain.
There are all kinds of other crazy hacks people use to circumvent the
same origin policy, but they are all either severely limited, or suffer
in terms of your ability to control the HTTP request parameters and
properly handle the response in failure scenarios.
Another option is to skip the whole idea of submitting your requests
directly from the browser to the remote server. You can install your own
proxy server on the same domain as your client JavaScript application
and make requests to your proxy which then makes the disallowed requests
for you because your proxy server isn’t governed by the same origin
policy. This method gives you full control over the entire process, but
setting up and maintaining a proxy server, paying for bandwidth and
storage, and dealing with the added complexity might be too expensive
and time consuming. It might also be totally unnecessary.
CORS is here to save the day. CORS has existed for a long time, but for
some reason (maybe browser compatibility reasons), it hasn’t yet caught
on in a big way. Many well-known APIs, including Google’s YouTube Data
API v3 already support CORS.
And chances are, the browser you’re currently using supports CORS too.
Continue reading »
Trading securities is a dangerous game. It can be difficult to develop a
strategy and stick to it in the face of an emotional marketplace that
stampedes from one extreme to the other. Sticking to a trading strategy
takes time, discipline and serious balls far beyond the capacity of most
human beings.
One way rise above the impediments is to encode your strategy into an
algorithm and instruct a machine to execute that strategy for you. You
can still freak out and pull the plug at any time, but until you do,
machines can execute your strategy without hesitation or emotion. Just
the exercise of encoding potential trading strategies into machine
instructions is enough to spot problems and potential weaknesses.
Continue reading »
It’s easy to fall into the trap of feeling special. From our own
perspective we seem so original and in many respects we really are
unique. Western society rightly encourages us to celebrate the things
that make us special. Individuality is virtuous.
In reality, we’re much more similar than we are different. The great
ideas we have are at best incremental improvements on existing theory.
At worst, they’re complete plagiarism. Even the problems we face are
just as commonplace. Nothing is new. Nothing is special. If you think
otherwise, you’re only deluding yourself. As the ecclesiast said so long
ago:
That which has been is that which will be,
And that which has been done is that which will be done.
So there is nothing new under the sun.
Is there anything of which one might say,
“See this, it is new?”
Already it has existed for ages
Which were before us.
Ecclesiastes 1:9,10 NASB
There is nothing new under the sun, and yet we act as though there is. I
see this pattern all over the place in the software world. We worry and
fret over our silly problems and bite our nails wondering how to solve
the same problems that have been solved countless times before. We
think, “Here is some problem that is uniquely mine. In fact, this
problem is so unique that I must invent a new kind of solution.”
Continue reading »
I was talking to a friend (lets call him Dave) the other day. He had a
good idea on how he could run his QuickBooks accounting software in the
cloud. By running the software in the cloud, he wouldn’t need to ship
QuickBooks backup files back and forth to his accountants, he could just
launch a cloud instance and let the accountants RDP into the instance
and use the software.
It sounds great, but Dave is cheap and he wanted to run this on an EC2
t1.micro and the machine just couldn’t handle it. So of course he wanted
to upgrade the instance. Being the cloud computing guy that I am, he
called me up and asked me how to do it. At first, I thought it was a
silly question, and I told him that of course it is impossible to
upgrade the memory on a running EC2 instance.
Continue reading »
jqXHR and the Promise Interface
jQuery 1.5 features a brand new mechanism for dealing with asynchronous
event-driven processing. This system, called deferreds, was first
implemented for jQuery’s $.ajax method and so we’ll be looking closely
at that method.
$.ajax({
url: "/some/url",
success: function(r){
alert("Success: " + r);
},
error: function(r){
alert('Error: ' + r);
}
});
Continue reading »