Pages

Saturday, October 27, 2012

functional programming using map with python

Let's say you have a list of strings that ends with '\n' in python.

The simple way to remove '\n' or '\n\r' is string#rstrip() method. You can use readlines() method to read all the contents of file in a string. The problem is all the strings are appended by '\n'.

The issue is how to remove the '\n' for all the elements. From:
['STRING\n',
'\n', 
'STRING\n']
To:
['STRING',
'', 
'STRING']
Using functional programming, you can do it just one line.
lines = map(lambda x: x.rstrip(), lines)

embed swf file into blogger

You need to video capture from any tool. I used Jing for it.

Then, you need to store it into somewhere in the cloud, I used google sites.
<embed src="https://sites.google.com/site/csmgroup/files/2012-10-27_2026.swf"
quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" align="middle" height="300pt" width="500pt">

Change the name of label in the blogger's new interface

Let's say you want to change the blogger label with bloodspot.

Add a new label, and set the posts with the new label

Click the Posts menu.

Screen Shot 2012 10 27 at 1 16 56 PM

Then select them all.
Screen Shot 2012 10 27 at 1 18 29 PM

Then, add bloodspot as a new label
Screen Shot 2012 10 27 at 1 19 06 PM

Using tab/menu in blogger(blogspot)

You may want to add tabs/menus on top of your blogger.
Screen Shot 2012 10 27 at 1 27 59 PM
Actually they are nothing but a web page that you can make a link. For my case, I use label to get the posts with the label. For example, with the Python tab, I link http://prosseek.blogspot.com/search/label/python, and so on.
Then you can visit blogger.com to select your blogs.
Screen Shot 2012 10 27 at 11 05 24 AM
Click Pages to add the page you want. Don't forget to set the "Show pages as" to "Top tabs".
Screen Shot 2012 10 27 at 11 08 12 AM
Screen Shot 2012 10 27 at 11 06 48 AM
You can change the configuration
Screen Shot 2012 10 27 at 11 09 14 AM

css programming

css code is more like a declarative language with C flavor. C flavor means it has open and closing bracket, and it separates elements with ';' just like C does.
Declarative in the sense that it starts with name and then directives what should be done.
This is an example for having blue 15pt for h2 heading, and drop some shadow on image.
h2 {
  color: blue;
  font-size: 15pt;
}

img {
  box-shadow: 10px 10px 5px #888;
}
For box-shadow, refer to this post.

You can dynamically modify the setup using class or ID.
.noborder{box-shadow: none;}

References

SyntaxHighlighter brushes

This is a list what kind of brushes that SyntaxHighlighter provides. Screen Shot 2012 10 27 at 11 40 49 AM From http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/.

Changing font size for headers

Some of the default font size in blogger template does not setup accordingly. This is my rendered output with h2 tag.
2012 10 27 10 41 24
In order to change this, one needs to edit the css file. The first step is click the design button.
Screen Shot 2012 10 27 at 10 42 33 AM
Then Customize the layout.
Screen Shot 2012 10 27 at 10 43 00 AM
In advanced menu, you need to use Add CSS.
Screen Shot 2012 10 27 at 10 43 20 AM

Add the necessary code in the editor.

Screen Shot 2012 10 27 at 10 44 02 AM

Now you have larger font.

Screen Shot 2012 10 27 at 10 44 28 AM

Reference

Syntax highlighter issue with google chrome

The code with SyntaxHighlighter shows wrong line formatting in google chrome. Screen Shot 2012 10 27 at 10 10 36 AM
I found that this is a known issue with of line formatting, check this site.

The http://alexgorbatchev.com/pub/sh/current/styles/shCore.css source has the line that causes this problem.
Screen Shot 2012 10 27 at 10 16 49 AM

There are easy two solutions.

Solution 1

Modify the shCore.css : replace this line.
.syntaxhighlighter table td.gutter .line {
  text-align: right !important;
  padding: 0 0.5em 0 1em !important; <-- Replace this line
}
.syntaxhighlighter table td.gutter .line {
  text-align: right !important;
  padding: 0 5px  !important;
}
Or make it point to where the bug is fixed. : http://codeoncloud.co.cc/shCore.css

Solution 2

Add following line after Configure HTML/JavaScript edit. Screen Shot 2012 10 27 at 10 19 03 AM

Following code should be added.