Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Tuesday, April 19, 2011

Exponential decay

Suppose a quantity q of substance is emitted by something over a period of time t, and the release is an exponential decay curve, like with cooling.

The proportion of q that has been emitted by an intermediate time h will be



\frac{{}1-e^{-(h/t)}} {1-e^{-1}}

( 1 - exp(-(h/t)) ) / ( 1 - exp(-1) )

The exponent -1 in the divisor is the reduction of -(1/1).

NB that we're saying nothing about whether more substance is emitted after the quantity q has been emitted. In particular the remaining amount of substance is unlikely to be 0 because the exponential decay curve never quite meets the x axis (I think).

Monday, April 11, 2011

Javascript modulo

The Javascript % operator can return a negative result, so in JS

-2 % 7 == -2

whereas in Perl

-2 % 7 == 5

Thursday, April 7, 2011

Powershell format-table

If you supply a property hash to format-table, it will show that column and no others, unless you specify the other columns

... | format-table name,value,@{ label="name_again"; expression = {$_.Name} }

I don't understand why we have a comma separated list of columns here, I haven't seen that syntax elsewhere in PSH yet.

Tuesday, April 5, 2011

Powershell foreach-object

If you do

gci | gc | measure-object -character

you get one measurement, on all the files concatenated together.

More useful is

gci | foreach-object { gc $_.name | Measure-Object -character}

which gives a count for each one.

And more useful still is

gci | foreach-object { $_.name + "," + ( gc $_.name | Measure-Object -character ).Characters }

which shows the file names too.

You have to use the parentheses or it doesn't work at all. You have to use .Characters as otherwise you just get the parent Microsoft.PowerShell.Commands.TextMeasureInfo object. I don't understand why that doesn't happen in the second example, but there you go.

Monday, April 4, 2011

ADO/ODBC dates

If you use ADO with Perl to run database queries, datetime fields will be converted into a character representation which does not necessarily use the default style for your SQL Server installation. This will cause problems if you will be using the representation to insert back into the db.

So if $daterep contains a datetime field which has been selected from the db in this way, then

"insert into table1(datetimefield) values ('$daterep')"

may result in a conversion failure. Put an explicit conversion on the select

"select convert(datetime, datetimefield, 120) daterep"

(You could instead put a conversion on the insert, but you'd have to inspect the data and see which format it was first).

Followers

Blog Archive