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
QuarkJets
Sep 8, 2008

When you have a data stream, are you easily able to map it to a physical sensor? Couldn't you just maintain the full sensor map without re-creating the entire dictionary every time that you see a new sensor?

Adbot
ADBOT LOVES YOU

SurgicalOntologist
Jun 17, 2004

The data stream includes the physical sensor number. Not sure what you mean by a "full" sensor map, if every application used all the sensors then this wouldn't be an issue. The issue is to figure out which subset of the sensors is currently in use.

I don't know why we're still talking about this. As I mentioned earlier, I figured out a way to ask for the number of sensors in use without requiring the user to enter it, so my new method doesn't involve catching exceptions or re-creating dicts:
1. Ask how many sensors to expect.
2. Keep track the sensors I've encountered.
3. When I've encountered the expected number of sensors, create the logical-physical mapping and switch to the normal data handler.

Macichne Leainig
Jul 26, 2012

by VG
code:
<Image HorizontalAlignment="Left"  Margin="0,0,0,0" Source="/ToolSuite;component/Images/Gray.bmp" Stretch="Fill"/>
Yup, this is an image, in full WPF XAML, that does exactly what a rectangle can do. And the color is literally the color Gray. As in the preset colors you can use for a rectangle fill Gray.

No Safe Word
Feb 26, 2005

Tha Chodesweller posted:

code:
<Image HorizontalAlignment="Left"  Margin="0,0,0,0" Source="/ToolSuite;component/Images/Gray.bmp" Stretch="Fill"/>
Yup, this is an image, in full WPF XAML, that does exactly what a rectangle can do. And the color is literally the color Gray. As in the preset colors you can use for a rectangle fill Gray.

Well now if you want to change the color you just update Gray.bmp to be blue, duh

Macichne Leainig
Jul 26, 2012

by VG
Perhaps more astonishingly, this exact method and image are used to set the background color of buttons elsewhere. Instead of, y'know, Background="Gray".

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
What if Microsoft changes the definition of Gray, or makes Rectangles display as hexagons? You need to think ahead.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug

Gazpacho posted:

or makes Rectangles display as hexagons

This isn't the thread for discussing leaked confidential Microsoft plans for Metro 2.0 in Windows 9

Macichne Leainig
Jul 26, 2012

by VG

Gazpacho posted:

What if Microsoft changes the definition of Gray, or makes Rectangles display as hexagons? You need to think ahead.

It's a non client facing utility and if I recall correctly the color definitions are from X11, so I would be more worried of interns changing images haphazardly. :v:

Goatse buttons anyone?

Polio Vax Scene
Apr 5, 2009



I can't believe I wrote this. To be fair it was over two years ago. It's a miracle this hasn't broken until today when someone put a non-UTF8 character in the json
code:
string sendData = entity.jsonSendData;

WebRequest request = WebRequest.Create(referenceCheckURL);

request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = sendData.Length;

Stream requestStream = request.GetRequestStream();
requestStream.Write(System.Text.Encoding.UTF8.GetBytes(sendData), 0, sendData.Length);
requestStream.Close();
e: also the lack of usings.

Polio Vax Scene fucked around with this message at 23:20 on Jan 21, 2014

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Manslaughter posted:

put a non-UTF8 character in the json

A code point wider than 8 bits, you mean?

Zombywuf
Mar 29, 2008

What the hell is a non-UTF8 character and what is it doing in a String object?

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Manslaughter posted:

You guys are so lucky, you actually have things in your exception blocks :smith:

At my last job we had:

code:
catch(Exception ex)
{
    throw ex;
}
or

code:
bool method(int foo, out string errorMsg)
{
    try { ... }
    catch(Exception ex)
    {
        errorMsg = ex.Message;
        return false;
    }
    return true;
}
Now with both of those in use you had no idea where anything came from.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
http://msdn.microsoft.com/en-us/library/office/cc264288%28v=office.14%29.aspx

Are you loving kidding me, Microsoft? A public API with multiple numbered methods?

code:
expression.EditDocument2(pdisp, bstrDocumentLocation, fUseLocalCopy, varProgID)

omeg
Sep 3, 2012

You must be new to COM interfaces. :v:

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Bognar posted:

http://msdn.microsoft.com/en-us/library/office/cc264288%28v=office.14%29.aspx

Are you loving kidding me, Microsoft? A public API with multiple numbered methods?

code:
expression.EditDocument2(pdisp, bstrDocumentLocation, fUseLocalCopy, varProgID)

Sharepoint. That explains it. I'm still not convinced that Sharepoint isn't something Microsoft made to gently caress with our heads as opposed to a usable, sane, useful product.

Jewel
May 2, 2009

Bognar posted:

http://msdn.microsoft.com/en-us/library/office/cc264288%28v=office.14%29.aspx

Are you loving kidding me, Microsoft? A public API with multiple numbered methods?

code:
expression.EditDocument2(pdisp, bstrDocumentLocation, fUseLocalCopy, varProgID)

Nice that the article is about EditDocument3 but the code sample is EditDocument2 :allears:

Also the comment on the page: "The expample is incorrect"

Edit: Using this post to share: My friend showed me this http://stackoverflow.com/questions/21186724/have-i-tattooed-a-syntax-error-on-my-arm?newsletter=1&nlcode=4592|dedb it's kind of a coding horror in a way :gonk:

Jewel fucked around with this message at 04:53 on Jan 22, 2014

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Ithaqua posted:

Sharepoint. That explains it. I'm still not convinced that Sharepoint isn't something Microsoft made to gently caress with our heads as opposed to a usable, sane, useful product.

I'm convinced it's a product that was made by a group of interns in 3 months that the marketing guys managed to get a hold of and sell to every large company on the planet. It's not uncommon for me and my coworker to ask each other "Why did you do this?" and the answer is usually "Because SharePoint." Here's a beauty in our current codebase:

C# code:
foreach (SPSite site in WebApplication.Sites) using (site)
	{
		foreach (SPWeb web in site.AllWebs) using (web)
			{
				ProcessWeb(web);
			}
	}
The properties Sites and AllWebs automatically instantiate connections to the sites or webs which you then have to dispose of yourself. This happens every time you access the property. Who the hell decided to make that a property and not a method? Also, what's up with the naming? Why not AllSites, or maybe just Webs, so we could have some drat consistency?

Polio Vax Scene
Apr 5, 2009



Munkeymon posted:

A code point wider than 8 bits, you mean?


Zombywuf posted:

What the hell is a non-UTF8 character and what is it doing in a String object?

Whoops, had it backwards. Expecting ASCII, got UTF8. Even though I'm using UTF8 GetBytes. Guess I picked one at random, said "eh it works" and moved on.

It was a thing that made the length of the string different from the length of the bytes.

So the stream got cut off early because I was measuring the string length and not the byte length.

(gently caress your bytes)

hirvox
Sep 8, 2009

Bognar posted:

The properties Sites and AllWebs automatically instantiate connections to the sites or webs which you then have to dispose of yourself. This happens every time you access the property. Who the hell decided to make that a property and not a method? Also, what's up with the naming? Why not AllSites, or maybe just Webs, so we could have some drat consistency?
Because SPWeb.Webs returns only the child sites of the current site. Sharepoint naming conventions are already bad enough without putting two completely different functionalities under identically named properties.

Another Sharepoint horror: Violating the design contract for the IDisposable interface. For example, SPLimitedWebPartManager implements IDisposable. But in addition to wrapping the SPLimitedWebPartManager in an using block, you must also dispose the SPWeb exposed by the Web property manually.

SPDisposeCheck saved us a lot of trouble, and I've configured it to be run in every Team Build that I'm responsible for.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Give me all the webs! :byodood:

Suspicious Dish
Sep 24, 2011

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

Jewel posted:

Edit: Using this post to share: My friend showed me this http://stackoverflow.com/questions/21186724/have-i-tattooed-a-syntax-error-on-my-arm?newsletter=1&nlcode=4592|dedb it's kind of a coding horror in a way :gonk:

I expect no less from a language that has "Quote Removal" as one of its parsing steps.

Dren
Jan 5, 2001

Pillbug

Manslaughter posted:

Whoops, had it backwards. Expecting ASCII, got UTF8. Even though I'm using UTF8 GetBytes. Guess I picked one at random, said "eh it works" and moved on.

It was a thing that made the length of the string different from the length of the bytes.

So the stream got cut off early because I was measuring the string length and not the byte length.

(gently caress your bytes)

While you're in there you might as well change things to support all Unicode, as json is defined to be unicode by rfc4627.

code:
3.  Encoding

   JSON text SHALL be encoded in Unicode.  The default encoding is
   UTF-8.

   Since the first two characters of a JSON text will always be ASCII
   characters [RFC0020], it is possible to determine whether an octet
   stream is UTF-8, UTF-16 (BE or LE), or UTF-32 (BE or LE) by looking
   at the pattern of nulls in the first four octets.

           00 00 00 xx  UTF-32BE
           00 xx 00 xx  UTF-16BE
           xx 00 00 00  UTF-32LE
           xx 00 xx 00  UTF-16LE
           xx xx xx xx  UTF-8
http://www.ietf.org/rfc/rfc4627.txt

jiggerypokery
Feb 1, 2012

...But I could hardly wait six months with a red hot jape like that under me belt.

Serious contender for the worlds greatest PR;

https://github.com/fre5h/DoctrineEnumBundle/pull/12

A collegue submitted that PR yesterday. We thought the reply was pretty special yesterday. Today it's all over twitter and gone totally viral.

Zombywuf
Mar 29, 2008

That thread highlights the dangers of code getting political:

quote:

poo poo. I don't want to have comments like these on PRs to my repos while I stay here, in Russia...

Jewel
May 2, 2009

Ahah, yep, I saw that on twitter today! Definitely getting around.

jiggerypokery
Feb 1, 2012

...But I could hardly wait six months with a red hot jape like that under me belt.

Zombywuf posted:

That thread highlights the dangers of code getting political:

Good point, if that is all over twitter too, the wrong people could see it and take it badly.

Opinion Haver
Apr 9, 2007

The scripting language interface for the IRC client weechat is pretty awesome:

quote:

As you probably know, there is not really "pointers" in scripts. So when API functions return pointer, it is converted to string for script.

For example, if function return pointer 0x1234ab56, script will get string "0x1234ab56".

And when an API function expects a pointer in arguments, script must give that string value. C plugin will convert it to real pointer before calling C API function.

Empty string or "0x0" are allowed, they means NULL in C. For example, to print data on core buffer (WeeChat main buffer), you can do:

weechat.prnt("", "hi!")
Warning
In many functions, for speed reasons, WeeChat does not check if your pointer is correct or not. It’s your job to check you’re giving a valid pointer, otherwise you may see a nice crash report ;)

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Still nowhere as insane as mircscript.

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

Oh man, an API made of unchecked function pointers. ~What could possibly go wrong?~

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

:stare:

I refuse to believe that this isn't some sort of elaborate joke.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Plorkyeran posted:

Still nowhere as insane as mircscript.

I wrote an entire trivia-based pokemon clone in mircscript.

Two, actually.

I think that's why I feel right at home in C++.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
A homework problem asked students to write a simple function which determines whether a number is divisible by 2 or 3. Some wrote it like this:

code:
(define (div23 v)
  (or
   (equal? 0 (modulo v 2))
   (equal? 0 (modulo v 3))
  )
)
And then there was this approach:



We just started covering recursion in Racket. Can you tell?

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Is this an introductory programming course, or a principles of programming languages course?

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
The latter. Students are mostly third-year CS students with some experience programming in imperative languages, but many have never used a functional language before. My sincere hope is that most of the overly complicated solutions I've seen so far are a result of wanting to show off.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


I know when I want to show off, I write things like "if true then return true else return false."

Zemyla
Aug 6, 2008

I'll take her off your hands. Pleasure doing business with you!

Internet Janitor posted:

A homework problem asked students to write a simple function which determines whether a number is divisible by 2 or 3. Some wrote it like this:

code:
(define (div23 v)
  (or
   (equal? 0 (modulo v 2))
   (equal? 0 (modulo v 3))
  )
)
And then there was this approach:



We just started covering recursion in Racket. Can you tell?
Well, obviously you can do it by determining what the number is mod 6. If it's 0, 2, or 4, it's divisible by 2, and if it's 0 or 3, it's divisible by 3.
code:
(define (div23 n)
  (if (>= n 6)
    (div23 (- n 6))
    (not (or (= n 1) (= n 5)))))
Instead of taking n/2 + n/3 = 5n/6 time, it takes n/6 time, so it's 5 times as fast!

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Internet Janitor posted:

The latter. Students are mostly third-year CS students with some experience programming in imperative languages, but many have never used a functional language before. My sincere hope is that most of the overly complicated solutions I've seen so far are a result of wanting to show off.

Probably they've come to associate functional languages with recursion as in "every solution must involve recursion." :v:

shrughes
Oct 11, 2008

(call/cc call/cc)
But those solutions are iterative.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Not the "solution" I was talking about.

Adbot
ADBOT LOVES YOU

shrughes
Oct 11, 2008

(call/cc call/cc)

carry on then posted:

Not the "solution" I was talking about.

Yes it is. It's iterative.

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