Tuesday, July 29, 2008

Slide with animation and image from file


Sub EpisodeAnimation()
w = 350
h = 190
l = 180
t = 300

With ActivePresentation.Slides(1)
For i = 1 To .TimeLine.MainSequence.Count
.TimeLine.MainSequence(1).Delete
Next i

While (.Shapes.Count > 3)
.Shapes(.Shapes.Count).Delete
Wend

Set oShpA = .Shapes(3)

x = 0#
dx = 0.057
For i = 0 To 11
file = "D:\Debprakash\4-Virginia Tech\Phd-Documents\My Algorithms and Analysis\DynamicSim\" & Trim(Str(i)) & ".png"
Set oShpB = .Shapes.AddPicture(file, msoFalse, msoCTrue, l, t, w, h)

Set oEffect = .TimeLine.MainSequence.AddEffect(oShpB, msoAnimEffectFade, msoAnimateLevelNone, msoAnimTriggerWithPrevious)
oEffect.Exit = msoFalse

Set oEffect = .TimeLine.MainSequence.AddEffect(oShpA, msoAnimEffectPathRight, , msoAnimTriggerOnPageClick)
s = "M " & FormatNumber(x, 3, vbTrue, vbFalse, vbFalse) & " 0.00 L " _
& FormatNumber(x + dx, 3, vbTrue, vbFalse, vbFalse) & " 0.00 E"
oEffect.Behaviors(1).MotionEffect.Path = s
x = x + dx

Set oEffect = .TimeLine.MainSequence.AddEffect(oShpB, msoAnimEffectFade, , msoAnimTriggerWithPrevious)
oEffect.Exit = msoTrue

Next i

End With
End Sub


Sub GetfromFile()
Dim oEffect As Effect
Dim oShpB As Shape
w = 350
h = 190
l = 180
t = 300

With ActivePresentation.Slides(2)
For i = 0 To 11
file = "D:\Debprakash\4-Virginia Tech\Phd-Documents\My Algorithms and Analysis\DynamicSim\" & Trim(Str(i)) & ".png"
'MsgBox file
Set oShpB = .Shapes.AddPicture(file, msoFalse, msoCTrue, l, t, w, h)
Set oEffect = .TimeLine.MainSequence.AddEffect(oShpB, msoAnimEffectFade, msoAnimateLevelNone, msoAnimTriggerAfterPrevious)
oEffect.Timing.Speed = 0.5
oEffect.Exit = msoFalse
Set oEffect = .TimeLine.MainSequence.AddEffect(oShpB, msoAnimEffectFade, msoAnimateLevelNone, msoAnimTriggerOnPageClick)
oEffect.Timing.Speed = 0.5
oEffect.Exit = msoTrue
Next i
End With
End Sub

Sunday, June 15, 2008

Muti-list merge in Python


from heapq import heappush, heappop

alist = []

l = [('A',1),('B',2),('F',6)]
alist.append(l)

l = [('C',3),('D',4),('H',8)]
alist.append(l)

l = [('E',5),('G',7)]
alist.append(l)

#print alist


heap = []

index = 0
for lst in alist:
if lst:
item = lst.pop(0);
heappush(heap, (item, index))
index = index + 1

while heap:
ituple = heappop(heap)
item = ituple[0]
index = ituple[1]
lst = alist[index]
if lst:
newitem = lst.pop(0)
heappush(heap, (newitem, index))

print item

Tuesday, June 03, 2008

Matlab statistical commands

x, y
n=length(x)
mean(x)
std(x)
hist(x,7)
prctile(x,5)
stairs(sort(x),(1:n)/n)
normplot(x)
qqplot(x,y)
median(x)
trimmean(x)
iqr(x)
median(abs(x-median(x)))
x(random('unid',n,n,1000))
regress(y,[ones(n,1),x])
two data columns
sample size
sample mean
sample standard deviation
histogram with 7 bins
5% sample quantile
empirical cdf
normal probability plot
QQ-plot
median
10% trimmed mean
interquartile range
MAD
1000 samples resampled from x
regression line y=a+bx

Chi-square test of homogeneity and independence:


x=contingency table;
e=sum(x')'*sum(x)/sum(sum(x));
X2=(x-e).^2./e
X2=sum(sum(X2))
df=prod(size(x)-[1,1])
P=1-chi2cdf(X2,df)


More statistical commands:

matlab -> helpwin -> toolbox/stats ->
  • probability density functions
  • cumulative distribution functions
  • critical values of distribution functions
  • random number generators
  • descriptive statistics
  • linear models
  • statistical plotting

Source: http://www.math.chalmers.se/Stat/Grundutb/CTH/mve155/0708/matlab.html

Tuesday, April 15, 2008

GPL v3 License template for netbeans

Created my GPL v3 License to be used as default in Netbeans IDE
"license-default.txt"

<#if licenseFirst??>
${licenseFirst}

${licensePrefix}This program is free software; you can redistribute it and/or
${licensePrefix}modify it under the terms of the GNU General Public License as
${licensePrefix}published by the Free Software Foundation; either version 3 of the
${licensePrefix}License, or (at your option) any later version.
${licensePrefix}
${licensePrefix}This program is distributed in the hope that it will be useful, but
${licensePrefix}WITHOUT ANY WARRANTY; without even the implied warranty of
${licensePrefix}MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
${licensePrefix}General Public License for more details:
${licensePrefix}http://www.gnu.org/licenses/gpl.txt
<#if licenseLast??>
${licenseLast}



To customize per project license:
Add license-.txt to Template->License in Netbeans IDE
and add property "project.license=" to nbproject/project.properties

Monday, March 31, 2008

Samba for printing !!!

Step 1: Add smb to services
system-config-services
Add service "smb"
Check auto start, and start service

Step 2: Open port in firewall
system-config-securitylevel
Check Trusted services "Samba"

Step 3: Configure samba service
vi /etc/samba/smb.conf

[global]
workgroup =
server string = Samba Server Version %v
passdb backend = tdbsam
printcap name = cups
printing = cups
cups options = raw

[homes]
comment = Home Directories
read only = No
browseable = No

[printers]
comment = All Printers
path = /var/spool/samba
printable = Yes
lpq command = lpq -P%p
lprm command = lprm -P%p %j
use client driver = Yes
browseable = No

Step 4: Add users
use smbpasswd -a to add user to samba

More info:
http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf
http://www.samba.org/samba/docs/Samba-Guide.pdf
http://www.linuxquestions.org/questions/linux-networking-3/samba-client-access-denied-unable-to-connect-122851/

Saturday, March 29, 2008

My favorite vi settings

Add the following lines to .exrc your $HOME folder

set autoindent
set backspace=indent,eol,start
set tabstop=4
set expandtab
set shiftwidth=4
set shiftround
syntax on
set nobackup
set nowritebackup
set number

Now vi looks and feels nice.

Subversion server setup

Installing subversion server on Linux (Centos/Redhat)

Step 0. Install svn
yum install svn

Step 1: Create repository
svnadmin create

Step 2: For User Id and password: Edit /conf/svnserve.conf
and /conf/passwd
svnserve.conf:
anon-access = none
auth-access = write
password-db = passwd

Step 3: Copy "svnd" into /etc/init.d/ and
chmod 755 svnd

Step 4: Edit svnd :
Line 28: daemon $SVND -d -r

Step 5: Open port in "/etc/sysconfig/iptables" add
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3690 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 3690 -j ACCEPT

Step 6: Make sure /etc/services has the following entries
svn 3690/tcp # Subversion
svn 3690/udp # Subversion

Step 7: start/restart firewall and svnserve
/etc/init.d/iptables restart
/etc/init.d/svnd restart

Done...