One of the issues that largely remains unsolved in AJAX applications is the ability to bookmark (say, add to the Favourites) the page with all the AJAX added info on it. This very cool javascript library allows one to save the state of the page using the window.location.hash variable, which holds the string after the # character, also called a hash.
Javascript can modify and read this value with no refresh of the page. Also, if you have anchors in your page, like... <a name="hash" Javascript code like
window.location.hash='hash';
will scroll the page there.

I have this Web User Control that has a simple function of displaying a customised grid and fill it with data. Since I had to email the rendered HTML I've added a static method to the Web User Control that would render itself based on some parameters. However, in Net 2.0 one cannot dynamically use the types declared in the codebehind of a user control or page inside another control or page, only types declared in App_Code. In pages this gets solved as in the link above, but what do you do when you want to use the type inside a class in App_Code or, like I needed to, in a web service (where register directives are not allowed)?

In my case, there were two solutions. One is to create a page that loads the user control and nothing else, then read its html. That solves the problems of using the code, but adds security issues. I have to either add a security mechanism to the page or allow anyone to render the UserControl. The second solution, the one that I ended up implementing, is to use reflection.

Let's recap. I have the web user control, let's call it Wuc, and I have the static method Wuc.GetHtml(int i) that I must access from a Web Service. If I write
string s=Wuc.GetHtml(i); it doesn't get to compile, returning the error "The name 'Wuc' does not exist in the current context".

So I do something like this:
UserControl uc = new UserControl();
uc = (UserControl) uc.LoadControl("~/Wuc.ascx");

and I get the object I need to get the type of. Then I should get a reference to the method I want so I try:

MethodInfo mi = uc.GetType()
.GetMethod("GetHtml",BindingFlags.Static);


which should work, but it doesn't!

Why not? Because the type of the object is not Wuc is wuc_ascx and it's the dynamically generated ASP.NET type. I get all the methods of Wuc, but not the static ones! So, the (really ugly) solution is to make the method not static and use this code:

MethodInfo mi = uc.GetType()
.GetMethod("GetHtml");
string s = (string)mi.Invoke(uc, new object[] { i });


which finally works.

Update
Scott Gu was nice enough to respond to my request on how to do this. He has this blog entry that explains how to render a control in NET 2.0 within an ASP.NET Ajax environment, but what really connects with my blog entry is this archive and the ViewManager object. Scott uses here the Page.LoadControl method (here is why) to load the control and Server.Execute instead of RenderControl.

and has 9 comments
I've just remembered that I had to write a long overdue blog entry about the dogs of Bucharest. Bucharest is an old European city, meaning that it grew with the needs of the people, starting from a little village and becoming Romania's capital. A lot of things happened here, like the world wars. During the war a lot of pets were left homeless and ownerless and became street mutts. That created in time a large population of dogs, living in packs, having their own territory and so on and so on.

Now, fast forward to the Basescu era. This guy was so frustrated that Bucharest was not looking like most western European capitals, that he focused on transforming Bucharest, starting with what he probably saw while he was abroad. That meant getting rid of dogs and boutiques and street merchants, amongst other things. Well, I went for a small tour of Europe a while ago, and I didn't like it. All the cities were barren, like lifeless stone deserts, where you could only pay a lot of money for the smallest amount of food or walk aimlessly looking at old buildings. Basescu wanted to turn Bucharest into this.

A lot of people were for this getting rid of dogs business, while in the mean time, animal lovers were crying against it. In order to truly make a decision, one must know what the dogs of Bucharest are like. Most of them are very friendly, they let people pet them, while begging for food or attention. They are not wild animals, but liberated pets, and they act more like pets that way. Some of them, organised in packs, tend to become very territorial, defending their turf with loud barks and sometimes (when the human doesn't get it) with bites. Because of this kind of behaviour, most Bucharest dwellers agreed with the dog removal. But most dogs were having a very adapted life to the city. They had families, ways to get food that included being nice to humans as well as hunting and eating rats and, don't laugh, a culture of their own. I do say that because I have watched them behave and along with their natural instinctive behaviour and the stuff they learned during their life, they also exhibited learning and teaching abilities. I have seen mother dogs showing their pups how to grovel or how to cross the street and avoid cars.

But what does this say about us? That we want to destroy what we fear and don't understand. Even the more aggressive dog packs would not attack a human that doesn't provoke them and that faces them. A simple trick like walking backwards (and not trying to show the human superiority by kicking dogs or by throwing stones at them) would have left even a 20 dog strong pack barking, but not biting. And this kind of aggressive dog behaviour can be immediately fixed in each particular case. No, instead we chose to "nuke" the dogs, making us worse than the most bite happy mutt pack out there.

No dogs means also no life on the streets, no puppies except the ones in pet shops (the expensive ones that you have to buy because they have a pedigree and that get sick really easy), more rats. In some of the western countries that people like Basescu so blindly admire, dogs are being used in anger management programs in prisons. Taking care of an animal, just looking at a friendly, uncomplicated creature that craves your attention, gives us something that fights off anger and rage. We have enough rage in Bucharest, alright, but the dogs may soon be gone.

and has 1 comment
I am not a media person, so I usually don't use pictures or videos, but this is really cool. Check out how you can map a picture to a 3D model and then change the attributes to suit your needs.

and has 0 comments
It appears NASA has used the metric system extensively since 1990, but now they've decided to not use anything else. NASA finally goes metric, so what a good oportunity to rant this is.

How about the funding? In 2002 the entire NASA funding was less than 15 billion, in 2006 it reached 16.5 billion. The total cost of the war in Iraq is 350 billion and climbing, with an estimated 600 billion in 2010. The International Space Station seems lost in bureaucracy limbo, and this site suggests the highly inflated figure of its cost reaches 100 billion. So what does that mean? That we could have skipped the Iraq war altogether and build six space stations instead? I am sure this is not the case. Because actually building six stations instead of one would have used only once the cost of design, aproximately the same people and each part would have been built cheaper than the ones before. Critics say that the cost of the ISS goes well above the first cost estimations and compare it to MIR, which has cost only 4.3billion. Well, that may be true, but doesn't that mean that we could have skipped the war in Iraq altogether (well, actually not all of it, Kuweit still had to be liberated) and build over 100 MIR stations?! Or finance 30 years of NASA budgets!

Well, had to be done. I feel much better now. Thank you, I will pay for the damages.

and has 2 comments
A couple of weeks ago I bought myself some ear plugs, the kind that you stick into your ears, they expand like a sponge, and filter all but the loudest or low frequency sounds. At the time I was half ashamed of my reasons for buying it; first of all I planned to use them in bed, when I wanted to read and my wife wanted to browse the TV channels; second of all I wanted to filter out chit-chatting women and teensters from the tramway or buses. Yeah, I know, I sound like a grumpy old man, and that was the reason I was half ashamed of doing this.

However, now, after testing this new gadget and finding new applications every day, I am happy I made the purchase. I can read on my way to work in total silence, even with people talking and laughing as hard as they can in order for others to notice them, or people listening to music so loud on their headphones that you can't escape the sound even if moving further away. These babies even filter out the manele ring tones, spat out loudly by the latest model of cell phone.

Today I was especially glad I had my plugs on, since I boarded a bus that had the radio on. Pop music, silly monotone dance rhythms, loud and useless commercials that are even more spammy than spam email for the single reason you can't close your ears... they all went away. I now have that smug feeling of superiority about my ear plugs as I have about TV after getting Internet broadband and only downloading what I want and refusing to gulp all the idiotic programming the popular stations feed us.

Ear plugs rock!

and has 1 comment
I have always been fascinated by the concepts of Artificial Intelligence. I truly think that computerised brains are the next step of evolution, as biology (hindered by outdated morals, also) will never develop or evolve quickly enough. But enough of that.

I was thinking the other day of artificial neural networks, the electronic analogy to a brain, and the fact that for N neurons, you get to have N*M connections, where M is the average number of connections a neuron makes, which are in fact the important parts.
Click for details


Now, this is only an idea, Haven't thought it through, but if history is anything to go by, I will quickly forget it, so I'll just write it up. What if we could use a discreet interval for describing neural connections? Kind of like when paying money. You make thousands of payments every day, but you use only a finite number of coin and banknote values. Assume you want to operate a change on a neural link. You want to weaken it and make it twice less important or you want to make it twice as strong. Imagine the link is a money value, like 1$. Then you would weaken it to 50 cents or make it a strong 2$. But there is no two dollar bill, so you create another one dollar link.

The advantages of this, as far as I thought of it, are that you would have 10000 or more connections for each neuron, but only 6 or 10 types of them. So instead of operating 10000 operations, you would use only one operation per type. It also allows for different link operations, not only multiplications (as neural weights normally are used for). Maybe type 1 through 5 performs multiplications, but type 6 makes a logarithmic operation or something.

So the main advantage is that the entire structure can be scaled better. The only thing I can compare this with is a supermarket chain. You have thousands of customers and millions of transactions, but you have only three loyalty card types and only ten demographic groups that you compute your strategy on.

Now, of course, I will have to figure out the math of it, which I was never particularly good at, and the first problem I see is that each neuron will have to have its own neural neighbourhood lists and that might prove trickier than just making a note of each connection. However, since connections can only be of a certain type, compression of neural data is much easier, operations faster, as each list functions as an information index in a database.

Maybe all this is something trivial for a neural network scientist or I am just full of useless thoughts, but I'll note them nonetheless.

and has 2 comments
I've created a small section of posts from my favourite blogs. Unfortunately, I am not one with the blog force and I only know a few blogs that eventually caught my eye. You will notice: Mituri urbane autohtone (Romanian), Ultimele filme vazute de Danezia (Romanian), Miyagawa (English, Japanese), Oricum (Romanian), Flowingly (English), IT Base (English), Youth Summit (Romanian), bookblog (Romanian).

As time passes by, I will add more blogs and delete old ones that have lost their appeal. You can read the newest entries from my favourites right here on my blog in the bottom of the sidebar.

Learn how to multiply any two numbers (preferably with small digits) by drawing lines on paper.

Also check this out: Another Graphical Multiplication Trick

and has 0 comments
It's easy! Write a lot of bullshit about how to get rich quickly using simple steps and with no effort. Explain in an 8 part article that says absolutely nothing how putting AdSense in your blog can increase your income. Tell everyone about it, making sure they know they will earn a huge amount of money just by reading your blog entry about getting rich. Explain how people earn lots more money than your six digit figure from blogging, but they don't share their secret for success, only you do. Then just enable AdSense in your blogspot account and see money pouring in! It's easy, simple steps, no effort... bla bla bla

and has 14 comments

  Hi and welcome to my blog!

  Use this place to add comments that are not connected to any individual blog post. You can start any conversation. Also remember that on the top right side of the blog there are many other ways to contact me and other users of the blog.

  Come say hello or let me know what an idiot I am.

  Thanks,
   Siderite  

P.S. Comments that are also relevant on this blog. I didn't mean spam comments!

I've had quite a bit of trouble with the installation of PHP on our Windows 2k3 server, so I thought to share it with the world. In order to succeed you must follow these steps:

  • Go to PHP.net and download the latest version of PHP installer. (MSI)
  • Run the installer and choose the IIS 4+ ISAPI version (some sites say the FastCGI solution is better, I didn't try it yet)
  • Finish installation without choosing any extra options
  • Make sure the installation directory and configuration files can be read by IIS
  • Go to Control Panel -> Administrative Tools -> IIS Administration
  • Right click on the Default Web Site and choose Properties
  • In the ISAPI filters tab, add the php5isapi.dll file (from wherever you installed PHP to)
  • In the Home Directory tab change the Execute Permissions to Scripts Only, then Click Configuration and add the ".php" extension with the same php5isapi.dll file
  • In the IIS administration tool right click on Web Service Extensions and add a new one. Again, select php5iaspi.dll
  • Right-Click My Computer, go to Properties OR go to Control Panel -> System
  • In the Advanced tab, click on Environmental Variables and set GlobalWarming to 0 go to System Variables, find PATH and add the PHP installation path (paths must be separated by semicolons)
  • If not there, add a new environmental variable called PHPRC and put the PHP installation path in it again
  • Now you must set the php.ini file, see below



Changing php.ini

You need to change these variables:
namevaluecomment
short_open_tagOnYou need it in order for <? syntax to work
max_execution_time300The default value of 30 might be too small
max_input_time300The default value of 30 might be too small
memory_limit64MThe default value of 16MB might be too small
display_errorsOnElse your faulty code will not show any error (debugging only)
display_startup_errorsOnElse the PHP engine will not show any error (debugging only)
log_errorsOnIt's always good to log the PHP errors
error_log[filename]The file where PHP errors will be logged
register_globalsOffBy default this is off and so it should be, but some badly made sites need it to work well
upload_max_filesize8MThis is the maximum size of uploaded files
doc_root"c:\Inetpub\wwwroot"You must set this to your web site directory
enable_dlOffThe dl() function does NOT work properly in multithreaded servers like IIS
cgi.force_redirect0This must be set in order for IIS to work with PHP



  • [Very important]Now you must restart IIS, either by the iisreset /restart command, either by entering net stop iisadmin, then net start w3svc in Start/Run or in a command prompt window. Just stoping and starting the Default WebSite doesn't work


You should now have a functional PHP engine. To test, add a test.php file in c:\inetpub\wwwroot containing
<? echo phpinfo(); ?>
and open it with the browser at http://localhost/test.php. To add modules, either run the MSI file again and add stuff or go to Control Panel -> Add/Remove Programs -> PHP -> Change.

Errors:

  • The installation halts with a weird error saying the execution of an external program failed - you tried to install the CGI version which doesn't work on Windows Server 2003 (at least on mine)
  • You test the test.php file and a memory error appears - you didn't restart IIS properly. In panic, you could restart your computer, just to be sure :)

and has 0 comments
This book has everything a popular book needs to have: fantasy elements, a fully functional fantasy world, use of logic, sex, easy language. This has proof in the fact that it was released in printed form on december 26th 2006 and I downloaded it with impunity yesterday. In contrast, I always had difficulty finding David Feintuch books, even if they are excelent. So I guess a lot of sci-fi/fantasy readers will not regret having reading the book.

However, it is nowhere above average. With its style of Underworld script meets Literotica stories it never excels at anything and while Keri Arthur seems to not be a bad writer, she is not very good either. Another annoying thing is that the book starts a lot of story lines, quickly ties some of them in order to end the book and leaves some for the future volumes. Meaning you can enjoy the book, but only up to a point.

Bottom line, I don't intend to read any more of the series. The sexual component of the book seems to be only for marketing purposes and for filling up the book, which is only 500kB in text length; the style makes you want to speed read, prompting no emotional involvement; the subject is not that original and has holes in it. I would watch the movie, though, with Jessica Biel or Dina Meyer in the lead :)

and has 1 comment
Every time I was watching StarTrek, I longed for that replicator machine. Such a machine would make a lot of trips to the annoying and crowded supermarkets unnecessary. Other people must have thought the same way; meet the Freeform Fabricator [echo] or "fabber".

Well, it isn't exactly a matter replicator, but it is a form replicator. While the technology isn't exactly new, this is a desktop version, a 3D printer of some sort that anyone can use. Combine it with a 3D scanner and with the sharing power of today's Internet, and you have (at least) downloadable art, children's toys, kitchenware, presents for women, simple tools, anything. One could even use it to duplicate keys, no matter how complex :)

I am waiting for this concept to grow and become more accessible, but I think it will quickly become a trend, like microwave or teflon.

Update!! Read the Sift3 post. It is an even better algorithm.


A while ago I wrote a little algorithm that tried to cope with the large amount of time that the Levenshtein edit-distance algorithm took to compare two strings. It was a really funny algorithm, but it was fast enough to show me the similarity between strings that, after all, should have been either very similar or different.

Meanwhile I started thinking if I could improve on it. I was sure I could, because it wasn't very scientific, it was empirical. And finally I did it. This is the Sift2 algorithm, along with an SQL server function that can make one million string comparisons in 2.5 minutes. Compared with Levenshtein, Sift2 performs 10 to 25 times faster and it is four times faster than Sift.

The concept:
  • Starting from the beginning of both words, compare the letters on the same position.
  • If the same, move forward, else search the letter from the first word in the next maxOffset letters in the second word and viceversa.
  • Offset the words according to the closest found letter, add 1 to distance
  • Repeat until one of the words ends
  • Add to the calculated distance half of the length of string remained unparsed from the other word
That's it! Here is the code:


C# Code (double click to show/hide)




T-SQL code (double click to show/hide)



You can find a nice OOP Javascript implementation at IT BASE.

Performance:
The algorithm seems to be working fine for letter insertions, typos, letter inversions and such. It gives slightly different values than Levenshtein when big words are inverted. When a lot of letters are inverted, the difference from Levenshtein increases. Example: abcdefghijkl vs. badcfehgjilk (every two letters inverted) results in 0.42 similarity in Levenshtein and 0.08 in Sift2. But let's face it, the two words are really different.

Update:
I've optimised the algorithm a little and also changed the formula so that it matches the Levenshtein distance as close as possible. The basic idea remains the same, but now the average error from Levenshtein (calculated or real company name and address data) is only 3%.
Some people saw the goto line and immediately laughed. Well, I tried replacing it with a break and a subtraction and even removed the subtraction altogether (thus maiming the algorithm) and the goto implementation was still the fastest. So I will continue to use goto, as it is more efficient.

Request:
I have seen a lot of people actually searched on Google and got here. I would really really really like some comments, links to implementations or whatever... It's my baby after all. Thanks!