[SEMI-OT] How to Shoot Yourself in the Foot in Any Programming Language

The proliferation of modern programming languages (all of which seem to have stolen countless features from one another) sometimes makes it difficult to remember what language you’re currently using. This guide is offered as a public service to help programmers who find themselves in such dilemmas.

C
You shoot yourself in the foot.
C++
You accidentally create a dozen clones of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can’t tell which are bitwise copies and which are just pointing at others and saying, “That’s me, over there.”
JAVA
After importing java.awt.right.foot.* and java.awt.gun.right.hand.*, and writing the classes and methods of those classes needed, you’ve forgotten what the hell you’re doing.
Ruby
Your foot is ready to be shot in roughly five minutes, but you just can’t find anywhere to shoot it.
PHP
You shoot yourself in the foot with a gun made with pieces from 300 other guns.
ASP.NET
Find a gun, it falls apart. Put it back together, it falls apart again. You try using the .GUN Framework, it falls apart. You stab yourself in the foot instead.
SQL
SELECT @ammo:=bullet FROM gun WHERE trigger = ‘PULLED’;
INSERT INTO leg (foot) VALUES (@ammo);
Perl
You shoot yourself in the foot, but nobody can understand how you did it. Six months later, neither can you.
Javascript
You’ve perfected a robust, rich user experience for shooting yourself in the foot. You then find that bullets are disabled on your gun.
CSS
You shoot your right foot with one hand, then switch hands to shoot your left foot but you realize that the gun has turned into a banana.
FORTRAN
You shoot yourself in each toe, iteratively, until you run out of toes, then you read in the next foot and repeat. If you run out of bullets, you continue anyway because you have no exception-handling ability.
Modula2
After realizing that you can’t actually accomplish anything in this language, you shoot yourself in the head.
COBOL
Using a COLT 45 HANDGUN, AIM gun at LEG.FOOT, THEN place ARM.HAND.FINGER. on HANDGUN.TRIGGER and SQUEEZE. THEN return HANDGUN to HOLSTER. CHECK whether shoelace needs to be retied.
LISP
You shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds ….
BASIC
Shoot yourself in the foot with a water pistol. On big systems, continue until entire lower body is waterlogged.
FORTH
Foot in yourself shoot.
APL
You shoot yourself in the foot, then spend all day figuring out how to do it in fewer characters.
Pascal
The compiler won’t let you shoot yourself in the foot.
SNOBOL
If you succeed, shoot yourself in the left foot.
If you fail, shoot yourself in the right foot.
Concurrent Euclid
You shoot yourself in somebody else’s foot.
HyperTalk
Put the first bullet of the gun into the foot of the left leg of you.
Answer the result.
Motif
You spend days writing a UIL description of your foot, the trajectory, the bullet, and the intricate scrollwork on the ivory handles of the gun. When you finally get around to pulling the trigger, the gun jams.

Unix
% ls
foot.c foot.h foot.o toe.c toe.o
% rm * .o
rm: .o: No such file or directory
% ls
%
Paradox
Not only can you shoot yourself in the foot, your users can too.
Revelation
You’ll be able to shoot yourself in the foot just as soon as you figure out what all these bullets are for.
Visual Basic
You’ll shoot yourself in the foot, but you’ll have so much fun doing it that you won’t care.
Prolog
You tell your program you want to be shot in the foot. The program figures out how to do it, but the syntax doesn’t allow it to explain.
Ada
After correctly packaging your foot, you attempt to concurrently load the gun, pull the trigger, scream and shoot yourself in the foot. When you try, however, you discover that your foot is of the wrong type.
Assembly
You try to shoot yourself in the foot only to discover you must first reinvent the gun, the bullet, and your foot. After that’s done, you pull the trigger, the gun beeps several times, then crashes.
370 JCL
You send your foot down to MIS with a 4000-page document explaining how you want it to be shot. Three years later, your foot comes back deep-fried.
Python
You try to shoot yourself in the foot but you just keep hitting the whitespace between your toes.

Tag di Technorati: ,

Abilitare applicazioni del Framework 4 a lavorare con IIS6

Se non vi girano i vostri servizi scritti con il .NET Framework 4 sotto IIS6, probabilmente la .NET 4 ASP.NET ISAPI extension è disabilitata.

Per abilitarla dovete “solo” lanciare il seguente comando:

cscript iisext.vbs /EnFile C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll

Maggiori dettagli, ad esempio, qui.

Tag di Technorati: ,

Cambiare “Edit Top 200 Rows” e “Select Top 1000 Rows”

Usando spesso il SQL Server Management Studio, trovo noioso che ogni volta dovevo cambiare la query della select e dell’edit per vedere tutti i record.

image

Ho detto “dovevo cambiare” perché ho scoperto che è una cosa configurabile nelle opzioni su questo post.

Basta andare su Tools –> Options –> SQL Server Object Explorer e mettere i valori da voi desiderati.

image

Mettendo 0 seleziona sempre tutti i record. Occhiolino

Tag di Technorati:

Sviluppare per Windows Mobile su Windows7

Installando il Windows Mobile Device Center vi viene chiesto di installare Virtual PC 2007 (per utilizzare un su driver) che oltre ad essere una installazione un po’ “pesante” vi blocca l’utilizzo del XP Mode.

image

Ma c’è una soluzione che potrete trovare a questo indirizzo.

Grazie Andrea!!!

Tag di Technorati: ,

Access & E_FAIL(0x80004005)

Me lo scrivo sul blog nella speranza che mi rimanga in testa: quando fate query verso database Access da .NET può facilmente succedere di ottenere la seguente segnalazione di errore:

IErrorInfo.GetDescription failed with E_FAIL(0x80004005)

per risolverlo dovete “solo” aggiungere le parantesi quadre prima e dopo tutti i campi della query (per essere più chiari [nometabella].[nomecampo] ). A quanto ho capito, nel caso di interrogazioni che coinvolgono più tabelle, ad Access non basta che preponiate il nome della tabella a tutti i campi. Perplesso

Adesso scusatemi che devo perdere 10 minuti a mettere parentesi quadre in giro. Occhiolino

Tag di Technorati: ,

DateRange in C#

Su richiesta di qualcuno ho provveduto a fare il porting in C# di una mia “vecchia” classe per la gestione dei range di data di cui avevo parlato qui.

Ecco la versione C# (…devo ammettere mi ha fatto scovare un po’ di “cavolate” che VB non segnalava Imbarazzato)

    public class DateRange 
    {

        public enum IntervalType
        {
            Milliseconds,
            Second,
            Minute,
            Hour,
            Day
        }

        public enum Direction
        {
            Foward,
            Backward
        }

        private DateTime _start;
        public DateTime Start
        {
            get { return _start; }
            set { _start = value; }
        }

        private DateTime _end;
        public DateTime End
        {
            get { return _end; }
            set { _end = value; }
        }

        public DateRange(DateTime start, DateTime end)
        {
            _start = start;
            _end = end;
        }

        public bool IsEmpty
        {
            get
            {
                return (_start.CompareTo(null) == 0 && _end.CompareTo(null) == 0) || (_start.Equals(null) && _end.Equals(null));
            }
        }

        public bool Contains(DateTime value)
        {
            DateTime dateValue = value;
            return _start.CompareTo(dateValue) <= 0 && dateValue.CompareTo(_end) <= 0;
        }

        public bool Contains(DateRange other)
        {
            return this.Contains(other._start) && this.Contains(other._end);
        }

        public bool Intersect(DateRange other)
        {
            return !(this.Contains(other)) || other.Contains(_start) || other.Contains(_end);
        }

        public bool Overlaps(DateRange other)
        {
            return this.Contains(other) || other.Contains(_start) || other.Contains(_end);
        }

        public DateRange Intersection(DateRange other)
        {

            if (!this.Overlaps(other))
                return null;

            if (this.Contains(other))
                return other;
            if (other.Contains(this))
                return this;

            if (this.Start > other.Start)
            {
                return new DateRange(this.Start, other.End);
            }
            else
            {
                return new DateRange(other.Start, this.End);
            }

        }

        public IList<DateRange> Subtraction(DateRange other)
        {
            List<DateRange> ret = new List<DateRange>();

            if (this.Overlaps(other) && !other.Contains(this) && !this.Equals(other))
            {
                if (this.Contains(other))
                {
                    if (!(this.Start == other.Start))
                        ret.Add(new DateRange(this.Start, other.Start));
                    if (!(this.End == other.End))
                        ret.Add(new DateRange(other.End, this.End));
                }
                else
                {
                    if (this.Start >= other.Start)
                    {
                        ret.Add(new DateRange(other.End, this.End));
                    }
                    else
                    {
                        ret.Add(new DateRange(this.Start, other.End));
                    }
                }
            }

            return ret;

        }

        public double Total(IntervalType intervalType)
        {

            switch (intervalType)
            {
                case IntervalType.Day:
                    return _end.Subtract(_start).TotalDays;
                case IntervalType.Hour:
                    return _end.Subtract(_start).TotalHours;
                case IntervalType.Milliseconds:
                    return _end.Subtract(_start).TotalMilliseconds;
                case IntervalType.Minute:
                    return _end.Subtract(_start).TotalMinutes;
                case IntervalType.Second:
                    return _end.Subtract(_start).TotalSeconds;
                default:
                    throw new NotImplementedException("Not supported interval");
            }
        }

        public DateRange Extend(int value, IntervalType intervalType, Direction direction)
        {


            switch (intervalType)
            {
                case IntervalType.Day:
                    if (direction == DateRange.Direction.Backward)
                        return new DateRange(_start.AddDays(-1 * value), _end);
                    else
                        return new DateRange(_start, _end.AddDays(value));
                case IntervalType.Hour:
                    if (direction == DateRange.Direction.Backward)
                        return new DateRange(_start.AddHours(-1 * value), _end);
                    else
                        return new DateRange(_start, _end.AddHours(value));
                case IntervalType.Minute:
                    if (direction == DateRange.Direction.Backward)
                        return new DateRange(_start.AddMinutes(-1 * value), _end);
                    else
                        return new DateRange(_start, _end.AddMinutes(value));
                case IntervalType.Second:
                    if (direction == DateRange.Direction.Backward)
                        return new DateRange(_start.AddSeconds(-1 * value), _end);
                    else
                        return new DateRange(_start, _end.AddSeconds(value));
                case IntervalType.Milliseconds:
                    if (direction == DateRange.Direction.Backward)
                        return new DateRange(_start.AddMilliseconds(-1 * value), _end);
                    else
                        return new DateRange(_start, _end.AddMilliseconds(value));
                default:
                    throw new NotImplementedException("Not supported interval");
            }
        }

        public DateRange Shift(int value, IntervalType intervalType, Direction direction)
        {

            switch (intervalType)
            {
                case IntervalType.Day:
                    if (direction == DateRange.Direction.Foward)
                        return new DateRange(_start.AddDays(value), _end.AddDays(value));
                    else
                        return new DateRange(_start.AddDays(-1 * value), _end.AddDays(-1 * value));
                case IntervalType.Hour:
                    if (direction == DateRange.Direction.Foward)
                        return new DateRange(_start.AddHours(value), _end.AddHours(value));
                    else
                        return new DateRange(_start.AddHours(-1 * value), _end.AddHours(-1 * value));
                case IntervalType.Minute:
                    if (direction == DateRange.Direction.Foward)
                        return new DateRange(_start.AddMinutes(value), _end.AddMinutes(value));
                    else
                        return new DateRange(_start.AddMinutes(-1 * value), _end.AddMinutes(-1 * value));
                case IntervalType.Second:
                    if (direction == DateRange.Direction.Foward)
                        return new DateRange(_start.AddSeconds(value), _end.AddSeconds(value));
                    else
                        return new DateRange(_start.AddSeconds(-1 * value), _end.AddSeconds(-1 * value));
                case IntervalType.Milliseconds:
                    if (direction == DateRange.Direction.Foward)
                        return new DateRange(_start.AddMilliseconds(value), _end.AddMilliseconds(value));
                    else
                        return new DateRange(_start.AddMilliseconds(-1 * value), _end.AddMilliseconds(-1 * value));
                default:
                    throw new NotImplementedException("Not supported interval");

            }
        }

        public override int GetHashCode()
        {
            return _start.GetHashCode() ^ _end.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            if (obj is DateRange)
            {
                return Equals((DateRange)obj);
            }
            else
            {
                return false;
            }
        }

        public bool Equals(DateRange other)
        {
            return _start.Equals(other._start) && _end.Equals(other._end);
        }

        public static bool operator ==(DateRange a, DateRange b)
        {
            return a.Equals(b);
        }

        public static bool operator !=(DateRange a, DateRange b)
        {
            return !(a == b);
        }
    }

Ho approfittato per aggiungere gli operatori == e != (cosa non fattibile in VB).

Spero che la fretta non abbia prodotto danni ai gattini A bocca aperta altrimenti segnalatemi qualsiasi imprecisione.

Tag di Technorati: ,

Errori WCF “poco chiari”

Ormai lavoro sempre attraverso servizi WCF per tre principali motivi:

  • Spesso mi trovo a dover delocalizzare geograficamente i miei programmi per cui avere l’accesso ai dati vicino al DB non va mai male Occhiolino
  • Non devo installare la connessione al DB a tutte le macchine client (attualmente uso Oracle XE come DB)
  • Se devo cambiare qualcosa, spesso il problema è lato servizi e posso rimediare senza “disturbare” gli utenti.


Purtroppo spesso WCF è criptico nella segnalazione degli errori e molto frequentemente ritorna una eccezione del tipo “The connection was closed unexpectedly” Perplesso che non aiuta molto nella soluzione del problema, anche se ho incluso la seguente voce nel file di configurazione:

<serviceDebug includeExceptionDetailInFaults="true" />

All’ennesimo errore ho “googlato” un po’ scoprendo questa pagina che spiega come abilitare e analizzare la traccia dei servizi WCF.
“Basta” aggiungere una parte di configurazione al web.config del servizio

<system.diagnostics>
    <trace autoflush="true" />
    <sources>
            <source name="System.ServiceModel" 
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
            <listeners>
               <add name="sdt" 
                   type="System.Diagnostics.XmlWriterTraceListener" 
                   initializeData= "SdrConfigExample.e2e" />
            </listeners>
         </source>
    </sources>
</system.diagnostics>

sulla pagina sopra riportata trovate tutte le possibili configuazione del tracing.Vorrei solo sottolineare che l’attributo “initializeData” consente di definire il nome del file di trace e può essere un path completo, nel caso venga utile e che l’attributo “switchValue” permette di decidere il livello di tracing desiderato.Il file di trace così prodotto può essere aperto con l’utility “SvcTraceViewer” che organizza il file in maniera molto più leggibile.Alla fine il vero problema era “Maximum number of items that can be serialized or deserialized in an object graph is '65536'”, risolto aggiungendo la seguente configurazione alla sezione del serviceBehaviors:

<dataContractSerializer maxItemsInObjectGraph="2147483647" />

Spesso nelle mie LOB applications mi trovo a dover gestire messaggi belli “cicciotti”… ma questo potrebbe essere materiale per un altro post Con la lingua fuori

Tag di Technorati: ,

Username e organizzazione sbagliata in Visual Studio 2010

Settimana di ferragosto = un po’ più di tempo per le “cavolate” non core business Occhiolino

Ogni volta che lanciavo Visual Studio 2010 mi dava fastidio non vedere le informazioni corrette della registrazione, ma era un fastidio facilmente sopportabile. A bocca aperta

image

Oggi ho trovato un post che spiega come risolvere il problema:

Per le macchine a 64 bit:

cambiate a vostro piacimento le seguenti chiavi:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Registration\UserName
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization

e poi, da una console di amministrazione, lanciate il seguente comando: "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" /setup

Per le macchine a 32 bit:

cambiate a vostro piacimento le seguenti chiavi:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Registration\UserName
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization

e poi, da una console di amministrazione, lanciate il seguente comando: "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" /setup

Happy developing to all! Con la lingua fuori

Archiviazione della posta di Outlook

Fino ad un po’ di tempo fa Outlook archiviava la posta basandosi solo sulla data di modifica della stessa. Di solito questa data corrispondeva alla data di ricevimento, ma non sempre, come ad esempio succede a me che devo “convivere” con Lotus Notes e utilizzo il DAMO connector per utilizzare Outlook come client. Quando rifaccio la macchina, infatti, il sistema riscarica le mail da Lotus mettendo la data di scaricamento come data di modifica (e non quella di ricezione).

Questo comporta problemi durante una fase di archiviazione (ad esempio io mi tengo un archivio per anno).

La soluzione utilizzata fino a poco tempo fa era utilizzare una utility di terze parti (ArchiveAssist for Outlook) che purtroppo non funziona né con Outlook 2010 né, tantomeno, con macchine a 64 bit. Triste

Con Outlook 2007 e 2010 ora è possibile utilizzare la data di ricezione invece che quella di modifica installando una HotFix (per Outlook 2010 “va su” con il SP1).

E’ quindi necessario aprire il registry e aggiungere la seguente chiave:

Per Outlook 2007:
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Preferences
Per Outlook 2010:
HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Preferences

Nome valore: ArchiveIgnoreLastModifiedTime
Tipo Valore: REG_DWORD
Valore: 1

Al prossimo riavvio di Outlook verrà utilizzata la data di ricevimento come data di riferimento per l’archiviazione.

Maggiori dettagli qui.

Buona archiviazione a tutti! Occhiolino

Tag di Technorati: ,

Formattazione stringhe SQL Online

So che ormai tutti usate ORM e quindi non dovete più sporcarvi le mani con l’SQL, ma nel caso vi trovaste a doverlo fare questo servizio on-line può aiutarvi a renderle più “belline” e anche, ad esempio, a prepararvele come StringBuilder da copiare e incollare sul vostro codice. Peccato non ci sia l’add-in per Visual Studio 2010… l’avrei comprato al volo.

Instant SQL Formatter

A must have tool! Occhiolino

Tag di Technorati:
«febbraio»
domlunmarmergiovensab
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910