2006-12-09 impresii

20:29 Fri 08/12/2006
la masa cu Diana S., Radu C., Gabriela B., Alina I. si altii. 95% din timp am discutat despre copii, si, pe deasupra, mi-a facut placere! Am imbatrinit…
La petrecerea de la firma: nu mai vazusem arteziana de ciocolata… si aveau si alba si neagra!
Nu am stat prea mult si am plecat sa vad luminile de pe Magheru.

Citeam Sfantu Asteapta de Raymond Queneau in colectia Cotidianul si nu intelegeam de ce, in acelasi timp, imi place si ma plictiseste. Apoi am inteles: este ebosa romanului un veac de singuratate de G. G. Marquez!

13:55 Sat 09/12/2006
La CityMall pentru petrecerea Minimax. Nimic interesant pentru M,  asa ca am plecat la Kids Planet-unde s-a distrat de minune

Seara am fost la saltea impreuna(imi face si mie alt tonus), iar acum, la Pro TV, “Slevin” – e a doua oara cind il vad si, ca de obicei, inteleg mai multe.

Excel si C#

Dupa ce m-am batut cu referintele COM ( care mor imediat daca e proiect consola, dar care mai traiesc daca e ASP.NET) am reusit sa implementez IDisposable peste (aproape) fiecare obiect de la Excel.
Astfel incit am un Range_Disposable care inglobeaza / deriveaza din
Range, un WorkSheet_Disposable care inglobeaza/deriveaza din Worksheet
( si la care metoda get_Range intoarce Range_Disposable).

Observatie 1.
    In proiectul consola, daca inchid Excel ( app.Quit(); Marshal.ReleaseComObject()) si am citeva Range_Disposable la care nu am aplicat Dispose, atunci app.Quit le apeleaza si pe ele.
    In proiectul ASP.NET , daca fac acelasi lucru, app.Quit da Access Denied…

Observatia 2.
    Totul se poate repara usor , folosind binecunoscutul using(Range_Disposable r = W.get_range())

2006-12-06 impresii

  1. In tramvai : “Doua servetele la 5000” – cit naiba cistiga vinzatorul asta?
  2. Cite sinecuri in RO- “grup de dialog social al guvernului” undeva linga Liceul I.L.Caragiale … Ce naiba face, practic?
  3. Catavencu si Dragos Manac au inceput sa ma enerveze cu rubrica FiatLinux

          Citate :

  • “Tineti minte asta si folositi Linux: este cel mai sigur sistem de operare”
      • Pentru utilizatorul obisnuit NU CONTEAZA care e cel mai sigur … conteaza care e cel mai EFICIENT. Tin minte ca , acum vreo 5 ani, parca, am instalat RedHat care venea pe CD de la Teora – si mi-a trebuit 1 saptamina sa configurez placa de sunet. Am fost extrem de mindru dupa aceea – si probabil ca asta-i sentimentul pe Linux :EU am reusit sa configurez. Dupa care mi-am dat seama ca in saptamina aceea puteam asculta muzica linistit – sau face orice altceva – instalind Windows in 1 ora …
      • Cine spune ca e sigur ? Pentru desktop, XP e sigur… iar pentru servere, W2003 competitioneaza de la egal la egal la securitate. Da , de acord, la pret e diferit.
  • “Sub Linux nu exista virusi”
      •  Intr-adevar, nu exista asa de multi ca la Windows- si din cauza de eficienta <hackereasca>. Daca vreodata o sa ajunga Linux la fel de folosit ca desktop ca si Windows, sunt sigur ca o sa se creeze si pentru Windows.

Nu mai am articolul de data trecuta(si nici nu am chef sa imi dau adresa de email doar ca sa consult colectia la www.catavencu.ro), cu o la fel de mare idiosincrazie fata de Windows.Ma rog, parerea lui … Stau sa ma gindesc daca nu ar trebui sa fac un contraeditorial la fiecare editorial al lui
Altfel, blog-ul lui e interesant

 

Dilema veche si politetea

Nu am reusit sa iau Dilema vineri (se terminase peste tot!)- dar azi am facut rost de ea.
Incepe super cu citatul de pe coperta:
Politeţea e ca o pernă umplută cu aer, nu are nimic înăuntru, dar amortizează şocurile.“ – MARK TWAIN

Apoi e plina – PLINA ! – de articole super:
Mircea Dinescu despre “bulz de mămăligă cu feta şi bacon”
Mircea Vasilescu despre irelevanta UE
Lucian Mandruta cu un articol superb despre Carti -dar as vrea sa ii spun ca nu toate cartile sunt romane
Sever Voinescu despre optiunile Americii in Irak : Go Big, Go Long si Go Home, ca si despre sfatul “pe care marele profesor de actorie, Lee Strasberg, îl dădea unuia
dintre cei mai celebri elevi ai săi, Al Pacino. „Uneori, nu merge atît
de departe pe cît ştii că poţi să mergi!“ ” aplicat la situatia Americii
Nora Iuga:
“virtuţile morale şi cele estetice se bat între ele ca familiile Capulet
şi Montagu, iar o mare iubire între progeniturile lor apare foarte rar
şi sfîrşeşte totdeauna prost”
“Ştiu, dintr-o îndelungată experienţă, şi aici nu încape nici o
metaforă, că nu ţi se îndeplineşte decît ceea ce-ţi visezi cel mai mult.”
Mihaela Miroiu care cade in pacatul tuturor feministelor
“Asta e problema pe care o pun feministele: de ce îmi dai voie să intru
prima pe uşă şi la nici una din uşile de decizie, resurse şi putere
nu-mi permiţi să intru”
CINE nu va lasa? exemple, please… caci contra exemple( de la Tatoiu la orice  Columbeanu exista destule)
ca si despre exagerarile lor
“Ei bine, cele care erau activiste s-au supărat îngrozitor pe mine că
miroseam a parfum franţuzesc. Şi au avut o reacţie aproape brutală:
„Cum, tu zici că eşti feministă şi te dai cu parfum?“. Şi le-am spus:
„Plecăm din frustraţii diferite. Eu vin dintr-o societate în care
accesul la minimele ingrediente care să te facă să trăieşti cu plăcere
a fost atît de limitat, încît de-abia am aşteptat să mă spăl cu un
săpun bun sau să folosesc un parfum bun“. Nu venim din acelaşi context,
nu putem fi tulburate de aceleaşi obsesii.” … Deci, daca era in acelasi context… era justificata obsesia???
( ma rog, pe urma adauga
“Şi, în fond, nu te dai cu parfum, ca femeie, să faci neapărat plăcere bărbaţilor, ci în primul rînd să te simţi tu însăţi bine.
” – deci isi da seama ca treaba cu contextul e falsa…)

M-a impresionat articolul despre Iulius Mall din Timisoara… trebuie sa il vad .

Andrei Manolescu
despre ipocrizia politicienilor – dar sfirseste intr-o nota pe care , din pacate, nu o inteleg:
Filozoful francez Denis de Rougemont spunea, la mijlocul secolului
trecut, că „pretutindeni unde unei pisici i se spune pisică, răul dă
înapoi“. Acum probabil că deja lucrurile au evoluat şi trebuie să fim
atenţi dacă nu cumva cine spune pisicii pe nume, nu e de fapt un cîine.

1. Chiar daca e ciine , e normal sa i se spuna pisicii pe nume
2. Denis de R. se intelege bine cu Orwell – care spunea ca libertatea pleaca de la 2+2=4

Neaparat de citit Hans-Werner SINN ,Viitorul statului asistenţial

Angajatorii nu sînt nişte altruişti. Ei angajează o persoană numai dacă
aceasta produce un surplus faţă de costul său şi dacă acest surplus nu
este mai mic decît surplusul pe care l-ar putea crea un muncitor din
altă ţară, sau o maşină. Iar angajaţii nu sînt proşti. Ei acceptă o
slujbă numai dacă vor cîştiga mai mult decît ajutorul social oferit de
stat. De aceea, angajaţii care nu sînt destul de productivi vor deveni
şomeri.

Sistemul european de asistenţă socială, bazat pe ajutor social şi salariu minim, nu va supravieţui globalizării.

Neaparat cititi TOT articolul : http://www.dilemaveche.ro/index.php?nr=149&cmd=articol&id=4483

Si last, but not least 3,14
„Nu te-ntreb cum ai făcut primul milion, ci cînd ai de gînd să-l faci.
La Bursă ţi-ar fi simplu“ – ne spune, sigur pe el, prezentatorul unei
emisiuni financiare, într-un promo la Realitatea TV. Păi, dacă e aşa de
simplu, de ce nu-l face el însuşi şi-şi pierde vremea prezentînd
emisiuni? (C. P.-B.)

Probabil ca asa si-l face el 😉

2006-12-05 impresii

Munca la servici – am inceput sa ma obisnuiesc sa fac vreo 3 proiecte in paralel…

Am fost cu M la Mall – si m-a impresionat imaginea miscatoare( pe baza de umbra ) de pe podea.
Cel mai mult mi-a placut mingea in care poti sa “dai” cu piciorul – iata imaginea aici

PK Dick – furnica electrica

18:17 Mon 04/12/2006
P.K. Dick este preferatul meu in materie de SF care pune intrebarea: Ce este realitatea?
Ubik este superba, dar si nuvelele sunt superbe.
Impostorul- simpla si de efect
Varianta a doua- nu lasa oamenilor nici o sansa, dar finalul e usor de anticipat.
Raport minoritar- nu pune problema in profunzime
Un joc de razboi- despre importanta de a citi instructiunile( desi neverosimila)
Ce spun mortii- o ebosa a lui UBIK
Ah, sa fii gelat- despre viata , dragoste si afaceri a gelato-oamenilor
Amintiri garantate – despre dorintele deja realizate
Credinta parintilor nostri –  o descriere superba a comunismului
Furnica electrica – despre conditia umana de receptacul

Daca v-a placut Ubik, or sa va placa si astea…

Part 4 : .NET programming

If you have
not read yet the first parts, please found them here: Part
1
, Part
2
and Part
3

 

 

Now we have
the Access database on the C:\Book\BookData – and the dll to load data is on
the C:\Book\BookObjects.

We will
create a Windows Forms project to see the data that is in the MDB file.

Right click
on the solution -and choose: Add => New Project => and choose Windows
Application. Put the name
BookWin. A new form is created for you by
default.

Change the name from Form1 to frmPublisherList.cs, double
click on the file, press F4 to bring Properties window up front and change the
Text from Form1 to List of Publishers.

Now we must tell to the windows project to use the objects
project that we created earlier. Right click BookWin project in the Solution
Explorer, click „Add reference” and go to the Projects tab on the next window.
Double Click the BookObjects project.Compile(CTRL+SHIFT+B).

 

I must
found a way to copy the MDB in the same location as the executable, in order
that the path can function easily even the application will be deployed in
other paths. (Not every user will easily agree to deploy the application on the
same path as we do, C:\Book – maybe he wants to install in other places).

The
solution to be always in sync is to perform the copy automatically and
precisely when the build is complete.

Right click
on BookWin project from Solution Explorer, select properties (or find in menu
Project => Book Project Properties)

On the
“build events“tab you have a pre and a post build event command line

We will
wrote this code in the post build

copy
$(ProjectDir)..\BookData\*.mdb $(TargetDir)

That means
copy all MDB files from the following dir C:\Book\BookData (obtained as
following from the project dir (C:\Book\BookObjects\), the up (C:\Book\), the
to BookData (C:\Book\BookData)) to TargetDir (does no matter if debug or release)

Save and compile
(CTRL + SHIFT + B)

Now in the
C:\Book\BookObjects\bin\Release or in the C:\Book\BookObjects\bin\Debug must be
another copy of the MDB file.

Very good *
let’s write now the connection to the MDB. Right Click on BookWin in the Solution
Explorer – click Add => New Item => and choose “Application Configuration
File” ( default name :App.config – do not change this!) and put the following
lines:

<?xml version=“1.0“ encoding=“utf-8“ ?>

<configuration>

<appSettings>

<add
key=“DatabaseUsed“ value=“MDB“/>

<!– possible values : MDB, SQLServer–>

</appSettings>

<connectionStrings>

<add
name=“MDB“ connectionString=“Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\book.mdb;User Id=admin;Password=;
“/>

<!– TODO : add for asp.net application the connection string with SQL Server–>

</connectionStrings>

</configuration>

Now it’s
the moment to load the records. We put code in the settings.cs file to be able
to switch connection at run-time:

public static DbConnection TheConnection

{

get

{

switch
(TheDatabase)

{

case
DatabaseUsed.MDB:

OleDbConnection oc = new OleDbConnection(ConnectionStringMDB);

return oc;

case
DatabaseUsed.SQLServer:

SqlConnection sc=new SqlConnection(ConnectionStringSQLServer);

return sc;

default:

// Maybe throw an error that config file has not been initialized with

// the database type ?

return null;

}

}

}

 

And to load Records:

public static IDataReader

Load(string CommandLine, DbConnection dbcon)

{

 

if

(!(dbcon.State == ConnectionState.Open))

dbcon.Open();

 

DbCommand
dc = null;

switch
(TheDatabase)

{

case
DatabaseUsed.MDB:

dc = new OleDbCommand(CommandLine);

break;

case

DatabaseUsed.SQLServer:

dc = new SqlCommand(CommandLine);

break;

default:

//TODO
: throw specific error that database type does not properly have been initialized

break;

}

dc.CommandType = CommandType.Text;

dc.Connection = dbcon;

return
dc.ExecuteReader();

 

return
null;

 

 

}

 

 

As you see,
we return a
DbConnection no matter we use the OleDbConnection
or
SqlConnection .

Now let’s fill
in the Load code in the ColPublisher file:

using System;

using
System.Collections.Generic;

using
System.Text;

using

System.Data;

using
System.Data.Common;

 

namespace
BookObjects

{

public class ColPublisher :
System.Collections.ObjectModel.KeyedCollection<string,Publisher>

{

protected
override string
GetKeyForItem(Publisher item)

{

return
“K” + item.IDPublisher;

}

public void Load()

{

DbConnection
db = Settings.TheConnection;

using
(db)

{

db.Open();

IDataReader
ir = Settings.Load(“select
IDPublisher, NamePublisher, SitePublisher from Publisher”
, db);

while
(ir.Read())

{

Publisher
p = new Publisher();

p.FillObject(ir);

//TODO : add p into the
collection

}

}

}

 

}

}

 

We realize
now that the
ColPublisher is not a collection where to add the new
publisher p. Fortunately, the .NET collection is enough big to contain many
collection.

Just look
into the
System.Collections namespace, then into System.Collections.ObjectModel and into System.Collections.Specialized. You will find many more on the net

( for example, an implementation of a Set collection : http://www.codeproject.com/csharp/sets.asp)

We will
derive the
ColPublisher from the System.Collections.ObjectModel.KeyedCollection<string,Publisher> .We must wrote how to generate the key for a specific Publisher -and what Key is better than the ID ?

protected override string
GetKeyForItem(Publisher item)

{

return
“K” + item.IDPublisher;

}

 

Now we can
wrote the
Load method
properly :

using System;

using
System.Collections.Generic;

using
System.Text;

using

System.Data;

using
System.Data.Common;

 

namespace
BookObjects

{

public class ColPublisher :
System.Collections.ObjectModel.KeyedCollection<string,Publisher>

{

protected
override string
GetKeyForItem(Publisher item)

{

return
“K” + item.IDPublisher;

}

public void Load()

{

DbConnection
db = Settings.TheConnection;

using
(db)

{

db.Open();

IDataReader
ir = Settings.Load(“select
IDPublisher, NamePublisher, SitePublisher from Publisher”
, db);

while
(ir.Read())

{

Publisher
p = new Publisher();

p.FillObject(ir);

this.Add(p);

}

}

}

 

}

}

 

And use it
from the Form :

Double
click on the frmPublisherList.cs and drag a DataGridView to the form

 

Now configure
the data source:

 

Click on “(none)”
and select “add new data source”

In the next
dialog, choose “Object”





 

and press
next.

Now expand the
BookObjects node and choose “ColPublisher”. Press Next and then Finish.

To the form
is a new control added: colPublisherBindingSource – and the Grid has already the columns defined.

Now wrote
the data to load the data from the database:

Double click
on form, and you will find yourself in the Form_Load event :

private void frmPublisherList_Load(object

sender, EventArgs e)

{

BookObjects.ColPublisher publishers = new

BookObjects.ColPublisher();

publishers.Load();


colPublisherBindingSource.DataSource = publishers;

}

 

Now the
results – right click on BookWin – and select “Set as startup project”

Now press F5
* and wait to see the results. If the best case, you will see a form with no
data at all – and this is very correct – because of the fact that are no items
in the Book.mdb

 

In the next
lesson we will wrote code to do insert of a new Publisher and viewing him on
the form ( finally!)

 

Recommended
readings:

CSLA : http://www.lhotka.net/cslanet/ – a good framework to handle all the security,
scalability , binding and other issues ( and, most of all, free).

 

 




 

 

 

 

Linkuri de programare

Stroustroup despre C++:
I think I know more about the problems with C++ than just about anyone,
but I also know how to avoid them and how to use C++’s strengths.
(Exact ce obisnuiesc sa spun si eu despre VB 😉 )

Despre programare la MS

When investigating a piece of code the developer first turns to the code itself: on average
respondents to the survey spent 42% of the time examining the source code, 20% using the
debugger, 16% examining check-in comments or version diffs, 9% examining the results, 8%
using debug or trace statements, and 5% using other means. In other words, the code itself is the
best source of information about the code. However it is not flawless. It is common for
developers to become disoriented in source code, and it is often difficult to discern the
relationships between observed behavior and the source code.

When the code itself does not give the answers the developer needs, one might expect them to
turn next to the vast amount of information that’s written about it – the bug reports, the specs, the design documents, the emails, etc. This however is emphatically not the case.

The second recourse for investigating the rationale behind code is in fact the social network. If
the developer thinks that someone within his team might be able to provide the needed
information (or the name of the person who might), he will walk down the hall to talk with the
teammate. Unplanned, face-to-face meetings happen frequently with teammates, averaging 8.4 in
the prior week, and much less frequently with non-teammates, averaging 2.6. Email is used
instead of face-to-face meetings when the issue is low priority, involves multiple people, or
crosses the team moat, averaging 16.1 sent to teammates in the prior week and 5.9 to nonteammates.
(Note that these data show that communication within the team is much more
common than communication across teams, indicating that the culture of informal communication
works well and that the team boundaries are typically drawn in the right places.)
Once the developer has the desired information, he returns to his office, applies the newfound
information, and gets on with his work. This information is precious: it is demonstrably useful,
demonstrably hard to ascertain from the code, and was obtained at a high cost. Yet it is
exceedingly rare for the developer to write this morsel down anywhere
. The next person who encounters the same information need has to go through the same laborious discovery process. There are plenty of reasons that a developer would choose to not record the information – the overhead of checking the code out, editing it, and checking it back in (possibly triggering checkin review processes, merge conflicts, test suite runs, etc.) is enough to dissuade the developer from recording the information as a comment in the code. But the loss of this precious knowledge is, from an organizational perspective, a crying shame.

De ce am impresia ca asta se intimpla peste tot? Doar ca am intilnit-o si eu ?…