IdeaMonk

thoughts, ideas, code and other things...

Friday, June 27, 2008

Adding SyntaxHighlighter to your blogger blog

Have you noticed colourful, beautified codes written in syntax highlighted format on so many blogs around the world? Here's how to get this into your own blog too -

1. If you want it to be done fast checkout FaziBear: Blogger Syntax Highlighter. You can add it as a widget on your blog. Clean and easy!

2. Now if you really want to use the real SyntaxHighlighter and wish to have greater control, the developertips article is worth reading.

3. Now as you have tried both of these, you will encounter strange extra
s and blank lines between each line. Don't worry I have a stupid hack for that. Use my negligibly modified code instead of the one mentioned at developertips.


<link href='http://[YOUR OWN PAGE].googlepages.com/SyntaxHighlighter.css' rel='stylesheet' type='text/css'/>

<script src='http://[YOUR OWN PAGE].googlepages.com/shCore.js' type='text/javascript'/>
<script src='http://[YOUR OWN PAGE].googlepages.com/shBrushCpp.js' type='text/javascript'/>
<script src='http://[YOUR OWN PAGE].googlepages.com/shBrushCSharp.js' type='text/javascript'/>
<script src='http://[YOUR OWN PAGE].googlepages.com/shBrushCss.js' type='text/javascript'/>
<script src='http://[YOUR OWN PAGE].googlepages.com/shBrushJava.js' type='text/javascript'/>
<script src='http://[YOUR OWN PAGE].googlepages.com/shBrushJScript.js' type='text/javascript'/>
<script src='http://[YOUR OWN PAGE].googlepages.com/shBrushSql.js' type='text/javascript'/>
<script src='http://[YOUR OWN PAGE].googlepages.com/shBrushXml.js' type='text/javascript'/>
<script src='http://[YOUR OWN PAGE].googlepages.com/shBrushRuby.js' type='text/javascript'/>

<script class='javascript'>
//<![CDATA[
function FindTagsByName(container, name, Tag)
{
var elements = document.getElementsByTagName(Tag);
for (var i = 0; i < elements.length; i++)
{
if (elements[i].getAttribute("name") == name)
{
container.push(elements[i]);
}
}
}
var elements = [];
FindTagsByName(elements, "code", "pre");
FindTagsByName(elements, "code", "textarea");

for(var i=0; i < elements.length; i++) {
if(elements[i].nodeName.toUpperCase() == "TEXTAREA") {
var childNode = elements[i].childNodes[0];
var newNode = document.createTextNode(childNode.nodeValue.replace(/<br\s*\/?>/gi,''));
elements[i].replaceChild(newNode, childNode);

}
else if(elements[i].nodeName.toUpperCase() == "PRE") {
brs = elements[i].getElementsByTagName("br");
for(var j = 0, brLength = brs.length; j < brLength; j++) {
var newNode = document.createTextNode("");
elements[i].replaceChild(newNode, brs[0]);
}
}
}
//clipboard does not work well, no line breaks
// dp.SyntaxHighlighter.ClipboardSwf =
//"http://[YOUR OWN PAGE].googlepages.com/clipboard.swf";
dp.SyntaxHighlighter.HighlightAll("code");
//]]>

</script>

Labels: ,

instr is indexOf in javascript

Is there any equivalent of instr of VBscript in javascript, yes there is, its called indexOf
object.indexOf (string);

this will give you position of string in the object indexed from 0. examples -
var foo="ideamonk";
document.writeln (foo.indexOf("idea"));
document.writeln (foo.indexOf("monk"));
document.writeln (foo.indexOf("nothing"));

the output is likely to be -
0
4
-1

Labels:

Thursday, June 26, 2008

“Shoot the Runner” by Kasabian

“Shoot the Runner” by Kasabian. The coolest music video I’ve seen in a while.

Labels:

Wednesday, June 25, 2008

Evil Captcha

http://i32.tinypic.com/2upqp6s.jpg

Is this the height of spam, or height of trust, or height of programmer's wild imagination. Whatever it is... its crazy!

Labels: ,

Friday, June 20, 2008

GTA IV or some 3d Artist's work

Nopes! don't mistake it for GTA IV, its an "The Streets of memories" by Marek Denko overlayed with HUD of the game. some more -

Last one - After many unsuccessful tries to quit smoking it looks like this time it will be successfully done. I’m really curious what will I find as a alternative. As far as I know myself I think it will be kind of coke or liquirizia roots. I didn’t like the ash part of my render so I cutted it away. If you are still interested to see it then check my demoreel with camera projected picture of real ash. That one is much better. This piece took me about 2 hours of work. Rendered in Final render stage-1.
Crowd 8 - It was a boring night and I didn’t know what to do so I typed the word “inspiration” into Google and I found this page: bsimple.com. I immediately fell in love with the work of photographer Misha Gordin. I used one of the impressive photographs and I made a re-make it in 3D. Hope you like it. Original photograph by Misha Gordin. Thank you! Done in 3dsmax with Final render.
Blood series - It all started when I cut my finger by accident. I started to bleed on the paper and notes from university. I started to play with blood trying to create some nice textures. Crazy i know. And blood series were born - then it was just a quick modeling of clothes based on real references and quick light setup. Rendered in Final render stage-1. Overpainted with my blood and lot of dirt textures in Photoshop.
Waiting for spring - It took me one week of work. I tried to achieve photorealistic look. I downloaded blueprints from http://www.suurland.com/ . I took many pictures of real Fiat500L to have best references as possible. Snow beneath the car is modeled and after displaced with semi-procedural displacement map. There is all 3d except the houses in background. Rendered in Final render.
Behind the portrait of Dorian Grey - I tried to achieve a good portrait look with deep feeling. It should be the dark side of Dorian Grey. Rendered in Final r

Labels: , ,

Wednesday, June 18, 2008

Scoring High in Word Games on facebook!



Ever played TextTwirl or WordShuffle on facebook or elsewhere ?

Don't you ever! for they are very addictive as my uber player buddy from Wisconsin warns me. But what can I do, I have my own problems, I'm jobless, there's nothing to do, And I like winning the smart way.
So, what do I do! I think of C++ and a Dictionary... and poof! my weapon is ready in my mind! And soon I come up with my own little tool called WordWar.
Heres the code:

#include <iostream>
using namespace std;

int main(int argc, char *argv[]){
string word,check,cword;
int len,match,count,checksum=0,l;

if (argc>=3){
word = argv[1];
len = word.length();
for (int i=0;i<len;i++)
checksum+=word[i];

freopen (argv[2],"r+",stdin);
if (argc==4){
while (cin >> check){
check[0]=tolower(check[0]);
if (check.length()<=len &amp;&amp; check.length()>=3){
match = 1; count=0;
cword=word;
for (int i=0;i<check.length();i++){
if (cword.find(check[i]) == string::npos){
match=0;
break;
} else {
cword[cword.find(check[i])]='_';
}
}
if (match == 1)
cout << check << endl;
}
}
} else {
while (cin >> check){
if (check.length()==len){
match = 1; count=0;
for (int i=0;i<len;i++){
if (word.find(check[i]) == string::npos){
match=0;
break;
} else {
count+=check[i];
}
}
if (match == 1 &amp;&amp; count==checksum)
cout << check << endl;
}
}
}
} else {
cout << "WordWar v0.1\t\t\t(c) Abhishek Mishra\n"
<<" \t\t\t ideamonk@gmail.com\n\n"
<<"Usage : "<<argv[0]<<"> <dictionary_file>\n\n";
}
return 0;
}

For this you also need a dictionary. Download dictionary here. This is a very basic dictionary, I recommend you to get better one or try adding 's' etc to this ones results. Compile WordWar in DevCPP/MinGW32 on windows or GCC on linux. Have 1.txt (your dictionary) in the same path. and run it like this ->

enjoy scoring high!
With PHP I can also make a neat live web interface to cheat. :)
happy hacking.
http://ideamonk.googlepages.com/ddl.gif

Labels: , ,

Thursday, June 12, 2008

I am a lakhpati now! wow :|

got $69 today. That makes my total revenue since March '07 sum up to $2870 + $230(yet to come)
So, it takes me 450 days to become a lakh-pati from Adbrite. Making average $6.8 per day wasn't that hard. Thanks to my SEO skills everyday 10-15 people arrive at my $$ blog from google search alone. But now my CTR has been falling. Average revenue per day lags at $1.xx a day. So, I manage to make Rs. 1500 a month effortlessly. Thats Rs.50 a day. Hmm.. this means I don't have to ask for pocket-money anymore.
And what happened to $2870 that I got so far? Hmm..
initially 30k was wasted on broadband bills.
Some 7-8k used in flight to Bangalore.
3K for Samsung portable HDD.
30K for my Compaq Presario V6000.
Rest of the 30K saved me from being ashamed at my lavish expenditures in 1st and 2nd semester. hehe.
Its time to make some more moolah! Adbrite... here I come to plunder.




and yes! looks like my average daily is going to shoot up! $4.56 yesterday :-)

Labels:

Wednesday, June 11, 2008

KAMIL! jumping from 57 to 53 to 46!

Okay this is what made me happy about ruby -

10.times do
s=gets
p=1
s.gsub(/[DTFL]/){p*=2}
puts p
end

this made me happier :) to 53 bytes
i just remembered that Ruby is object oriented to the core!

10.times do
p=1
gets.gsub(/[DTFL]/){p*=2}
puts p
end

and some common syntax sense made it shrink to 48 bytes :))

10.times{p=1;gets.gsub(/[DTFL]/){p*=2}
puts p}

Still i know there is a shorter solution... that's the beauty of spoj.
The day ends in world rank of 1900 and 1.4 points. :)

Labels: , ,

Monday, June 09, 2008

KAMIL ... stuck at 57

Another challenge problem at SPOJ - KAMIL
interesting one, easy to figure out, but what the heck, write shortest code!
with C i could get 127 bytes code :(
Come Ruby into picture and poof! we got 57!

10.times do
s=gets
p=1
s.gsub(/[DTFL]/){p*=2}
puts p
end

looking forward for more compression... ;)

Labels: , ,