Pages

Monday, November 16, 2015

Prism 6 is open source!

Prism 6 is open source! You can get the source code from github.

Resources:

patterns & practices: Prism, https://compositewpf.codeplex.com/
Prism grows up, http://blogs.msdn.com/b/dotnet/archive/2015/03/19/prism-grows-up.aspx

Friday, November 06, 2015

My Friday's links


Programming



What makes a cool URI?
 A cool URI is one which does not change.
 What sorts of URI change?
URIs don't change: people change them.





I discovered the links above by reading the book Pro Asp.Net MVC 4 By Adam Freeman
( http://www.apress.com/9781430265290 )


Programmers


  • Programmers: Stop Calling Yourselves Engineers

( http://www.theatlantic.com/technology/archive/2015/11/programmers-should-not-call-themselves-engineers/414271/ )

Wednesday, October 28, 2015

Obtinerea adresei IP in formatul standard dintr-un numar intreg

Calcularea adresei IP în formatul IPv4 dintr-un număr întreg pe o platforma little endian.


long IP = 3232679515;

byte[] bytes = new byte[4];


bytes[0] = (byte)((IP >> 0) & 0xFF);
bytes[1] = (byte)((IP >> 8) & 0xFF);
bytes[2] = (byte)((IP >> 16) & 0xFF);
bytes[3] = (byte)((IP >> 24) & 0xFF);

// all of the protocol layers in the TCP/IP suite are defined
// to be big endian
string ipText = bytes.Select(b => b.ToString())
 .Aggregate((ip, b) => (ip.Length == 0) ? b : ip + "." + b);

Console.WriteLine(ipText); // prints 91.198.174.192


Bineînțeles că nu trebuie să ne chinuim atât de mult să obținem o adresă IP dintr-un long. În .net există clasa IPAddress care reprezintă o adresa IP și furnizează diferite proprietăți și metode utile:


System.Net.IPAddress ip = new System.Net.IPAddress(3232679515);
Console.WriteLine(ip.ToString()); // prints 91.198.174.192


Am citit despre:
Big-Endian vs. Little Endian: Endianness Explained, http://www.barrgroup.com/Embedded-Systems/How-To/Big-Endian-Little-Endian


Referințe:
MSDN, https://msdn.microsoft.com/en-us/library/system.net.ipaddress(v=vs.110).aspx
Understanding IP Addresses, Subnets, and CIDR Notation for Networking, https://www.digitalocean.com/community/tutorials/understanding-ip-addresses-subnets-and-cidr-notation-for-networking

Tuesday, October 27, 2015

Ce am mai invatat astazi



1. Ștergerea fișierelor dintr-un repository git.


Am făcut lucrul ăsta de mai multe ori dar nu atât de des încât sa țin minte comanda :).

În exemplul următor, comanda va șterge din directorul curent, în mod recursiv, fișierele compilate python (*.pyc) .


1
git rm -r \*.pyc




2. Cum să faci scroll într-un panel tmux


Folosind combinația de taste Ctrl-b [ se intra în modul "scroll". În acest mod se pot folosi săgețile și tastele PgUp (Page Up) si PgDn (Page Down). Pentru a ieși din acest mod trebuie apăsata tasta q

3. Cum poti folosi mouse-ul pentru a modifica marimea panelurilor in tmux


Se adăuga în fișierul de configurare a tmux, ~/.tmux.conf, următoarea linie


1
set -g mouse on

4. Tagul HTML (HTML Keyboard Input Element)

Reprezinta input de la tastatura si produce un element "în linie" (inline) ce va fi afișat de către browser cu un font monospace. Elementului ii poate fi adăugat un stil folosind css.

<kbd>Ctrl</kbd>

Rezultat

Ctrl


Referințe:

https://git-scm.com/docs/git-rm
http://superuser.com/questions/209437/how-do-i-scroll-in-tmux
http://stackoverflow.com/questions/30185210/ubuntu-change-tmux-1-8-to-tmux-next-1-9
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/kbd

Monday, October 26, 2015

The sp_configure value 'contained database authentication' must be set to 1 in order to create a contained database.

Acum cateva zile a trebuit sa-mi reinstalat sistemul de operare dupa un upgrade nereusit la windows 10.

Cu cateva zile inainte de toata nebunia asta cu reinstalarea sistemului, incepusem lucrul la un proiect in care foloseam ca server de baze de date SQL 2014 Express LocalDB. Nu am mai lucrat pana acum cu LocalDB deoarece intotdeauna am la indemana o instanta de SQL Server Developer Edition. La acest proiect am dorit sa incerc si aceasta versiune.

Dupa reinstalarea sistemului de operare si o parte a programelor necesare dezvoltarii de aplicatii, am deschis proiectul la care lucram in Visual Studio si, din panelul "Server Explorer", am incercat sa atasez baza de date (fisier mdf) la LocalDB . Din pacate am obtinut urmatoarea eroare:

The sp_configure value 'contained database authentication' must be set to 1 in order to create a contained database. You may need to use RECONFIGURE to set the value_in_use. An attempt to attach an auto-named database for file failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Ce mai este si acest 'contained database authentication'?

Am cautat pe Google.. si asa am aflat de existenta acestor 'contained databases', baze de date ce sunt izolate fata de celelalte baze de date si de instanta SQL Server care le gazduieste.

SQL Server realizeaza aceasta izolare in 4 moduri:
- mare parte din metadatele ce descriu baza de date sunt mentinute in baza de date si nu in baza de date master
- toate metadatele folosesc aceleasi tip de interclasare ("collation")
- autentificarea este facuta de baza de date reducand astfel dependenta de "login"-urile definite in instanta SQL Server
- mediul SQL Server (DMV-urile, XEvent-urile etc) raporteaza si poate actiona asupra informatiilor izolate.

Acest tip de baze de date a aparut incepand cu versiunea 11 a SQL Server (SQL Server 2012). Mai multe detalii despre 'contained databases' se pot gasi pe MSDN, vezi Referinte

Eroare mea s-a rezolvat executand urmatoarele instructiuni:


1
2
3
4
sp_configure 'contained database authentication', 1;
GO
RECONFIGURE;
GO


Instructiunile de mai sus le-am executat din panelul SQL Server Object Explorer => Selectare instanta LocalDb => New Query...

Dupa rularea instructiunilor de mai sus, baza de date a fost atasata fara probleme la instanta LocalDB.


Referinte: 


MSDN - Contained databases: https://msdn.microsoft.com/en-us/library/ff929071.aspx
MSDN - Contained database authentication Server Configuration Option: https://technet.microsoft.com/en-us/library/ff929237.aspx
SQL Server Portal, SQL SERVER 2012 – Fix – Error – 12824 – The sp_configure value ‘contained database authentication’ must be set to 1: http://raresql.com/tag/the-sp_configure-value-contained-database-authentication-must-be-set-to-1-in-order-to-s_msg-a-contained-database-you-may-need-to-use-reconfigure-to-set-the-value_in_use/

Thursday, September 03, 2015

Javacript, python si c# si operatia de impartire a numerelor intregi

În Python 2.7 găsesc supărător faptul ca împărțirea a doua numere întregi are ca rezultat tot un număr întreg chiar dacă împărțirea celor două numere nu este exactă. De la un limbaj dinamic m-aș fi așteptat să obțin un număr real, precum în Javascript:


C:\Users\>Daniel>node
> var a = 10;
undefined
> var b=3;
undefined
> a/b
3.3333333333333335

Javascript, intern, are doar singur tip de reprezentare a numerelor, 64-bit virgula mobila, acelasi cu double din c#.

Python în schimb suportă și tipul integer. Rezultatul împărțirii a doua numere întregi în Python 2.7 este întotdeauna un număr întreg:

In [1]: a = 10
In [2]: b = 3
In [3]: a/b
Out[3]: 3

Pentru a pentru a obține rezultatul corect trebuie sa convertim unul din operatori la tipul float.

In [5]: a/float(b)
Out[5]: 3.3333333333333335

Python 3 nu are această problemă, rezultatul împărțirii în astfel de cazuri fiind un număr real (true division).

Putem folosi și în Python2.7 operația de diviziune din Python 3  cu un import din __future__:

In [1]: from __future__ import division
In [2]: a = 10
In [3]: b = 3
In [4]: a/b
Out[4]: 3.33333333333333355


În C#, rezultatul împărțirii a doua numere întregi este tot un număr întreg, rezultat care nu ridică întrebări având în vedere faptul ca limbajul este static.


1
2
3
4
int a = 10;
int b = 3;

Console.WriteLine(a/b); // prints 3

Result: 3


REFERENCES:

- Python 2.7 Documentation, https://docs.python.org/2.7/library/stdtypes.html#numeric-types-int-float-long-complex
- Python 3.4 Documentation, https://docs.python.org/3.4/library/stdtypes.html#numeric-types-int-float-complex
- MDN, Numbers, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates
- How can I force division to be floating point in Python? http://stackoverflow.com/questions/1267869/how-can-i-force-division-to-be-floating-point-in-python
- Learning Python de Mark Lutz. Capitolul 5, Numeric Types
- Javascript: the Good Parts de Douglas Crockford. Capitolul 2. Grammar
- C# 5.0 in a Nutshell de Joe Albahari, capitolul 2 Numeric Types


Friday, June 26, 2009

An easy way to check if a number is odd or even

Using the bitwise operator AND you can check if a number is odd or even.

private bool IsOdd(int i)
{
return (i&1==1);
}


If the function IsOdd() returns true then the number is odd otherwise, the number is even.

I posted this entry in my new blog at http://www.elgrillo.eu/blog. The new blog is about programming.

Monday, September 03, 2007

From Dave Obajano blog:
"The funny thing about a lot of the people who claim to be 'Enterprise Architects' is that I've come to realize that they tend to seek complex solutions to relatively simple problems. How else do you explain the fact that web sites that serve millions of people a day and do billions of dollars in business a year like Amazon and Yahoo are using scripting languages like PHP and approaches based on REST to solve the problem of building distributed applications while you see these 'enterprise architect' telling us that you need complex WS-* technologies and expensive toolkits to build distributed applications for your business which has less issues to deal with than the Amazons and Yahoos of this world? .."
An interesting point of view about enterprise development is here on James McGovern blog entry More Thoughts on Ruby and Why it isn't enterprise ready! I don't know now if he has right or not I have to read the article carefully. But I tend to give him right, because at the enterprise level the managers are so conservative and nobody has time to evaluate and try new technologies , tools etc. if they are not sure (??) they have a profit.
They simple do not take the risk.

David Heinemeier Hansson replies "Boy, is James McGovern enterprise or what!" .

Thursday, April 19, 2007

Php, Firefox and IIS - Authentication Required message for localhost sites

I had some trouble trying to run some php scripts located on an virtual site located on a different place than the default root site of iis (c:\inetpub\wwwroot). In my case the scripts where located on d:\sites.
What I found is that I have to set the doc_root setting of the php.ini file to d:\sites
;doc_root = "c:\inetpub\wwwroot"

doc_root = "d:\sites"

Now the php script run very well on internet explorer but accessing the script with firefox browser give me an Authentication Required message box asking me to enter an user name and a password. To address this issue I googled here and there and I found that I have to configure Firefox by setting the network.automatic-ntlm-auth.trusted-uris entry of the about:config file to value localhost
Further reference:
http://en.wikipedia.org/wiki/NTLM
http://www.mozilla.org/projects/netlib/integrated-auth.html
http://www.crossedconnections.org/w/?p=89

Reference equality, bitwise equality and value equality

Reference equality means the object references that are compared refer to the same object.

Bitwise equality means the objects that are compared have the same binary representation.

Value equality means the compared objects have the same value even though they have different binary representations. For example, consider two Decimal objects that represent the numbers 1.10 and 1.1000. The Decimal objects do not have bitwise equality because they have different binary representations to account for the different number of trailing zeroes. However, the objects have value equality because the numbers 1.10 and 1.1000 are considered equal for comparison purposes since the trailing zeroes are insignificant.

Further reference : http://msdn2.microsoft.com/en-us/library/bsc2ak47.aspx

How to compare two fonts in .Net

Which of the two folowing expressions to use when you want to compare two fonts?
a) if (fontA == fontB)
b) if (fontA.Equals(fontB)

Answer
if you want to check whether the fonts have the same family font, same size, same style etc. use the first expression, (a) :
if (fontA.Equals(fontB)
if you want to compare if the reference of the fontA is the same as the reference of the fontB use the second expression, (b):
if(fontA == fontB) or the equivalent expression if ( Font.Equals(fontA, fontB) )

Further reference http://msdn2.microsoft.com/en-us/library/w4hkze5k.aspx

Thursday, April 12, 2007

XML CDATA

Astazi m-am lovit de urmatoarea problema: parsarea unui text in format xml de catre functia OPENXML intr-o declaratie T-SQL nu pastreaza spatiile la stanga si la dreapta ale textului dintre tagurile unui element.

De exemplu daca am

<separator>  -  </separator>

dupa parsare voi avea valoarea "-" pentru elementul .

Am descoperit ca pentru a pastra spatiile, trebuie sa introduc textul intr-o sectiune xml CDATA ( http://www.w3schools.com/xml/xml_cdata.asp) ca in exemplul de mai jos:

<separator><![CDATA[ - ]]></separator>
Asadar textul format xml va trebui sa-l construiesc astfel in .Net

xml.AppendFormat("
<separator><![CDATA[ - ]]></separator>>", separator);

Saturday, August 05, 2006

Whether and if

Doua cuvinte, conjunctii, care se traduc prin "daca" dar in engleza au sensuri diferite. Ma gandesc cat de mult folosesc if si cat de putin whether. Oare cate greseli am facut in vorbire si in scriere datorita vocabularului sarac si a necunoasterii sensului cuvintelor?

Definitia lui whether (1):
I. conj. dacă (însă nu condiţional) do you know ~ he's here? stii cumva daca este aici ? she wondered ~ to come se intreba daca e cazul sa vina; it was uncertain ~ he would take the floor nu era sigur daca va lua cuvantul (sau nu); she worried about ~ she had hurt his feelings se intreba mereu daca nu (cumva) l-a jignit; ~ whether by accident or design intamplator sau nu/intentionat/cu buna stiinta; ~ or not/no daca este asa sau nu; I am not interesed in ~ you approved or not nu ma intereseaza/putin ma intereseaza daca esti de acord sau nu (cu aceasta); ~ she comes or not we shall leave indiferent daca vine sau nu, noi o sa plecam; this is what I think, ~ right or wrong fie ca am sau nu (am) dreptate, asta este ceea ce gandesc/cred.
II. pr inv 1.interog. care (din doi) ~ is lighter, oil or water? care este mai usor, untdelemnul sau apa? 2. nehot. oricare din doi
III. adj. interogativ - inv care sau pe care (anume); ~ room do you prefer ? ce camera preferati (din mai multe)?

(1).Leon Levitchi, Andrei Bantas Teora 95

Tuesday, January 24, 2006

Am facut ce am facut si pana la urma am instalat Ruby. Va trebui sa aleg intre Python si Ruby. M-am mai gandit si mi-am dat seama ca trebuie sa cunosc bine un limbaj dinamic pentru a crea prototipuri intr-un timp scurt, pentru crearea unor mici scripturi etc. Acest limbaj trebuie sa fie un limbaj general, util pentru administrarea retelelor, bazelor de date, creare aplicatii web etc., limbajul  sa fie bine documentat si sa pot gasi exemple de cod.
JPython, Iron Python, Boo, Nemerle .. oare ar fi bine sa ma specializez pe un framework ..? Mi se pare o prostie sa scriu cod pe care il pot scrie foarte usor in C#, in Boo sau Nemerle de exemplu.. Care ar fi avantajul de a mai invata un limbaj cand folosesti acelasi framework? In loc sa scriu Console.WriteLine sa scriu print ? Nu stiu, trebuie sa ma gandesc bine.

Monday, January 23, 2006

Ruby ???

Zilnic imi pierd timpul cu tot felulul de tampenii. Nu ma pot concetra deloc. Sunt ingrozitor !!
Aseara am citit cateva articole despre Ruby, Ruby On Rails. Numai lucruri bune n-am ce sa zic. Totusi ceva indoieli am de cand am citit intr-unul din blog-urile lui Bruce Eckel ca nu ar fi totusi superior limbajului Python (Thinking in Ruby... not sau in Ruby is bad Python, but good Perl ). Curiozitatea insa ma macina.. Daca n
u am reusit sa invat Python din lipsa de timp, de ce cred ca putinul timp pe care il am il pot irosi pe Ruby? De ce nu incerc sa imi reamintesc limbajul Perl? Perl aproape ca l-am uitat. Nu stiu daca mai sunt capabil sa scriu 20 de linii de cod fara ajutor-ul documentatiei in Perl. De ce sa nu ma specializez in C# si .Net platforma pe care lucrez curent si sa-mi pierd timpul cu Ruby on Rails sau Java ? De ce? La ce imi ajuta Haskell cand uit sa programez in C++ pe zi ce trece?
Trebuie sa imi pun in ordine prioritatile. Sa renunt la balast si sa ma concentrez la ce e important ca sa pot merge inainte. Important este sa fac ceva. Daca nu reusesc sa creez nimic si imi pierd vremea cautand sfantul gral al limbajelor de programare, o sa esuez.

Friday, December 23, 2005

Planuri de viitor

Astazi am fost extrem de obosit, nu m-am putut concentra deloc la serviciu.
Ma tot gandesc cum sa incep o afacere.. Dar inca nu stiu ce vreau sa fac si nici cum. As vrea sa pornesc o afacere in industria IT dar imi trebuie un proiect cu care sa incep. Si imi trebuie TIMP.

Tehnologii... .Net, Java, Python nu ma pot hotara, ASP.Net, PHP , Window, Linux, Crossplatform. Cum sa incep ?

De ce imi este frica sa incep cu tehnologii scumpe ?
Ma gandesc ca imi va fi greu sa reusesc. Sunt sute de companii care fac lucrul asta. Daca ar trebui sa fac legal totul m-ar ucide costul uneltelor de dezvoltare.
Pentru a reusi am nevoie de un proiect mic sa fac ceva ce nu fac altii sau, ceva ce fac altii dar eu sa fac mai bine.
Ma gandesc ca sunt si incepator in domeniul asta. Nu sunt prost, dar am inceput tarziu si nu stiu inca multe lucruri.Stiu insa ca am putere de munca.

Tuesday, September 27, 2005

At last I know what duck typing is..

Now I know what duck typing means “If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck”.

Resources:
Duck test, https://en.wikipedia.org/wiki/Duck_test

Thursday, September 22, 2005

Must read book

I have to buy the following book: Framework Design Guidelines :Conventions, Idioms, and Patterns for Reusable .NET Libraries (Microsoft Net Development Series) (Hardcover)