## Cubic Spline Interpolation in Matlab

This was a homework in my geometric modeling class. Later I modified it to receive input with mouse click and a button to clear and redraw, and also a drop down to choose parametrization method.

Take a look at the spiral I made!!

Bezier representation:
$$p(t)=\sum_{i=0}^{n} c_i B^n_i(t)$$

function [ ] = draw( )
figure
hold on; box on;
grid;
uicontrol('Style', 'pushbutton', 'String', 'Try me again!',...
'Position', [20 20 50 20],...
'Callback', @draw_new);
uicontrol('Style', 'popup',...
'String', 'uniform|centripetal|chordal',...
'Position', [20 340 100 50],...
'Callback', @setmethod);
draw_new ('','');
end

function [] = setmethod (hObj,event)
axis([0 10 0 10]);
global PARAMETER;
PARAMETER=get(hObj,'Value');
draw_spline();
end

function[]=draw_spline()
cla;
global XY;
global PARAMETER;
if PARAMETER ==1
interpolate(XY, 0, 'r');
elseif PARAMETER == 2
interpolate(XY, 0.5, 'g');
elseif PARAMETER == 3
interpolate(XY, 1, 'b');
else
interpolate(XY, 0, 'r');
end
end

function [] = draw_new (hObj,event) %#ok
global XY;
cla;
axis([0 10 0 10]);
% Initially, the list of points is empty.
XY = [];
n = 0;
% Loop, picking up the points.
disp('Left mouse button picks points.')
disp('Right mouse button picks last point.')
but = 1;
while but == 1
[xi,yi,but] = ginput(1);
plot(xi,yi,'ro')
n = n+1;
XY(:,n) = [xi;yi];
if (length(XY(1,:)) > 1)
draw_spline;
end
end
draw_spline();
end

function [] = interpolate(x, mu, color)
n=length(x);
t=parameterize(x,mu);
h(1:n-1) = t(2:n)-t(1:n-1);
mi=get_cubic_slope(x,t);
for i=1:n-1
a=x(1,i);
b=x(1,i+1);

p(1,:)=x(:,i);
p(2,:)=x(:,i)+(h(i)).*mi(:,i)/3;
p(3,:)=x(:,i+1)-(h(i)).*mi(:,i+1)/3;
p(4,:)=x(:,i+1);

[q_bez] = deCasteljau(0,1,p,linspace(0,1,100));

plot(q_bez(:,1),q_bez(:,2),[color,'-'],'LineWidth',3);
plot(p(:,1),p(:,2),[color,'--o'], 'MarkerSize',3);
end

plot(x(1,:),x(2,:),'ro', 'MarkerSize',5,'MarkerFaceColor','r');
xlabel('x'), ylabel('y'),title(['Cubic Spline Interpolation']);
end

function[m] = get_cubic_slope(x,t)
%cublic spline interpolation
n=length(x);
h(2:n) = t(2:n)-t(1:n-1);
A=zeros(n-1,n-1);
b=zeros(2,n-1);
b(:,1)= 3*((h(1)/h(2)*(x(:,2)-x(:,1))));

for i=1:n-1
A(i,i)=2*(h(i)+h(i+1));
end

for i=2:n-1
b(:,i)=3*((h(i+1)/h(i)*(x(:,i)-x(:,i-1)))+(h(i)/h(i+1)*(x(:,i+1)-x(:,i))));
A(i,i-1)=h(i+1);
A(i-1,i)=h(i);
end

m=A\b';
m=m';
m(:,n)=0;
end

function[m] = get_hermite_slope(x,t)
n=length(x);
%piecewise hermite interpolation
m(:,1)=(x(:,2)-x(:,1))./(t(2)-t(1));
m(:,n)=(x(:,n)-x(:,n-1))./(t(n)-t(n-1));
m(1,2:n-1)=(x(1,3:n)-x(1,1:n-2))./(t(3:n)-t(1:n-2));
m(2,2:n-1)=(x(2,3:n)-x(2,1:n-2))./(t(3:n)-t(1:n-2));
end

function [t] = parameterize(x, mu)
t=zeros(1,length(x));
for i=2:length(x)
t(i)=sqrt((x(1,i) - x(1,i-1))^2 + (x(2,i) - x(2,i-1))^2)^mu + t(i-1);
end
end

function [p_t] = deCasteljau(a,b,p,t)
n = size(p,1);
m = length(t);
p_t = zeros(m,2);
X(:,1) = p(:,1);
Y(:,1) = p(:,2);

for j = 1:m
for i = 2:n
X(i:n,i) = (t(j)-a)/(b-a)*X(i-1:n-1,i-1) + (b-t(j)-a)/(b-a)*X(i:n,i-1);
Y(i:n,i) = (t(j)-a)/(b-a)*Y(i-1:n-1,i-1) + (b-t(j)-a)/(b-a)*Y(i:n,i-1);
end

p_t(j,1) = X(n,n);
p_t(j,2) = Y(n,n);
end

end



## WOT

WOT gives warning whenever we are about to enter websites with bad reputations, rated by the community. WOT categorises those bad websites as either: scam, phishing, adult content, illegal, Malwares/viruses.

I totally understand that ads is a way to gain traffic and customers. But I sincerely prefer to not have flashy adult site ads, or promotions that actually requires you to do sacrifice for them before they will give you a piece of cake. So go ahead and install this Adblock add-on.

This is especially useful for someone who is living in a foreign country. You might be thinking that English is an international language and most websites must have the option for English. This is partially true because some websites are not multi-lingual and even if they do, some of the times it sucks. Here it is: for Firefox, and for Chrome.

## XPath Helper

It might be out of topic, but I found this useful for web application development. XPath Helper also gives a console where we can test Xpath command, and it also displays HTML element inspect and another couple of useful things.

## VOIP with Skype from a Local phone

If you are someone living far from family and being lazy to buy telephone cards, perhaps you are like me too, to end up using Skype for calling home. And then if you think 3G connection is not good enough to make phone call, then perhaps you have already known that Skype offered a VOIP feature.

So I've just recently tried the 'Call To Go' feature from Skype. Long story short, this feature makes it available to set up our own private VOIP number specified for our favorite contacts. And then to call that person we just need to dial the private VOIP number from a telephone. The VOIP number will appear as a local toll-free number. Other than that as a bonus, you do not have to get online in Skype in order to make a phone call.

The pro of this method, I don't have to say no more, is that you are going to have a phone call with better and stable quality. And then about the pricing, it has no different with how much if will cost if the call was made through Internet connection via Skype client. Of course to be able to make use of the toll-free, you might need a fixed line telephone. Maybe it is free as well if made from a mobile phone.

So below are the steps to setup the to-go number.

1. Login to Skype, and then under your profile, click Skype To Go.

2. To set up a new Skype To Go number, click on "Add a contact". If you have not set up any registered phone, at this point Skype will have you register one, which could be either a local phone or a mobile phone.

3. And then, fill in contact's name, country, type, and phone number or Skype ID. On the right side you are going to see a local phone number started with (315). In Singapore, this is a phone number format reserved for VOIP purpose.

4. You could also set up a PIN number if you wish to protect your Skype balance, especially when you have auto reload being set up.

5. To make the phone call by using your Skype credit, directly dial the number specified for the contact, and you phone number where you made the call from, will appear as the Caller ID.

*Unfortunately, Skype has not yet support all countries for this feature. Fortunately, Singapore is one of the country that has this feature ready.

## How to Set to Always Open a Similar File with a Preferred Application in Mac OS X

The Wrong Way to Do This

1. Right click on the file
2. Select "Open With", and then select "Other...", choose the application
Doing #1 and #2 will lead to always open rand-anthem.epub with Adobe Digital Editions, instead of setting to always open epub file with Adobe Digital Editions.

The RightWay to Do This
1. Right click on the file, choose "Get Info"
2. A left panel will show up.  Select "Open with:" and then check the specified application.
3. Click on "Change All.."
4. Click "Continue", and now you have a MAC OS which always open epub file with Adobe Digital Editions.
Why a blog post was made to explain this
Because the way to do this in MAC OS is ridiculously against the common sense.

## You Are Just One Click Away to Spend Those Dollars

It's been years since the last time working on some shopping related web applications that I forgot the main angle behind the design of those applications is to make it as easy as possible for the customers to spend their money. The idea behind online shopping business is that it's so easy that as long as we have a credit card (or credit card numbers), we can order whatever we want.

So last time I went to Groupon to purchase a voucher for gift because of the convenience. Prior completing the payment, I was surprised that everything is already filled up. What I have to do to complete the payment is basically just to click the "Submit Order" button. And there is no explanation provided that "after clicking this button, your credit card will be charged". It just happened, my card was charged.

So convenient, right? Imagine if some day Groupon's database get hacked, what will happen? If really one day all those credit cards numbers were downloaded by someone else and he's using them to shop around, I wonder if Groupon is going to stand up and take the full responsibility to handle customers' claim to VISA to fully refund all the money drained by the hacker. If not, then at this time the customers are going to experience big time inconvenience, provided that they're using a credit card. If they're using debit VISA, then I wonder if Groupon is going to refund those money, because debit card has zero fraud protection and does not provide dispute resolution options.

The fact is that this kind of thing happens, and when it does, everything is already too late. For example this is what it will look like when 6 millions of CSDN's users credentials getting hacked and shared publicly on XunLei (a torrent clone of China). This event occurred just last month, and I was one of the members of CSDN. What happened is that since then my mail account (that I used to register on the website) has been always full of spams and I have to update every account that is using the same password (because it's a common knowledge that people tend to use the same password for everything).

Going back to my story about Groupon, I was upset for a few minutes and then daydreaming big time to sue the company. Of course it's not going to happen. They are big, I am just like a fly to them, chances are so small. But I still did some researches and asked around about it.

With the references given by some of StackExchange's member, I figured out that it's indeed illegal to store customer's CVV2 number.

http://www.visa-asia.com/ap/sea/merchants/riskmgmt/ais_merchants.shtml#TIP

The merchant must have confirmed that sensitive authentication data (i.e., the full contents of magnetic stripe, CVV2 and PIN data) is not stored, as defined in the PCI DSS.

So I wrote an email to VISA's AIS team to complain about that. What they replied is that they're unable to confirm if Groupon is storing customers' sensitive credit card information. The asterisk may not represent the actual CVV2 provided that the credit card information is also masked. If I have any concern about card security, I was supposed to contact the bank who was issuing the card (I assumed that they were trying to say that I may request the bank to just deactivate the card if I was really concerned about it).

But Amazon, Apple Store and PayPal also provide the same convenience, right? What makes it different between them and Groupon is that they explicitly explained it to us when we're going to enter the number, that it will be for future purchases as well. Groupon does not do that, I might have remembered it wrong, but I'm quite sure that there wasn't any explanation when I made the first purchase a few months before that.

To support my unreliable memory, additionally here's what we can see on Groupon's FAQ page. It is so beautiful and safe!

What make it worse is that Groupon is allowing you to connect your Groupon account with your Facebook account. People will commonly be being careless about Facebook account because it's just a social media. So what usually happen is that they will check the "remember me" button to keep their browser logged in to Facebook until there's one of the day when the browser's cookies are being cleaned up. Of course this is related to personal responsibility, but what I see here is that Groupon doesn't really care about their customers' security.

Maybe I'm just making this small thing such a big deal. But as a customer I never expect and wouldn't be thankful to have this kind of convenience, especially when it's related to the safety of a debit VISA card.