Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

Suspicious Dish posted:

Context: this post.

Let's start with what I called "stooge maps". They wanted an ordered set of key-value pairs in JSON. How did they choose to represent it?

code:
[
  { 'foo': 3 },
  { 'bar': 10 }
]
The linear lookup power of a list, combined with the API usefulness of a hash map! Here's the code that built it, and yes, that whole file is a horror.

Back in the early 90s, Amiga OS programmers called these things "tag lists"! Looks like someone was reminiscing a bit.

Of course, that was back before we had fancy associative maps.

Adbot
ADBOT LOVES YOU

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Flobbster posted:

Back in the early 90s, Amiga OS programmers called these things "tag lists"! Looks like someone was reminiscing a bit.

Of course, that was back before we had fancy associative maps.

I would have been fine if it was [ ["foo", 3], ["bar", 10] ] or even [ "foo", 3, "bar", 10 ]. I fully accept that JSON doesn't have an "ordered map" type. It's just awkward and inconvenient to represent a key/value pair by a JSON dictionary.

Zombywuf
Mar 29, 2008

shrughes posted:

You people are hysterical. Why don't you complain about the subtraction operator, that's indistinguishable from a dust particle too.

Clearly you have better dust than me. The dust on my screen forms dots not perfectly horizontal bars.

FLEXBONER
Apr 27, 2009

Esto es un infierno. Estoy en el infierno.

xarph posted:

Please, PLEASE tell me you have a successful example.

Unless it has something to do with your username, in which case you can keep it to yourself.

Here's my chef program in all its stupid glory - it's a "banana smoothie" recipe that outputs the word "banana" when run on the command line:

code:
Explicit Banana Smoothie.

Ingredients.
13 banana slices
13 plantain slices
6 strawberries
1 cup milk
1 teaspoon vanilla extract
4 pinches sugar
6 ice cubes
4 teaspoons yogurt

Method.
Dice the strawberries. 
Put ice cubes into the mixing bowl. 
Combine sugar into the mixing bowl. 
Combine yogurt into the mixing bowl. 
Add vanilla extract into the mixing bowl. 
Dice the strawberries until diced. 
Add banana slices into the mixing bowl. 
Stir the mixing bowl for 4 minutes. 
Add plantain slices into the mixing bowl. 
Stir the mixing bowl for 2 minutes. 
Add milk into the mixing bowl. 
Add strawberries into the mixing bowl. 
Liquify contents of the mixing bowl. 
Pour contents of the mixing bowl into the baking dish. 

Serves 1.
I got a B on the project :v:

EDIT: breakin them tables

FLEXBONER fucked around with this message at 19:03 on Feb 5, 2012

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
{'foo': 3} isn't even valid JSON :argh:

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Janin posted:

{'foo': 3} isn't even valid JSON :argh:

Oh yeah, JSON requires double quotes for strings. That's not the code's bug, it's mine.

ymgve
Jan 2, 2004


:dukedog:
Offensive Clock

Poop Delicatessen posted:

Here's my chef program in all its stupid glory - it's a "banana smoothie" recipe that outputs the word "banana" when run on the command line:

code:
Explicit Banana Smoothie.

Ingredients.
13 banana slices
13 plantain slices
6 strawberries
1 cup milk
1 teaspoon vanilla extract
4 pinches sugar
6 ice cubes
4 teaspoons yogurt

Method.
Dice the strawberries. 
Put ice cubes into the mixing bowl. 
Combine sugar into the mixing bowl. 
Combine yogurt into the mixing bowl. 
Add vanilla extract into the mixing bowl. 
Dice the strawberries until diced. 
Add banana slices into the mixing bowl. 
Stir the mixing bowl for 4 minutes. 
Add plantain slices into the mixing bowl. 
Stir the mixing bowl for 2 minutes. 
Add milk into the mixing bowl. 
Add strawberries into the mixing bowl. 
Liquify contents of the mixing bowl. 
Pour contents of the mixing bowl into the baking dish. 

Serves 1.
I got a B on the project :v:

EDIT: breakin them tables

Only B? What the gently caress would you need to do to get an A?

FLEXBONER
Apr 27, 2009

Esto es un infierno. Estoy en el infierno.

ymgve posted:

Only B? What the gently caress would you need to do to get an A?

Produce a more interesting output. You have to undrestand, Ian Bogost is a crazy person.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Poop Delicatessen posted:

Produce a more interesting output.

When you say "output", are you referring to the output of the program qua program or the program qua recipe?

Hammerite fucked around with this message at 08:52 on Feb 6, 2012

FLEXBONER
Apr 27, 2009

Esto es un infierno. Estoy en el infierno.

Hammerite posted:

When you say "output", are you referring to the output of the program qua program or the program qua recipe?

The former.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Poop Delicatessen posted:

The former.

Oh come on, I bet if it produced an amazing beef bourguignon and printed "MOO" you'd have got an A.

edit: or made a tasty pie and calculated pi

w00tz0r
Aug 10, 2006

I'm just so god damn happy.
"So each node has either a branch or a leaf..."
"Wait, what?"

code:
class Tree
{
   ...

private:
   Node *_root;
};

struct Branch { std::list<Node> children };

// Leaf just has a bunch application specific fields
struct Leaf { };

struct Node
{
    Node(Branch *branch);
    Node(Leaf *leaf);

    union NodeType
    {
        Branch *branch;
        Leaf *leaf;
    }

    NodeType nodeType;
    bool     isBranch;
};
I guess that's one way to construct a tree.

edit: Didn't think to describe the body of Branch and Leaf.

w00tz0r fucked around with this message at 06:18 on Feb 7, 2012

nielsm
Jun 1, 2009



w00tz0r posted:

I guess that's one way to construct a tree.

Looks like someone chopped down a forest and left the bits piled up on the ground.

PalmTreeFun
Apr 25, 2010

*toot*

w00tz0r posted:

I guess that's one way to construct a tree.

http://www.youtube.com/watch?v=pH5KJZuuyg8#t=1m52s

It's a highly attractive "tree" for sure. It almost looks like a hemlock. It's a coat rack.

w00tz0r
Aug 10, 2006

I'm just so god damn happy.
That video made my day.

Volte
Oct 4, 2004

woosh woosh

w00tz0r posted:

"So each node has either a branch or a leaf..."
"Wait, what?"

code:
class Tree
{
   ...

private:
   Node *_root;
};

struct Branch { };
struct Leaf { };

struct Node
{
    Node(Branch *branch);
    Node(Leaf *leaf);

    union NodeType
    {
        Branch *branch;
        Leaf *leaf;
    }

    NodeType nodeType;
    bool     isBranch;
};
I guess that's one way to construct a tree.
Haskell programmer found

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

Volte posted:

Haskell programmer found
that design doesn't make any sense in haskell, either:
code:
data Tree = Tree Node

data Branch = Branch
data Leaf = Leaf

data Node = Node NodeType

data NodeType = NodeBranch Branch | NodeLeaf Leaf

Volte
Oct 4, 2004

woosh woosh
I think Branch and Leaf are supposed to inherit from Node or something. Either that or it's an incomplete paste and Branch is what contains the pointer to the subtree. Still really dumb though

w00tz0r
Aug 10, 2006

I'm just so god damn happy.

Volte posted:

I think Branch and Leaf are supposed to inherit from Node or something. Either that or it's an incomplete paste and Branch is what contains the pointer to the subtree. Still really dumb though

It's the latter, Branch has a pointer to a list of Nodes.

raminasi
Jan 25, 2005

a last drink with no ice
That looks like it's supposed to be a tree implemented with discriminated unions.

FamDav
Mar 29, 2008

GrumpyDoctor posted:

That looks like it's supposed to be a tree implemented with discriminated unions.

Isn't it, though? Node has a bool value that can be used to check type.

Still, goddamn.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
The matrix operations on dict :) python-ideas thread seems to me like it belongs in this thread.

julien tayon posted:

Proposing vector operations on dict, and acknowledging there was an
homeomorphism from rooted n-ary trees to dict, was inducing the
possibility of making matrix of dict / trees.

Since, linear algebrae on dict was coldly welcomed, I waited to have
some code to back me up to push my reasoning furhter, and it happily
worked the way books predicted.


This was the reasoning :
- dict <=> vector
- Vectors + linear algebrae <=> matrix
- Most of Rooted Trees <=> dict( dict( ... ) ) **
- Matrix * Vector = Vector2 <=> Matrix * tree1 = Tree2

The details of the proposal make a surprising amount of mathematical sense, but to me (and everyone who replied on the mailing list) the implementation is bizarre.

julien tayon posted:

Sturla Molden posted:

Why would you want to use a hash table (Python dict) for linear algebra?
* Because it naturally provides matrix. And matrix are an easy way to
formalize and standardize tree manipulations which are a growing
concern in real life computer craft.

* Because actual CS is precise but not exact, and that metrics on
objects enable more exact comparison :

== is the actual way to compare it is precise
, but metrics (cos, norm, dot) enable
is_close_to( Value , modulo error )

For instance no actual langage can tell if two floats are equal,
because, there are error margins.

pi != 3.14159
pi is close to 3.1 [+-.05]

Exactitude and precision are not the same.
:stare: Am I crazy, or does that answer have very little to do with the question?

Sturla Molden posted:

julien tayon posted:

It is stupid to code matrix with an hash, I just say as there is a
strong analogy between dict and vectors,

No there is not. A vector is ordered, a hash-table (dict) is unordered.

- In a vectorlike structure, e.g. a Python list, element i+1 is stored subsequently to element i.

- In a hash-table, e.g. a Python dict, element hash(i+1) is not stored subsequently to element hash(i).

I can see how you can view dicts as a sorted set of key-value pairs in terms of the natural ordering of the keys, but this guy doesn't seem to be able to articulate an answer to "why the hell do you want to do this; if you're going to do linear algebra on sparse matrices why don't you use any of the appropriate SciPy classes that benefit from decades' worth of optimization (e.g. using LAPACK)"

Maybe he's a genius and the joke's on me, but his inability (or unwillingness) to answer simple questions makes me wonder:

julien tayon posted:

Steven D'Aprano posted:

Otherwise, this looks rather like a library of functions looking for a
use. It might help if you demonstrate what concrete problems this helps
you solve.
Since 95% of the functions are method of a dict, I guess, we may call
it an object.

(maybe stealth) EDIT: I should have looked closer at that SciPy page -- one of the sparse matrix types is based on a dictionary of keys. It looks like the main advantages of this type are that they're easy to build, certain matrix operations are fast (e.g. addition), and you can very easily transform them to other SciPy matrix types when you need to do anything more advanced.

I'm starting to think that the only horror is wanting to include a watered-down version of SciPy matrix manipulation in the standard library.

Lysidas fucked around with this message at 18:15 on Feb 8, 2012

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
I don't have the code to actually post, but I'm doing an online submission for a recommendation letter for one of my students' scholarship applications, and as I was reading the instructions (a pretty standard "upload a Word doc or PDF"), I see this thing highlighted in red:

quote:

Please note that you can not upload documents with more than 7 characters, spaces or symbols. Name your document with a simple name, such as essay.doc

:wtc:

In the first place, the way it's written it sounds like the letter, not the filename, can only be 7 characters :haw: Secondly, why? If you're accepting arbitrary uploads via HTTP, they can (and probably should) discard the filename provided by the user and rename it using some naming convention anyway.

Maybe the back-end server is an old 8.3 DOS machine but they told users to stick with 7 just to be extra safe.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
deltree windows&.doc

Red Mike
Jul 11, 2011
Obviously it's because after chaining the numerous if statements to reject every insecure combination they could think of, up to 7 characters, they decided the code was too long.

kalleth
Jan 28, 2006

C'mon, just give it a shot
Fun Shoe
code:
  def populate_maps(devices_map,strips_map,widgets_map)
      regexpr = /\w*:\w*:(\d*)/
      unless devices_map.nil?
        cached_dsm = MEMCACHE['data_source_map']
        cached_dsm = cached_dsm['unspecified']['unspecified'].invert
        cached_devices = MEMCACHE['devices'] || []
        cached_devices.each do |dev|
          unless cached_dsm[dev].nil?
            results = regexpr.match(dev)
            devices_map[cached_dsm[dev]] = results[1] unless results.nil?
          end
        end
      end
      # read all the destination strips
      unless strips_map.nil?
        cached_dsm = MEMCACHE['data_source_map']
        cached_dsm = cached_dsm['unspecified']['unspecified'].invert
        cached_strips = MEMCACHE['strips'] || []
        cached_strips.each do |s|
          unless cached_dsm[s].nil?
            results = regexpr.match(s)
            strips_map[cached_dsm[s]] = results[1] unless results.nil?
          end
        end
      end
      # read all the destination widgets
      unless widgets_map.nil?
        cached_dsm = MEMCACHE['data_source_map']
        cached_dsm = cached_dsm['unspecified']['widgets'].invert
        cached_widgets = MEMCACHE['widgets'] || []
        cached_widgets.each do |wid|
          unless cached_dsm[wid].nil?
            results = regexpr.match(wid)
            widgets_map[cached_dsm[wid]] = results[1] unless results.nil?
          end
        end
      end
  end
can anyone spot why I, as a 'lesser' Developer, cried when I saw this code from a Senior Developer? (read: Crony of the CEO)

ozymandOS
Jun 9, 2004
Not a coding horror so much as a large-company process horror. Okay, it's a bit of a coding horror as well.

I work on a client/server-architected app. Our core-code team handrolled the RPC mechanism between the client & server. This is less terrible than it sounds as there is no "standard" RPC mechanism between the client & server technologies we use.

A while back someone got worried that we were sending all the data between the client & server unencrypted. So they implemented an "encrypted" RPC, which is the same as a regular RPC except that all of the data between the client & server is encrypted.

I got a call from one of our higher-level tech support guys a few days ago to track down a bug one of our customers was hitting, which was related to an RPC that happened to be encrypted. The root cause turned out to be that the encrypted RPC would silently drop the beginning of the returned data if the response was too large. I dutifully reported this to our core team.

The core team refused to fix the bug and asked why we were sending so much data back in the first place. (Nowhere is it documented that there is a size limit on the return value for encrypted RPCs, and there explicitly isn't a size limit on the response for non-encrypted RPCs which the encrypted RPCs are supposed to be a drop-in replacement for.) Now my job is to implement a workaround for this RPC, outside of the RPC. Other users of the encrypted RPC? Better hope they don't start returning too much data.

Extra bonus horror: [nah]

ozymandOS fucked around with this message at 08:34 on Jan 29, 2016

That Turkey Story
Mar 30, 2003

BP posted:

Extra bonus horror: the fix we are putting in place is to stop using the encrypted form of the RPC. This is because the "encryption" on the RPC is actually just a keyless transposition/obfuscation, not any real form of encryption. The core team didn't really share this with anyone--we've been transmitting sensitive data with essentially zero security for years.

Haha, saw this coming a mile away.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

BP posted:

This is less terrible than it sounds as there is no "standard" RPC mechanism between the client & server technologies we use.

Well ok.

BP posted:

Extra bonus horror: the fix we are putting in place is to stop using the encrypted form of the RPC. This is because the "encryption" on the RPC is actually just a keyless transposition/obfuscation, not any real form of encryption. The core team didn't really share this with anyone--we've been transmitting sensitive data with essentially zero security for years.

Yes, roll-your-own encryption. Good idea or the best idea?

Vanadium
Jan 8, 2005

Clearly the solution is for your team to implement your own encryption and also response-splitting technology on top of the core team's encrypted rpc stuff. There's a reason they call it networking stack!

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Use their encrypted RPC mechanism to transmit a single bit, then roll your own PPP implementation of top of it.

Then you can layer TCP/IP on top of that and finally your own RPC mechanism to top it all off.

Impotence
Nov 8, 2010
Lipstick Apathy
code:
function forwardedfor(ip) {
  var ip_address = ip.connection.remoteAddress ? ip.connection.remoteAddress : ip.remoteAddress;
  try {
    if(ip.headers["X-Forwarded-For"]) {
      var host_array = ip_address.split(".");
      var XFF = false;
      switch(parseInt(host_array[0])) {
        case 192:
          if(parseInt(host_array[1]) == 168 && parseInt(host_array[2]) > -1 || parseInt(host_array[2]) < 256) {
            XFF = true;
          }
          break;
        case 172:
          if(parseInt(host_array[1]) > 15 || parseInt(host_array[1]) < 32) {
            XFF = true;
          }
          break;
      }
      if(XFF) {
        ip_address = ip.headers["X-Forwarded-For"];
      }
    }
  }
  catch(e) {}
  return ip_address;
}
;
This isn't IPv6 ready, is it

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Would it be too generous to suggest that someone forgot to add if (debug) around that garbage?

Impotence
Nov 8, 2010
Lipstick Apathy

pokeyman posted:

Would it be too generous to suggest that someone forgot to add if (debug) around that garbage?

Why would you think that?

(production)

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
isn't just putting in openssl/gnutls like a 10-line change? why did your team roll their own encryption?

ymgve
Jan 2, 2004


:dukedog:
Offensive Clock
I don't even understand the code. It will only use the XFF address if the connection IP address is a LAN address, but not otherwise? In what situations would that happen?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Biowarfare posted:

Why would you think that?

(production)

ymgve posted:

I don't even understand the code. It will only use the XFF address if the connection IP address is a LAN address, but not otherwise? In what situations would that happen?

Debugging is the only situation I came up with, so that's why I thought that.

The Gripper
Sep 14, 2004
i am winner
What on earth is it trying to do? I followed it mostly until it got to:
code:
if(parseInt(host_array[1]) > 15 || parseInt(host_array[1]) < 32) {
which is ALWAYS true.

Actually even the previous one is always true (if ip is x.168 or octet 3 is < 256 (always)).

Impotence
Nov 8, 2010
Lipstick Apathy

The Gripper posted:

What on earth is it trying to do?

I presume it's to do something like allowing X-F-F to be parsed for logging to access.log/error.log or for DB/logins/etc

It doesn't actually work.


edit: the only thing that that function is called in is to log to access.log on page hit

access.log's IPs consist entirely of 10.* LAN IPs.

Impotence fucked around with this message at 01:34 on Feb 11, 2012

Adbot
ADBOT LOVES YOU

ymgve
Jan 2, 2004


:dukedog:
Offensive Clock
I just thought of a reason why it might be there - if there is a transparent proxy/concentrator in front of the web server, it will allow the server to log the real IPs.

Of course, this doesn't work at all since they ignore 10.x.x.x.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply