Archivi per la categoria nerdate

Ma no, mica è una vulnerabilità grave...

02-07-2008 17:33:24 CEST Postato in: nerdate | Commenta
set user_name to system attribute "USER"
tell application "ARDAgent" to do shell script "dscl localhost -append /Local/Default/Groups/admin GroupMembership " & user_name

Firefox download day

18-06-2008 17:34:11 CEST Postato in: gente di un certo livello, nerdate | Commenta

<luxid> oggi è il download day! aiuta firefox ad entrare nel guinnes dei primati con il massimo numero di download in 24 ore! http://www.spreadfirefox.com/it/worldrecord entro le 20 di oggi

E' da ieri che Azzurra è piena di questa immondizia - e non oso immaginare cosa stiano combinando i soliti maniaci delle catene su MSN.

Se ormai l'unico modo per pubblicizzare l'opensource è armare orde di spammer deficienti, allora abbiamo sbagliato su tutta la linea e meritiamo di essere presi per il culo dai troll di PI.

FNV-0 in Python

16-06-2008 23:09:48 CEST Postato in: nerdate, python | Commenta

Piccolo code snippet per estimatori del pitone.

def fnv_hash(data):
   """
    Returns a 32bit FNV-0 hash of the given string.

    >>> fnv_hash('3dcb910fb26bafb97e4a9660493afd9704536743')
    -1588890617L
    >>> fnv_hash('deb114355f8b912c4f7c7f0aceac7adceaa5db10')
    317390073L
    """
   h = long(0)
   for i in xrange(len(data)):
      h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24)
      h ^= ord(data[i])
   # Everything after the 32th bit is meaningless
   h &= 0xffffffffL
   # Perform sign extension
   if h & 0x80000000L:
       h = -(~(h - 1) & 0xffffffffL)
   return h

I compagni di merende che masticano C avranno sicuramente storto il naso vedendo sia l'AND che l'estensione di segno fatta in quel modo becero, quindi precisiamo:

  • Python promuove automaticamente gli interi alla storage class superiore (ANCHE oltre i 64 bit) per evitare l'overflow, quindi solo i 32 bit inferiori contengono valori sensati;
  • per quanto appena esposto, l'estensione di segno non può essere effettuata con un banale OR (che promuoverebbe l'intero per conservare il segno!) ma è necessario fare ricorso alla definizione scolastica di complemento a 2.

The pasta theory of design

11-06-2008 15:50:58 CEST Postato in: nerdate, python | Commenta
  • Spaghetti: each piece of code interacts with every other piece of code [can be implemented with GOTO, functions, objects]
  • Lasagna: code has carefully designed layers. Each layer is, in theory independent. However low-level layers usually cannot be used easily, and high-level layers depend on low-level layers.
  • Ravioli: each part of the code is useful by itself. There is a thin layer of interfaces between various parts [the sauce]. Each part can be used elsewhere.
  • ...but sometimes, the user just wants to order Ravioli, so one coarse-grain easily definable layer of abstraction on top of it all can be useful.

(from Twisted Matrix documentation)

Post Successivi »