tag:blogger.com,1999:blog-11613050465460506872024-03-13T11:38:27.178-07:00Just thoughtsmethodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-1161305046546050687.post-35008930824208144732012-04-17T02:22:00.002-07:002012-04-19T01:44:15.274-07:00Trying something cool<meta name="generator" content="WordPress 3.2.1" />
ash and skin the haddock and remove the flesh from the bones in firm pieces suitable for serving.
Put the head, bones and trimmings to cook in cold water and add a small sliced onion and salt and pepper.
Boil six good-sized onions until tender, then drain and slice and put half of them into a buttered baking dish.
Arrange the pieces of fish on these, sprinkle with salt and pepper, then add the remaining onions.
Drain the fish from the trimmings, add to it two tablespoons lemon juice and pour it over onions and fish.
Cover very closely and cook in the oven until the fish is tender.
Then drain off the liquid, heat it to the boiling point, and thicken it with two eggs slightly beaten and diluted with a little of the hot liquid.
Arrange the onions on a hot platter and place the fish on top, then pour over the thickened liquid.methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com0tag:blogger.com,1999:blog-1161305046546050687.post-30800684028138314262010-12-23T04:17:00.000-08:002010-12-23T04:17:08.174-08:00Gawker Password Stats -- The Sad RealityI stumbled upon a list of passwords that apparently belong(ed) to Gawker Media. For a fairly long time I assumed that people finally understood that passwords are worth something only if they're strong, say, if they contain a wide range of alphanumeric characters. The sad reality is that my assumption was very, very wrong. The list of 250 passwords contain disappointing passwords, such as '123456' or 'password'.<br />
<br />
<script type="text/javascript" src="//ajax.googleapis.com/ajax/static/modules/gviz/1.0/chart.js"> {"chartType":"ColumnChart","chartName":"Chart 1","dataSourceUrl":"//spreadsheets.google.com/tq?key=0AiRzD6SQ2VmHdDRObkZCNjVIemFfYXRqYkxOWkRaNmc&range=A1%3AE10&gid=0&transpose=0&headers=-1&pub=1","options":{"displayAnnotations":true,"showTip":true,"nonGeoMapColors":["#9fc5e8","#DC3912","#FF9900","#109618","#990099","#0099C6","#DD4477","#66AA00","#B82E2E","#316395"],"reverseCategories":false,"dataMode":"markers","maxAlternation":1,"pointSize":"0","colors":["#9fc5e8","#DC3912","#FF9900","#109618","#990099","#0099C6","#DD4477","#66AA00","#B82E2E","#316395"],"smoothLine":false,"lineWidth":"2","labelPosition":"right","is3D":false,"logScale":false,"hasLabelsColumn":true,"wmode":"opaque","title":"","legend":"none","allowCollapse":true,"cht":"bhg","reverseAxis":false,"mapType":"hybrid","isStacked":false,"width":530,"height":400},"packages":"corechart","refreshInterval":5} </script><br />
<br />
If anyone wants to play a bit more with the spreadsheet containing the top 250 passwords, here it is: <a href="https://spreadsheets.google.com/ccc?key=0AiRzD6SQ2VmHdDRObkZCNjVIemFfYXRqYkxOWkRaNmc&hl=en&authkey=CI6RvNcF">https://spreadsheets.google.com/ccc?key=0AiRzD6SQ2VmHdDRObkZCNjVIemFfYXRqYkxOWkRaNmc&hl=en&authkey=CI6RvNcF</a>methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com1tag:blogger.com,1999:blog-1161305046546050687.post-61888152301357601752010-12-05T21:56:00.000-08:002010-12-06T01:42:10.424-08:00Speech recognition on BloggerSSoo. Ever wanted to have your own Google Search in your blog? Yeah yeah. Lame. How about adding ... dunno, like speech recognition to the input field?<br />
<br />
The code is:<br />
<br />
<code><form method="get" action="http://www.google.com/search"><br />
<input name="q" type="text" x-webkit-speech="" speech=""><br />
</form><br />
</code><br />
<br />
And if you want to play with it, here it is. Click on the mike then recite Macbeth:<br />
<br />
<form method="GET" action="http://www.google.com/search"><input name="q" type="text" x-webkit-speech="" speech=""><br />
</form><br />
<br />
It works only on Chrome though. So you can download from <a href="http://www.google.com/chrome/intl/en/landing_chrome.html?hl=en">here</a> if you didn't already.methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com0tag:blogger.com,1999:blog-1161305046546050687.post-10531294337822529902010-11-28T01:57:00.000-08:002010-11-28T03:34:48.994-08:00Deleting the Facebook accountYesterday I managed to delete my Facebook account. This isn't that interesting after all, but seemed to be the right move after all the ... whatever. I thought it will be an easy ride to delete the account but it actually has proven to be a minor headache due to the lack of information about how to actually do it. In my settings page I found a "Deactivate account" feature, but that wasn't what I wanted to do. I wanted Facebook to leave me alone and my personal data, mostly because I love so much zucchini and his arrogant ignorance.<br />
<br />
So, how to do it? You have to click a link which is buried I have no idea where. Even though I'm quite good in search, it took me at least 10 minutes to find it: <a href="http://www.facebook.com/help/contact.php?show_form=delete_account">http://www.facebook.com/help/contact.php?show_form=delete_account</a>. After clicking that link, you will be asked if you want to delete your account. Okay, yes. After you press "Okay", you're asked to provide your password and to test your eyesight with a Captcha challenge.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfwzlpZvZMTIJRIV7pIhO6FlZo5ipaf_esm9VEWniye4QltAk33rlfUftADEhx4yABatufTVk9Vp2kMt16r77ofedXWM9vZaosnqsDutobCQ52ksvTICRdDT3RZHvXWSJwhPnir1TnBjR4/s1600/FB1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="265" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfwzlpZvZMTIJRIV7pIhO6FlZo5ipaf_esm9VEWniye4QltAk33rlfUftADEhx4yABatufTVk9Vp2kMt16r77ofedXWM9vZaosnqsDutobCQ52ksvTICRdDT3RZHvXWSJwhPnir1TnBjR4/s320/FB1.jpg" width="320" /></a></div><br />
By the way. See that Captcha there? It's reCaptcha which is owned by Google and taking the challenge you actually help G digitalizing books while deleting your Facebook account. :)<br />
<br />
I thought I was done, but no: Facebook reminded me that I will still have to wait 14 days in order to have my account deleted from their site (wondering if I can have my username back afterward). If by a mistake I login to Facebook during this period, my account will not be deleted. What does this mean? It means that I had to do the above described process again because I dared to "like" a Techcrunch article. Seems that even though I was logged out after deleting my account, a slippery cookie still remained active and logged me back in to Facebook. Nice try!<br />
<br />
But what's my issue with Facebook? It's a hype. According to their <a href="http://www.facebook.com/press/info.php?statistics">press package</a> they have 500 million active users. Mind if I don't believe that? Maybe if they'd drop the "active" adjective. I am skeptical because I saw what happened when I pressed that "Lick" button on TC. Ooops, typo: "like". Logged out users are magically logged back in if they press a like button and yes, that will appear on their wall, but that doesn't really mean they're active.<br />
Secondly, Facebook is worth nothing for me. I find a site useful when I can learn something thanks to it. I follow blogs that publish comics; thanks to these blogs I improve my sense of humor. I use Twitter, because the people who I <a href="http://twitter.com/#!/toshen">follow</a> <a href="http://twitter.com/#!/maileohye">are</a> <a href="http://twitter.com/#!/JohnMu">really</a> <a href="http://twitter.com/#!/hazelcn">awesome</a> and I become a better human barely by reading their congested thoughts (that sounds a bit 'yech'). I enjoy sites where users publish their images; my sense of beautiful is redefined each time I see a picture that was shot by someone who can appreciate what's <a href="http://commondatastorage.googleapis.com/static.panoramio.com/photos/original/818455.jpg">beautiful</a> or plain <a href="http://commondatastorage.googleapis.com/static.panoramio.com/photos/original/9593481.jpg">stunning</a>, <a href="http://commondatastorage.googleapis.com/static.panoramio.com/photos/original/410280.jpg">impressive</a>. <br />
In Facebook's case there's nothing to learn in my case. I'm flooded with information which has nothing to do with me, ads that are irrelevant for me and suggestions to become "friends" with people I don't find interesting at all. All this if I'm inside Facebook. If I am not... there's <a href="http://www.google.com/#q=site:facebook.com">no valuable content</a>.<br />
<br />
Moreover, I haven't seen any technique on Facebook that would make me "wow" or at least would make me think about how it's done. In Twitter's case I always wonder how did they solve so neatly to push updates into my homepage, Google's Instant feature amazes me because it's so fast and I don't really get how could they make it so fast; even Bing makes me wonder sometimes about certain things they do. Facebook? Nothing at all.<br />
<br />
So to summarize: Facebook is nothing more than a mammoth with high user base, a site that brings no innovation to the internet; they're stuck at where they were 3 or 4 years ago, both content and speed wise. It's an overrated rudimentary website, period.<br />
<br />
Gary's off... with a <a href="http://www.google.com/trends?q=delete+facebook,+sign+up+facebook&ctab=0&geo=all&date=all&sort=1">trend</a>methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com1tag:blogger.com,1999:blog-1161305046546050687.post-70368684912204477582010-11-26T12:59:00.000-08:002010-11-26T12:59:16.302-08:00So, after I hacked Google's Instant previews and now unfortunately for me, I can use it in a ... wherever I want, I had to do something neat. And here came in the picture Assembly :), so the rest of the post will be in assembly.<br />
<br />
<pre style="font-size:11px">call 0x00890105
add [ecx+0x64E53160], cl
rcl [edx-0x75], cl
mov esi, [eax]
or al, 0x52
push edx
mov ecx, [ebx-0x488DD7EC]
mov tr1, [edx-0x1]
xor eax, eax
xor [esp+ebp*4], edi
jl 0x00000089
pop edx
loopnz 0x0000008B
call [edi+0x58]
mov ebx, [edx-0x15]
adc bl, [ebp-0x7A]
xor ebp, [eax+]
xor ch, [eax+]
jnc 0x00000113
lea edx, [eax]
and al, 0x00
push esp
inc esp
push esi
push eax
push esi
push esi
push esi
inc esi
push esi
dec esi
push ebx
push esi
push 0x8679CC56
aas
aad 0xFF
loopnz 0x000000B7
push eax
push eax
push eax
push eax
inc eax
push eax
inc eax
jmp $0xDF68:0xDF68
push esi
dec esi
inc [esi+0x68]
xor [edi-0x2AE29FF8], al
push eax
mov ebx, 0x5668B5A2
xchg eax, ebp
cmps es:[edi], ds:[esi]
popf
mov ebp, 0x3C06FFD5
or bh, [ebx+edi*8-0x80]
jnz 0x0000012E
push esi
dec esi
inc [esi+0x68]
xor [edi-0x2AE29FF8], al
push eax
mov ebx, 0x5668B5A2
xchg eax, ebp
cmps es:[edi], ds:[esi]
popf
mov ebp, 0x3C06FFD5
or bh, [ebx+edi*8-0x80]
jnz 0x0000012E
mov ebx, 0x6F471305
jc 0x00000155
push 0xFF
push ebx
inc ecx
push 0xFF
push ebx
inc ecx
mov ebx, 0x6F471305
jc 0x00000155
push 0xFF
push ebx
inc ecx
pop edi
xor ch, [eax+0x54]
ja 0x000000EE
push edi
aad 0xC7
mov [ebp+0x68], esi
dec ebp
outs dl, ds:[esi]
jmp [ecx+0x68]
pop es
aad 0xFF
nop
mov eax, 0x00290100
push esp
les ebp, [eax+0x50]
sub [ecx], 0x00
imul edx, ebp, 0xFF
push eax
push eax
push eax
push eax
push eax
inc eax
push eax
inc eax
jmp $0xDF68:0xDF68
pop edi
pop eax
mov ebx, [edx-0x15]
adc bl, [ebp-0x7A]
xor ebp, [eax+]
xor ch, [eax+]
jnc 0x00000113
pop edi
xor ch, [eax+0x54]
ja 0x000000EE
pop es
aad 0xFF
nop
mov eax, 0x00290100
push esp
les ebp, [eax+0x50]
sub [ecx], 0x00
imul edx, ebp, 0xFF
push eax
push eax
push eax
push eax
push eax
inc eax
push eax
inc eax
jmp $0xDF68:0xDF68
sub al, 0x02
shl [eax], 0x0D
iret
mov [ecx], 0x5257E2F0
push edx
mov ecx, [ebx-0x2FBDC3F0]
add [eax-0x75], eax
test [eax+0x74], edi
rol [ecx], 0x4A
push eax
ror [eax-0x75], 0x01
mov ebx, [eax]
and [eax-0x2D], bl
add [ebx], edi
mov ecx, [ecx-0x75]
xor al, 0xD6
add edi, edi
xor eax, eax
xor ecx, eax
lods al, ds:[esi]
or eax, 0xE001C7CF
cmp ah, dh
jnz 0x000000E2
call [ebx-0x2B]
push edi
push ebx
jz 0x00000152
outs edx, ds:[esi]
jc 0x00000155
push 0xFF
push ebx
inc ecx
cmp ebp, esp
jmp ecx
add edi, [ebx]
clc
and al, 0x7D
loop 0x000000E1
jmp 0xD55400E5
mov ebx, [eax+0x24]
pop eax
rol [ecx], cl
mov esp, [esi+0x4B]
or al, 0x58
mov eax, [ecx]
sbb al, 0x8B
ror [ebx+0x4401D004], cl
mov [esp], esp
pop ebx
pop ebx
pop ecx
popa
push ecx
pop edx
loopnz 0x0000008B
pop edi
pop eax
mov ebx, [edx-0x15]
adc bl, [ebp-0x7A]
xor ebp, [eax+]
xor ch, [eax+]
jnc 0x00000113
pop edi
xor ch, [eax+0x54]
ja 0x000000EE
pop es
aad 0xFF
nop
mov eax, 0x00290100
push esp
les ebp, [eax+0x50]
sub [ecx], 0x00
imul edx, ebp, 0xFF
push eax
push eax
push eax
push eax
push eax
inc eax
push eax
inc eax
jmp $0xDF68:0xDF68 </pre><br />
Tomorrow I tell you what it does. Or not, will see :)methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com1tag:blogger.com,1999:blog-1161305046546050687.post-38200242792818553232010-11-26T02:06:00.000-08:002010-11-26T02:06:33.086-08:00Google Chrome with Xvfb (Headless Server)Because I'm so damn bored, I tried to set up a box to take screenshots of webpages. This is usually fairly easy to do with khtml2png or with PyQt, but to be honest I haven't heard about a Chrome based screenshot generator. Why Google Chrome? Well, it has libgcflashplayer.so (like... Flash player, anyone?) by default so you don't have to hack your way through pixmaps and get a headache thanks to the flood of segfaults.<br />
<br />
The issue is, that Google Chrome doesn't support natively "headless mode" and is very likely that we hit a nice concrete wall fairly fast after we install it and attempt to capture a screenshot with an external program like ImageMagick. But here comes in the picture the X virtual frame buffer, aka. Xvfb. <br />
<br />
By now, thanks to all these weird names I used, I hope everyone thinks that it's very hard to persuade Google Chrome to run in a headless environment; it's not.<br />
I grabbed an Ubuntu EC2 micro instance from Amazon (~$15 per month?), ran a few package installs and there you go, had the screenshot generator:<br />
<br />
root@localhost: ~# apt-get install xvfb imagemagick<br />
root@localhost: ~# apt-get install google-chrome<br />
<br />
For the latter you may need to "force" things, but aptitude will tell you what to do, so I won't.<br />
<br />
And kinda that was all you needed, because apt-get will find the dependencies and will install them for you. Now to get a screenshot of a webpage:<br />
<br />
root@localhost: ~# xvfb-run --server-args='-screen 0, 1024x768x24' \<br />
google-chrome -start-maximized http://www.example.com \<br />
> & /dev/null &<br />
root@localhost: ~# DISPLAY=:99 import -window root myimage.png<br />
<br />
And that's it. There are still some problems, but in general it works neatly. There were two errors I encountered, first being Chrome's inability to create the 'Local State' file in ~/.config/google-chrome/. To fix this I ran [ touch 'Local State' ]. It fixed the issue; if it doesn't for you, find this file on your local system and paste the contents of it into the server's 'Local State' file.<br />
The second issue happened sporadically when I tried to capture a webpage which contained Flash. A segmentation fault occurred which crashed to death the frame buffer. I didn't fix this issue (yet) because, one, it happens rarely, two, even if it happens, running again xvfb-run sets the frame buffer up correctly and I can use import to capture the contents of the root window in the specified display.<br />
<br />
And finally, flash content is client side, that is it has to be downloaded before we get something. I say this because if I didn't let Chrome to run the flash for a few seconds, I got an empty container on the screenshot in place of Flash content. To 'fix' this, I let Chrome to run for about 5 seconds, and only then captured the image.<br />
<br />
<br />
Hope this helps someone :)methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com1tag:blogger.com,1999:blog-1161305046546050687.post-57004652316648602022010-11-02T08:13:00.000-07:002010-11-02T08:13:38.243-07:00Android Timer and UI threadsIn the past few days I was trying to create a daemonized timer without too much luck, then after sweating blood I managed to come up with the following code:<br />
<br />
<blockquote>public class SampleTimer extends Activity {<br />
<br />
/** Called when the activity is first created. */<br />
@Override<br />
public void onCreate(Bundle icicle) {<br />
super.onCreate(icicle);<br />
setContentView(R.layout.yourlayout);<br />
<br />
// we create a new timer<br />
// arg0 -- String - The timer's name<br />
// arg1 -- Boolean- Whether the timer should be daemonized<br />
Timer timer = new Timer("MyTimerName", true);<br />
<br />
timer.schedule(new TimerTask() {<br />
@Override<br />
public void run() {<br />
// method to repeat<br />
SampleMethod();<br />
}<br />
// initial delay is 0 seconds<br />
// and SampleMethod() will run every<br />
// 1.8 million milliseconds (30mins)<br />
}, 0, 1800000);<br />
}<br />
<br />
private void SampleMethod(){<br />
// we run a new worker thread on the UI thread<br />
this.runOnUiThread(worker);<br />
}<br />
<br />
private Runnable worker = new Runnable() {<br />
public void run() {<br />
// do some checks then send notification (upcoming post)<br />
}<br />
};<br />
}</blockquote><br />
This piece of code, without the class container, is actually used in another background thread (in a class which extends Activity and implement Runnable). I bet if a long-time Java programmer would see my code, would cut my throat, but hey, it works :)methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com0tag:blogger.com,1999:blog-1161305046546050687.post-33052951197734495292010-10-25T11:45:00.000-07:002010-10-25T11:46:02.015-07:00Revolving Coins (brain twister)I found another interesting question which has an incredibly high failure ratio. Most of the people will instinctively select the wrong answer: 47% of them. The question follows:<br />
<br />
You have two coins which are exactly the same in size. Without using any type of coin (don't cheat, please), determine how many revolutions one of the coins will do if it's rolled around the other coin.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-FDMWt6qB2ribnOXoazW2ZqtJyV-ZZYT0PL-bTribsDWOql0kQRQK9h1tnM2g8IVxDcUiRumVz9RJbHu7lY9HTz1Ehp5kFokIVz4TIceO6YT_WXREL8_h8LMJ93FYHUT2m3iRrUHfZVCo/s1600/RevolvingCoins.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-FDMWt6qB2ribnOXoazW2ZqtJyV-ZZYT0PL-bTribsDWOql0kQRQK9h1tnM2g8IVxDcUiRumVz9RJbHu7lY9HTz1Ehp5kFokIVz4TIceO6YT_WXREL8_h8LMJ93FYHUT2m3iRrUHfZVCo/s1600/RevolvingCoins.png" /></a></div><br />
<br />
a) 1<br />
b) 1 <sup>3/4</sup><br />
c) 2<br />
d) 2 <sup>1/2</sup><br />
<br />
Again, please don't use any coins while thinking. :)methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com0tag:blogger.com,1999:blog-1161305046546050687.post-91712844677329552082010-06-07T12:17:00.000-07:002010-06-07T12:24:00.971-07:00I started to avoid visiting YouTubeSeriously, either the engs working at YouTube are so high of themselves they simply don't care, or they forgot that the world is not only the United States! Frankly, folks, I'm familiar with the US copyright laws and I fully understand that for example VEVO has to block some of its content from being viewed outside of the country of freedom, but then, when am watching a playlist from outside of the United States and the next song's uploader decided that the resource may not be viewed in the country I live in, just don't show me that song.<br />
<br />
Don't exit that playlist, don't show me warning messages cos I freaking don't care... I only want to see the next available video and that's all. If a video is not available, no probs lads, just skip it. Seriously, this is going like this since I know YouTube; what can be so damn hard to provide a solution to this, WHAT? Probably nothing, it's just they don't care about people outside the US or they got F+ in geography and they don't know that a world exists outside the US. For the latter there's a solution though: go to <a href="http://maps.google.com/">http://maps.google.com</a>; see that brown thing below the US and next to each blue splash? Those are other continents each having many, many other countries where people live and are trying to use YouTube (i.e. users)...<br />
<br />
Heck, just block all the freaking content available on YouTube from being viewed outside the US like Pandora. Then at least I know that I have to avoid visiting YouTube...methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com0tag:blogger.com,1999:blog-1161305046546050687.post-53309692291384194352010-06-06T09:26:00.000-07:002010-06-06T09:26:13.690-07:00When you loose your motivation...Yes, I did loose it, but it arose a question: when you work for a great company, when you're surrounded with awesome, smart and intelligent people, what makes you loose the motivation you had? What makes you feel that what you do has no benefit or has no good reason? What makes you just throw in the towel and say "I can't do it anymore"?<br />
<br />
<br />
<b>Getting interrupted</b> - just imagine that you work nicely on something and the product manager pops up at your desk and says stop, do something else, then after you started the other thing, you're stopped again and assigned to another task. Best way to annoy someone and of course results in nothing being finished.<br />
<br />
<b>Idiotic internal software</b> - you're used to a software. I'm used to Perforce for example, but have to use SVN, which compared to Perforce is literally shit. Or, I love to add references to the support requests I answer, but I can't because someone didn't configure properly the Google Custom Search engine and the reference box is useless.<br />
Let's say that the Perforce/SVN thing I understand because Perforce is freaking expensive, but I will certainly never understand the Custom Search thing because 1. it's free and easy to configure, in fact a child can also configure it, 2. because it's been configured by someone who very likely has BS in Computer Science, yet it isn't working. It annoys the hell out of me.<br />
<br />
<b>Communication</b> - the lack of it. Let's say you're part of a community in which you are recognized as top contributor. But even if you have this nice label, the common users get insight into product updates, experiments and special programs way before you. I'm actually sick of this; renders that nice title useless and gives the awkward thought of just throwing it away.<br />
<br />
<b></b><br />
<b>Appreciation</b> - probably one of the biggest reasons someone will loose their motivation is if the work they finished isn't appreciated. A few simple word like "Thank you" or "Awesome" makes them happy and will motivate them, even if only a slightly.<br />
<br />
<b>Burn out</b> - Oh yeah. You know this well. <br />
<br />
You may observe that I didn't put on the list the money factor. In my opinion if money is a motivation factor, then you haven't chose well your job.methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com0tag:blogger.com,1999:blog-1161305046546050687.post-13156163541740496672010-05-21T01:09:00.000-07:002010-05-21T01:09:21.722-07:00Validating an URL in JavaShort and to the point. You can do it in two ways: hard and simple. Hard is when you come up with a 600 byte long regex pattern and your pattern fails when your user inputs something you haven't thought of, or you can go the simple way and test if the URL is reachable from java.net's point of view. If it's not, you can't use it anyway.<br />
<br />
Java.net throws an exception if the URL isn't valid, but you don't have to use the thrown message, who said you have to?<br />
<blockquote>//...<br />
import java.net.MalformedURLException;<br />
import java.net.URL;<br />
//...<br />
<br />
private boolean isValidURL(String a) {<br />
try {<br />
URL url = new URL(a);<br />
return true;<br />
} catch (MalformedURLException e) {<br />
return false;<br />
}<br />
}</blockquote><br />
The usage is... very simple:<br />
<br />
if(isValidURL(userInput)){<br />
//Do something<br />
}else{<br />
// URL is invalid <br />
}<br />
<br />
I Googled quite a lot for a better way which is simpleminded like me but no luck. So that method is actually as simple as my mind...methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com0tag:blogger.com,1999:blog-1161305046546050687.post-41520897148768912322010-05-21T00:40:00.000-07:002010-05-21T01:59:58.288-07:00Regex matching code comments - JavaOkay. So I hate Regex for some reason, yet have to use it cos... cos I have to. I spent my whole day trying to figure out a Regex pattern which would match any code comment. I want to strip them off (i.e. replaceAll(pattern, "")) from CSS files cos they're useless, they take up unnecessary space and bandwidth. <br />
<br />
In English. I want this:<br />
<br />
<code></code><br />
<blockquote>/*This is my comment<br />
spanning across multiple lines*/<br />
body {background-color: #000}</blockquote><br />
to become this:<br />
<br />
<code></code><br />
<blockquote>body {background-color: #000}</blockquote><br />
Easy, isn't it? It's not that easy as it turned out. I came up with this pattern first; I think this was the child of my own brain, but after all the hours spent trying to find a working pattern, I really don't remember:<br />
<br />
<blockquote><code>(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)</code></blockquote><br />
Humm. Looks OK, isn't it? It's not OK. Here's this multiline comment:<br />
<br />
<code></code><br />
<blockquote>/* This is my comment<br />
* spanning across multiple lines<br />
* and having asterisks at every new line <br />
* cos that's cool<br />
*/</blockquote><br />
If I use <code>(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)</code> like presented below on the above comment block, I will get an awesome stack overflow error (read, I get a nice HTTP500 on Ant):<br />
<br />
<code></code><br />
<blockquote>public static String compress(String s){ <br />
s = s.replaceAll("(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)", "");<br />
return s;<br />
}</blockquote><br />
Guess I get an infinite loop.<br />
<br />
So I need a better pattern else I'll get SO errors every once in a while. I'm not sure where but I got this pattern:<br />
<br />
<blockquote><code>//.*|(\"(?:\\\\[^\"]|\\\\\"|.)*?\")|(?s)/\\*.*?\\*/</code></blockquote><br />
This one works surprisingly well for now. Guess this also has some limitations I'm not aware of right now but at least I don't get SO errors.<br />
<br />
<b>Update</b>:<br />
Okay, so it strips relative URLs as well. Awesome :/methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com0tag:blogger.com,1999:blog-1161305046546050687.post-9619049507339294132010-05-19T06:53:00.000-07:002010-05-19T06:59:11.840-07:00Google Appengine- free service, not good for anythingAt least for me. I didn't have too much mood to try it out but since everyone was so "wow" about it, why not.<br />
But what should I do, what should be the first project?! Let's create a chat!<br />
<br />
<b>GAE Chat</b><br />
What can be so hard in creating a chat on Appengine using Python? Ajaxy GUI, Google Single Sign-on, free, fast database... it should rock on, shouldn't it? I tell you what, it won't.<br />
If you're not clever enough, even with two users chatting you hit a limit. Not Datastore calls, not number of requests... but CPU Time! You have the fastest servers you can imagine and what happens when you run an AJAX chat? You hit the wall cos you have such a generous quota set.<br />
<br />
<b>GAE Audio/Voice Chat</b><br />
This is neither hard considering that Java has a massive, powerful Sound API. In fact, you can create such a service with not more than 50 lines of Java call and two classes.<br />
Hoho... hold it back; it's not so easy if you want to use GAE! You didn't observe that GAE has no support for the Sound API, did ya? Creating an Audio Chat on Appengine = Failure.<br />
<br />
<b>GAE Crawler</b><br />
How about automated crawling of a forum? I want stats, I have to extract data from URLocations. In PHP 100 lines of code the most, with database CREATE calls altogether so with the powerful Python or Java it should be a piece of cake. Especially since you have such a simple GQL syntax.<br />
Nah, you won't automate your crawler... you hit a frigging limit again! It turns out that Google allmighty ain't likes too many content on forums... there are too many URIs to be crawled. So what, just damn crawl it.<br />
<br />
<b>GAE URLFetch</b><br />
<br />
<code></code><br />
import java.io.BufferedReader;<br />
import java.io.IOException;<br />
import java.io.InputStreamReader;<br />
import java.net.HttpURLConnection;<br />
import java.net.MalformedURLException;<br />
import java.net.URL;<br />
import java.net.URLEncoder;<br />
import java.util.Iterator;<br />
import java.util.List;<br />
import java.util.Map;<br />
import javax.servlet.http.*;<br />
<br />
@SuppressWarnings("serial")<br />
public class html_fetcherServlet extends HttpServlet {<br />
private String line;<br />
<br />
public void doGet(HttpServletRequest req, HttpServletResponse resp)<br />
throws IOException {<br />
resp.setContentType("text/html");<br />
try {<br />
if(req.getParameter("uri") != null){<br />
URL url = new URL(req.getParameter("uri"));<br />
HttpURLConnection connection = (HttpURLConnection) url.openConnection();<br />
connection.setDoOutput(true);<br />
connection.setRequestMethod("GET");<br />
connection.setRequestProperty("User-Agent", "My UA");<br />
<br />
String urlenc = URLEncoder.encode(req.getParameter("uri"), "UTF-8");<br />
connection.setRequestProperty("Referer", "http://www.google.com/url?sa=t&source=web&ct=res&cd=7&url=" + urlenc + "&ei=0SjdSa-1N5O8M_qW8dQN&rct=j&q=flowers&usg=AFQjCNHJXSUh7Vw7oubPaO3tZOzz-F-u_w&sig2=X8uCFh6IoPtnwmvGMULQfw");<br />
<br />
connection.setInstanceFollowRedirects(false);<br />
<br />
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));<br />
Map responseMap = connection.getHeaderFields();<br />
int i = 1;<br />
<br />
for (Iterator iterator = responseMap.keySet().iterator(); iterator.hasNext();) {<br />
String key = (String) iterator.next();<br />
resp.getWriter().println(key + " = ");<br />
<br />
List values = (List) responseMap.get(key);<br />
for (int i1 = 0; i1 < values.size(); i1++) {<br />
Object o = values.get(i1);<br />
resp.getWriter().println(o + "");<br />
}<br />
}<br />
resp.getWriter().println("<br />
<pre id="rb">");
while ((line = reader.readLine()) != null) {
resp.getWriter().println(i + " " + escapeHtmlFull(line));
i++;
}
resp.getWriter().println("</pre>");<br />
reader.close();<br />
}<br />
} catch (MalformedURLException e) {<br />
resp.getWriter().println(e.getMessage());<br />
} catch (IOException e) {<br />
resp.getWriter().println(e.getMessage());<br />
}<br />
}<br />
<br />
<br />
public static StringBuilder escapeHtmlFull(String s){<br />
} <br />
<br />
<br />
Simple, isn't it? Set some headers, referer and user-agent then get the remote page... hard? No.<br />
Google says... Hold on Sparky! You won't do that, will ya?! No I won't cos the allmighty doesn't let me to do it. Better said, it does, but it frigging appends its own User-Agent to mine just to show off how cool we are! I tell you what: I need my own user agent cos it's my frigging app, not yours! The app has to have correct user agent set by me, else it has no meaning creating it. And when do I learn about that you'll append your crap to my crap? On the production server; locally works fine. <br />
<br />
Did I finish whining? Nope.<br />
<br />
<b>GAE Sitemap checker</b><br />
How about uploading some XSDs as static files with my app and let the webmasters test their sitemaps against those XSDs? It's a cool app and is for the humanity.<br />
Not so fast (again)! You can't open your own files for READING through Java on Appengine (probably with Python neither). Your own files...<br />
<br />
<br />
So, why I'm not paying for this service and have some limits lifted?<br />
After all these experiences? Hell no. I was told it's <b>free</b>. If I will pay for a cloud computing service, that will be EC2. Just because they didn't let me fall in false assumptions like I get top-notch service for free...methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com0tag:blogger.com,1999:blog-1161305046546050687.post-13938818739779784192010-05-17T09:27:00.000-07:002010-05-17T09:28:40.800-07:00A great interview... FAILSo, was lurking at my "awesome" Twitter feed and saw a tweet by JohnMu (<a href="http://twitter.com/JohnMu/status/14165538484">http://twitter.com/JohnMu/status/14165538484</a>). He points to an interview created by Lee Odden on TopRankBlog.com. The subject is Maile Ohye, one of my favorite Googlers to date (she's points out great things and she's even funny); the problem is not with Maile, she did a great job answering the questions, the problem is with the questions.<br />
<br />
When you do an interview, please, for the humanity's sake, don't do it with template questions. The interviewer had a bunch of unrelated questions created in the office, written on a paper and he asked these template questions. This is bad. It's unnatural.<br />
<br />
A good interview should be a dialog between the interviewer and the subject of the interview. A chat. You may have some questions written on the paper, but you should just flow with the subject and use your pre-made questions if the chat hits a wall.<br />
<br />
For example, Lee asks:<br />
<br />
<blockquote>Google Webmaster Central has been a great resource for many webmasters. What tips can you share with web site owners to make the most out of Google Webmaster Tools?</blockquote>Maile answers:<br />
<blockquote>Awww, Webmaster Central a “great resource” for many webmasters? That’s wonderful to hear. As for tips, I’d say verify ownership of your site in Webmaster Tools, sign up for email forwarding in Webmaster Tools’ Message Center, and then check out all the specific data for your site: our Top Search Queries feature was just revamped. Crawl Errors is cool for making sure your site is accessed as you’d expect (many people find unknown 404s, or realize they have server downtime because of noticing the “Unreachable” errors), HTML Suggestions shows you the URLs with duplicate titles or meta descriptions. I think once you start poking around in Webmaster Tools you’ll <a href="http://googlewebmastercentral.blogspot.com/2010/01/google-seo-resources-for-beginners.html" onclick="javascript:pageTracker._trackPageview('/outgoing/googlewebmastercentral.blogspot.com/2010/01/google-seo-resources-for-beginners.html');">learn more and more</a>. It’s addictive. </blockquote><br />
then Lee asks a totally unrelated question from Maile:<br />
<blockquote>How does one become a Bionic Poster?</blockquote>Come on, would you ask that considering Maile's answer to the previous question if you'd chat with her next to a coffee in Starbucks? You certainly wouldn't. You would ask something like "What if the webmaster hits the wall, if he needs help?", and she'd reply that there's a very helpful forum where they can ask for help and the bionics would likely help the webmaster. Then you can ask about how does one become a bionic.<br />
<br />
Just saying...methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com0tag:blogger.com,1999:blog-1161305046546050687.post-54895044851752720342010-05-17T09:02:00.000-07:002010-05-17T09:02:34.004-07:00I hate HBOIt's not because it can't deliver top notch movies, it certainly can. It looks good, it offers HD (well, sort of) full stereo and sometimes surround which drives mad my neighbors... but still, it's a messed up channel.<br />
<br />
It happens that I love Lord of the Rings (LotR), I really do. It's an awesome movie from many points of view, but every episode is frigging long; you're expected to sit and watch the full movie in one shot, but I tell you, it's a pain! A movie is good when it can deliver some action in every seven minutes. That's required for people to not fall asleep. BUT! There are movies (LotR) which takes this to extreme and shows some really neat stuff between these seven minutes, or the "Wake the hell up" action takes exactly 6'59" and then continues with another "Wake the hell up" action. This is bad! No, it's Evil! <br />
<br />
<ol><li>you have to go to the bathroom. Shit happens sometimes, and this time it happens to happen exactly in the middle of a "Wake the hell up" action. How do you go to the bathroom? Will you go and miss the action or you try to abstain yourself from the pleasure causing pain for yourself?</li>
<li>you're hungry; that's quite common nowadays in the middle (or end, heck knows) of the financial crisis. Will you go to eat something after you take in consideration that the fridge is downstairs and you have no idea if you will find anything in it, or you continue to watch the movie and starve, causing you pain? </li>
<li>let's say you're a smoker and your girlfriend(s) won't allow you to smoke in the room? What do you do? Miss the action or go out on the balcony and have pleasure, knowing that you will die sooner?</li>
<li>you forgot to turn down your PC speakers and a weird sound notifies you that you got a new email. Of course, the PC is downstairs and you expect an email from the CEO of MSFT as both of you love puppies and you've engaged yourself in a cool conversation with him about these little, weird animals (due to lack of other, meaningful subject)</li>
</ol>Now, every time I watch something on HBO, these things happen to me... always! How about HBO implements something like a "Pause" function or something? It won't happen anytime soon, will it? I hate HBO...methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com0tag:blogger.com,1999:blog-1161305046546050687.post-74392947658465670032010-05-02T03:03:00.000-07:002010-05-02T03:04:10.138-07:00Shalom, fh6whUq3NnsPfj8g3vr0gQO4Yyzf.comSo I got a wiki, not a big deal but still good for people to share information between them. A nice thing about wikis is that people can share information without actually signing in, their IP address is logged but in rest, they can do whatever they want. The bad thing about wikis is that people can do whatever they want, without signing in. Combine the bad and good and you get a controversy.<br />
<br />
Wikis are the heaven of spammers and vandals, this is a known fact. Spam is a weird thing, but if the spammer links to an nonexistent domain, that's even weirder. This happened on the aforementioned wiki. After checking with a mysterious John, he had the idea to register the domain name and watch what happens, how many visitors the domain gets, how much AdSense revenue can one earn with such a domain and so on. Below you will find all the details.<br />
<br />
<b>The spammer</b><br />
<br />
On the wiki the IP address of the spammer when the spammy content was placed was 114.80.67.252. This IP address was tracked back to China and seems to be used by the Shanghai Minhang Cancer Hospital.<br />
The content of the spam was similar to:<br />
<blockquote><i><b>yjfgv http://</b></i><b><span id="main" style="visibility: visible;"><span id="search" style="visibility: visible;"><i>fh6whUq3NnsPfj8g3vr0gQO4Yyzf.com</i></span></span></b></blockquote>The first part of the comment is much likely a variable unique for the site the comment was placed on and is used by the spammer for tracking which websites allow comments through without moderation.<br />
<br />
When we first observed the link, Google knew about roughly 960-970 web pages where the string figured. At the time of this post Google knows about 49,000.<br />
<br />
<b>Traffic drill down</b><br />
<br />
In the course of one week, the website received traffic mainly --obviously-- from referring websites. In total there were 6120 unique request. In 289 cases the HTTP response code was "304 (not modified)" which means that someone from that specific computer and browser already visited the website.<br />
In 164 cases the user was referred from a WordPress admin back-end's Akismet spam viewer which means that some blog admins have the habit of visiting the URLs from the already caught spam.<br />
From the total of 6120 unique requests 613 were referred by Live Mail and Yahoo! Mail. Since mailboxes weren't targeted by the spammer, this likely means that people received a notification from the publishing platform and clicked through from within the spammy mail. Noteworthy, that Gmail referred only one single visitor.<br />
<br />
<ul><li>2010-04-11, 18:36 - 0 (website went online)</li>
<li>2010-04-12, 18:35 - 4515 </li>
<li>2010-04-13, 18:37 - 798</li>
<li>2010-04-14, 18:38 - 318</li>
<li>2010-04-15, 18:16 - 185</li>
<li>2010-04-16, 18:31 - 168 </li>
<li>2010-04-17, 18:31 - 136</li>
</ul><div class="separator" style="clear: both; text-align: center;"><a href="http://spreadsheets.google.com/oimg?key=0AiRzD6SQ2VmHdG1iQ1dueXdfQW04RWVXbm1yYmtZYnc&oid=1&zx=1ife1i-7xfep2" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="283" src="http://spreadsheets.google.com/oimg?key=0AiRzD6SQ2VmHdG1iQ1dueXdfQW04RWVXbm1yYmtZYnc&oid=1&zx=1ife1i-7xfep2" width="400" /></a></div><br />
<br />
<b>User-Agent strings</b><br />
<ul><li>iPhone - 142</li>
<li>Chrome - 330</li>
<li>MSIE - 2104 (IE6: 677, IE7: 519, IE7:899)</li>
<li>FireFox - 1053</li>
<li>Opera - 90</li>
<li>Blackberry - 33</li>
<li>Safari - 302</li>
<li>Android - 11</li>
</ul><div class="separator" style="clear: both; text-align: center;"><a href="http://spreadsheets.google.com/oimg?key=0AiRzD6SQ2VmHdHVtQUZ4TEdPZENlZUNWaHFmSmVCOXc&oid=2&zx=927d2k-39q5e7" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="http://spreadsheets.google.com/oimg?key=0AiRzD6SQ2VmHdHVtQUZ4TEdPZENlZUNWaHFmSmVCOXc&oid=2&zx=927d2k-39q5e7" width="400" /></a></div><br />
<br />
<b>Crawler Visits</b> <br />
<br />
Yandex's crawler visited the homepage the first time at 11th of April at 2350 GMT. It was followed by Googlebot on 12th, 0045 GMT then Yahoo's Slurp the same day at 0625 GMT. The last was Archive.org's crawler, which visited the homepage on 16th of April at 1357 GMT.<br />
In the one week test period none of Ask's or Bing's crawlers visited the homepage.<br />
<br />
<b>AdSense Stats</b><br />
<br />
In one week the total earnings through AdSense was about 2 USD. The click-through-rates (CTR) were relatively normal for a page where are no other links to click.<br />
Below is the AdSense drill down containing the date, number of clicks and CTR.<br />
<ul><li>2010-04-11 0 0 (website went online)<br />
</li>
<li>2010-04-12 8 2.29%</li>
<li>2010-04-13 7 1.87%</li>
<li>2010-04-14 3 1.66%</li>
<li>2010-04-15 5 4.03%</li>
<li>2010-04-16 1 0.8% <br />
</li>
<li>2010-04-17 0 0%</li>
</ul><br />
<b>Publishing Platforms</b><br />
<br />
In the very first days of the domain, a list of publishing platforms on which the spammy comment appeared was compiled. 69 percent of the comments were left on custom coded guest books or blogs. The rest of the spam was left on some sort of well established publishing platform:<br />
<ul><li>WordPress - 15%</li>
<li>Joomla - 3%</li>
<li>Mediawiki - 2%</li>
<li>Serendipity - 2%</li>
<li>phpBB - 2%</li>
<li>Other - 7%</li>
</ul>In 13% of the comments left by the spammer, the URL was turned into link by the CMS automatically. In 23% of the cases when a link appeared, the "nofollow" microformat was not used.methodehttp://www.blogger.com/profile/00708210004709797741noreply@blogger.com0