Hacking a site’s photo directory using DOM or jQuery

Web programming, Web security
I watched the film about Facebook the other day, yes I coudn't resist, and I thought it has some interesting moments. At the beginning, Marck "hacks" some Harvard websites which contain profile photos from the students. How did he made this? Well I didnt saw the code or remember it from the film but I am going to suppose what he did and how. Lots of webpages store they images in the same directory, or at least place all the same type images together, this means all the profile images were in the same source. Also, due to programming issues, those images tend to have a name which is a numeric code, maybe the student id, or maybe the number of the photo when that photo was uploaded. This means…
Read More

JQuery’s $(document).ready() method

Web programming
JQuery has a method that can help you when developing a website called "document.ready", in JQuery language: "$(document).ready()". This method let's you start doing things in your page using javascript once the document is ready but without having to wait for all the images to load. I mean, if you don't use JQuery and you want to do something like an effect or whatever when the page loads, you will for sure use the window.onload to start it, but if you have used this option in the past you will notice that window.onload needs the entirely page to be loaded, and sometimes due to images or something that is being requested to another server this takes some time making the effect less impressive or even regrettable. So JQuery gives you…
Read More

Introduction to jQuery

Web programming
To use jQuery we need to get the library from one of those sites hosting it, for example the JQuery project page, or use the Google Libraries API. We can call the online versions and save server resources or better have our own version to make sure it never goes off. jQuery library has methods, selectors and events to interact with the page objects and let you make some very nice effects, change or add styles and some other issues with no effort at all. I am going to have a look at it with the basics to get initiated into this amazing library. Selectors First of all, to interact with the page objects we need to select them, so that we can know with which object we are working.…
Read More

Reading blog feed using PHP

Web programming
Well, once I made the last post about how to read a blog feed in ASP.Net using LINQ I just wondered if I would be able to do it in PHP too, so I did it. Here's the code: [sourcecode language="php" wraplines="false"] function getBlogFeed($urlRSS) { $doc = new DOMDocument(); $doc->load($urlRSS); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node): $itemRSS = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue ); array_push($arrFeeds, $itemRSS); endforeach; return $arrFeeds; } [/sourcecode] Once you have that done you can just show it as you wish, this is my show function but have in mind it uses my css styles (you can have a look at how it looks at my home page). [sourcecode language="php" wraplines="false"] function showBlogFeed($urlRSS){ if ($urlRSS !== ''):…
Read More

Reading blog feed in Atom or RSS with LINQ

Web programming
One of the most practical features a blog has its the possibility of requesting the latest posts from another webpage to read it without the need of accessing its current webpage. For doing this crazy idea blogs use XML technology, the REST protocol and one of the syndication standards like RSS, RSS2.0, Atom or RDF. In this case I am going to use RSS2.0 to request the feed of my blog and I will manage it with Linq so that I will have a collection of my latest posts in a few lines. Let's see the code: [sourcecode language="vb" wraplines="false"] Private Sub readBlogRSS20() Dim feed As XDocument = XDocument.Load("http://www.rubencanton.com/blog/feed/") Dim sum = From item In feed.Element("rss").Element("channel").Elements("item") _ Select New BlogArticle(item.Element("title"), item.Element("link"), _ item.Element("pubDate"), item.Element("description")) End Sub [/sourcecode] I just load…
Read More

Extension methods in C#.Net

Web programming
One very useful thing we have in .Net technology is the possibility of extending it's classes to have our own and useful methods to work with. For example, imagine I need to show the user name in the project saying hello, something like this: "Hello Ruben!". But, I do not know if the name is stored in the database in lowercase, uppercase or how. So, I am going to capitalize it to be sure: [sourcecode language="csharp" wraplines="false"] public void SayHello() { string userName = "ruben"; Console.WriteLine(userName.Capitalize()); } [/sourcecode] But, Oops! We have a problem. The method Capitalize does not exist in C# string class, so we cannot just capitalize it with an instruction and we are going to need to make a library which we'll have to call always to…
Read More

Readonly vs Const in C#.Net

Web programming
In C#.Net we have two ways to establish a value that is constant (which means that its value will not be modifiable). The first way is the old one, making a const variable (maybe you know it as #define), the second one is to make a readonly variable. The most important difference between them is that a const will be evaluated at compile time while a readonly variable will be evaluated at run time. This limits the possibilities with consts since you cannot, for example, declare const structures, as they will need to call a constructor and that has to be made in run time, but you still can attach some expressions to it as soon as it can be resolved in compilation time. [sourcecode language="csharp" wraplines="false"] public const int…
Read More

Using LINQ in VB.Net for selecting encoded data

Web programming
Between the multiple advantages which offers LINQ I think there's the possibility of reselect some data you have in cache or RAM so you don't need to send another request to the database. I was programming a little personal application in VB.Net yesterday and found myself with a little problem. I am saving some data encoded in base64 in the database and I want to have the option to filter and show only the ones which match. The problem came when I realized that, of course, having the data encoded in the Access DB I couldn't just use a "LIKE" to filter the selection, since the characters are not as they really are. First of all I thought on decoding the data in the DB and then filter but I…
Read More

Asynchronous request with JavaScript: home-made AJAX

Web programming
This is a translation from my original post in spanish. I hope you enjoy it! Note: Original post had code in HTML, sorry if I missed something. A few days ago I was building a module that should make asynchronous requests to a webservice using javascript, in other words, the famous AJAX but manually made, without using any library. For those who do not know what AJAX is, it's what allows server requests without having to load the entire page. Surely you've seen it in many places, for example, when posting a comment on a blog which is posted and shown without a full reload of the page. So, in order to do this we need to use the XMLHttpRequest object of our browser using JavaScript and send a request…
Read More

Testing LINQ performance with ASP.Net

Web programming
This post its a translation from my original post in spanish. I hope you enjoy it! :) After learning the basics about LINQ and how it works, I had no choice but to test if, not only does it simplifies the code but also improves its efficiency. I decided to test the reading speed of XML files with LINQ and determine which one has a better reading speed: .Net XML access library or its new technology, LINQ. To that purpose, I built an XML with 100.000 registers which simulates a table with students data and I will send some requests. (more…)
Read More

How to throw a pop-up properly with Javascript

Web programming, Web standards
This is a translation from my original post in spanish. Hope you enjoy it! In some cases it can be useful for us and even more comfortable for the user to open a page in a pop-up on which to show the information. If we search in Google how to do it or read any javascript manual the code that will be shown its this one: [sourcecode language="js" wraplines="false"] window.open('url to open','window name','attribute1,attribute2') [/sourcecode] In fact, that code has some mistakes, lets see: Browsers without Javascript will cannot open the page. It will not be crawled correctly by searchers, and some crawlers, will not know how to follow it. When going over it with the mouse we will not see the url on our browser status bar. The user loses…
Read More

How to make a wordpress widget

Web programming
This is a translation from my original post in spanish. I hope you enjoy it! :) Continuing with the make your own wordpress theme guide, it is possible that you come to the point where you need a new module you don't have in the sidebar, more known as widget. There are a few ways for doing this, in one side since you can choose between a dynamic and an static sidebar you could choose the second one and just develop it in php in one piece, though it will not be editable from the administration panel. Another option is to enter in the admin panel and create a text widget which you can use to insert javascript or HTML code. But the problem comes in case you want to…
Read More