Saturday, August 4, 2012

Men's 100M track 9.66sec in 2012?

while waiting for race on Aug 5. I just wanted to look historical timing ( So, a simple linear regression with Excel (really?), gives me 9.66 sec (2008, 9.69 sec) for gold 2012.

And readers of 2664, please let me know if the race is won in just a second.

Friday, July 27, 2012

rename files mac

for file in *.txt
   mv "$file" "${file/.txt/.fasta}"

Wednesday, April 4, 2012

Matrix to vector Excel formula

Matrix is named range of matrix

Horizontal =OFFSET(Matrix,TRUNC((ROW()-ROW($A$12))/COLUMNS(Matrix)),MOD(ROW()-ROW($A$12),COLUMNS(Matrix)),1,1)

Vertical =OFFSET(Matrix,MOD(ROW()-ROW($A$12),ROWS(Matrix)),TRUNC((ROW()-ROW($A$12))/ROWS(Matrix)),1,1)


Thursday, February 16, 2012

batch rename and (move) files using python

So, my friend asked me to rename the files. The file names are alphanumeric and they should be renamed with leading zeroes but in order. the default sort is 1,10,11….2, 20….etc  but correct order would be 1,2,3,4,5…… So, I did some hit and trial and some binging, googling…
Finally done
here is the code

import os
import re
import shutil

def main():
## Commented out are the codes to create file for working purposes    
##    for a in range(1,20):
##        for b in ["a", "b", "c"]:
##            filename="sec"+str(a)+b+".data"
##            c=open(filename,"a")
##            c.close()
    sortedfnames=sorted(fnames, key=natural_sortkey)
    for index, fname in enumerate(sortedfnames):

        index2=str(index).zfill(4)  ##change zfill parameter to 3 if 001, 4 if 0001 etc
        #print str(index)+ fname
        shutil.copy(os.path.join(directory,fname), os.path.join(directory2,(index2+fname)))

tokenize = re.compile(r'(\d+)|(\D+)').findall

def natural_sortkey(string):          
    return tuple(int(num) if num else alpha for num, alpha in tokenize(string))


Worked as magic!!

note: I got the alphanumeric sort tips from stackoverflow user(

Wednesday, February 15, 2012

Alternate styling in word [With Macro]

Call me lazy,

I would rather write a script to do alternate bold and not bold of paragraphs than do it manually.

So, here is the script

sub i_am_not_lazy()

Dim para As Paragraph
Dim i As Integer
i = 1
For Each para In Selection.Paragraphs
If i Mod 2 = 0 Then
para.Range.Font.Bold = True
para.Range.Font.Bold = False
End If
i = i + 1

end sub

here is the result...

Dear aaa,
I am not trying to be lazy but I have some 50 plus questions
 I have to insert answers in between them in BOLD.
I am trying to find out if we have some smart idea to do.
Thank you for your post. I really was not looking for using CTRL B button because I have to press it everytime I enter answers.
Your response for putting macros seemed useful, but I still did not get how to use it.
Can you please guide me through the steps?
Thank you so much

Thursday, January 12, 2012

find and replace in batch in excel

Sub ReplaceText()
 'value to replace in D, value to be replaced by in E
For Each vCell In Range("d1:d49").Cells 'range to replace b
Columns("b:b").Cells.Replace What:=vCell, Replacement:=vCell.Offset(0, 1).Value, LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False Next vCell
End Sub

Tuesday, November 1, 2011

alpha lattice design

Background Design: cycdesign alphagen alpha+ R (agricolae) SAS (plan?) Analyse: With SAS proc lattice package (agricolae)