News for hackers. Stuff that matters.

codehero

Re:Named parameters in C on Monday July 14, 2014 @12:08PM (#8031567)
That is really cool.

Combine this with struct definitions in function bodies and I see a great teamup with variadic functions.

Take a theoretical struct_printf, which prints out non promoted data with struct packing (not variadic stack packing, which requires type promotion)

  /* Only uses va_start and va_arg to*/
  void struct_printf(const char* format, ...){
  ...
  }

  void print_foo(){
    struct foo_t{
      float f;
      uint16_t u2;
      uint8_t x;
    } input;

    struct_printf("No type promotion here: %f %hu %hhx\n",
     (struct foo_t){ .f = 0.1, .u2 = 1000, .x = 0xF2});
  }
Now we can actually pass what we mean to pass without the compiler changing it.

NOTE: After I wrote this I'm not actually sure what va_args does with a struct or how to get a pointer to the first member...

Re:Busting Modern Hardware Myths (2013) on Saturday June 28, 2014 @08:41AM (#7958047)
In Myth 4 SSDs, Thompson claims that:

"there's a limited number of times you can READ and ERASE a block" (emphasis mine)

My understanding is that ERASE cycles are what's limited; reading and writing are not destructive to the flash.

Re:Analysis of Quirky: Do Consumers Know What They Want? on Wednesday June 11, 2014 @02:17PM (#7879520)
So let's look at this from an inventor's perspective:

Feeling exuberant, I know Quirky will vet and accept my idea. According 109 of 823 accepted projects are on sale, so I have a 13.24% of getting my first dollar. Royalties are paid out to contributors on 10% of gross revenue. The idea originator automatically gets 40.5% of this revenue. So I would get a 4.05% royalty. Products are approximately $30, so my per unit royalty is ~$1.20

Let's say my cost for well thought invention idea is $1000 (includes time, drawing, cardboard prototypes, etc). Looking at the spreadsheet attached to the blog the average total units sold per product is 28378. However, this is a heavy tailed distribution, so we'll make two estimates (from eyeballing the spreadsheet, I divided the total units sold range into 1/3)

a 33% chance they will sell 500 units a 33% chance they will sell 5000 units a 33% chance they will sell 50000 units

So expected sales will be

$1.20 * (1/3 * 500 + 1/3 * 5000 + 1/3 * 50000) = $22000

So my expected value on idea submission is

(1 - 0.1324) * -1000 + 0.1324 * (22000 - 1000) = $1912.80

So I can expect to make about $2000 for a product idea on Quirky. Don't hold back any criticism on this analysis.

I don't understand where the 2072 mile figure came from. The Shell competition was only 16km. And why describe fuel economy in miles per liter?
Re:New Creative Tools on Instagram on Tuesday June 03, 2014 @03:51PM (#7842336)
They could inspire creativity by letting me upload photos from my desktop...
Re:Tindie says forget Kickstarter on Tuesday May 06, 2014 @10:10PM (#7708265)
Some questions:

Tindie Fundraisers just seem to have disappeared; what happened to them?

How do you regulate the marketplace competition? Do you let overseas companies copy a maker's product and sell it for a lower price?

Doesn't work when Vimium extension is enabled...though this project makes we want to disable it.
For I client I designed a UART<->Microphone adapter. It supports bidirectional communication at ~1kbps, almost 0% error rate at full volume (~15% error rate at half) and has a terribly unoptimized analog interface. I didn't really think there was much interest in creating these kinds of interfaces, but if anyone has any good ideas I am all ears.
Re:JSON5 is a proposed extension to JSON on Saturday March 01, 2014 @04:27PM (#7326196)
I couldn't tell, does the Numbers support include NaN?
Network routing is directed flow; water flow is undirected, so backflow is possible. The dangers of analogy....
Re:Vim3D – A new 3D vi clone [video] on Wednesday December 11, 2013 @08:02AM (#6887407)
I'd like to see it do CSG before I download it.
Re:ECMA-404: The JSON Data Interchange Format [pdf] on Friday October 11, 2013 @12:37PM (#6534189)
This is why you prepend the comma before every succeeding item in a list or map.
Would online students have access to paywalled research papers?
Since the days of the EspressoPC I have always been fascinated by small scale computers. With so many choices in small linux systems (Gumstix anyone?) I am not enchanted with seeing the Arduino name slapped on a Linux board. I was appalled at how digitalWrite was actually implemented, so I cannot imagine what kind of layers they put between the programmer and the metal.
Re:Pitfalls in C and C++: Unsigned Types (2011) on Wednesday September 25, 2013 @02:39PM (#6446427)
I've definitely been bitten by this kind of bug before, but I did not come to this author's conclusion. What I learned is that each step of a calculation has lower and upper bounds, regardless of int type. You always make sure your inputs, intermediates and products fall within these bounds. Consequently, the author's advice becomes irrelevant.
Re:Nvidia to release documentation on Nouveau project on Tuesday September 24, 2013 @07:00AM (#6437112)
Philip Katz of PKZip fame (may he RIP)
Re:Peachy Printer - The world's first $100 3D Printer on Saturday September 21, 2013 @04:56PM (#6424496)
I really like it and its entirely analog nature is refreshing. It makes sense to set aside something like a raspberry pi for it (I would never use a PC, especially on update tuesdays. And I would not want to set my PC audio to full blast so the output swings the full +-2.5V).

Mechanically delicate though. Vibrations disturbing the surface of the liquid will skew the print and cause poor layer adhesion. And you have to make sure your surface is perfectly level.

Re:Tny: A simple data serializer in C on Saturday September 21, 2013 @12:13AM (#6421962)
My point is that people expect malloc to optimize more than it really should. I don't have the time to explain anything more to you. Look at how malloc uses the brk() function and read up on TLBs. That should get you some depth.
Re:Tny: A simple data serializer in C on Friday September 20, 2013 @11:56PM (#6421936)
Jsmn is a fresh (somewhat copout) approach, but unless you know the size of your JSON a priori (ie memory mapped file), I would hard call it beautiful or without global side effects.

If you're into C++, take a look at benejson's pull parser. There is a C core but its presently very ugly and only intended for library, not application developers.

http://codehero.github.io/benejson/

Re:Tny: A simple data serializer in C on Friday September 20, 2013 @11:28PM (#6421869)
Help me get on the same wavelength as you. Maybe you can tell me what is "sporadic" about Tny's malloc usage? I don't understand your second question at all.

Optimizing the usage of malloc and free is no different than optimizing the run time of any algorithm. The only difference is people believe they can just abstract allocation away and rely on somebody else's code to handle it.

Re:Tny: A simple data serializer in C on Friday September 20, 2013 @09:21PM (#6421534)
I think it's interesting and I get that it's a simple data parser, but if I am using C I prefer performance over simplicity. The Tny structs and their string values are individually malloc'ed, worsening the performance, so allocation and deletion is a slow process. Of course he's not the only one to do this, yajl2 also makes liberal use of malloc and free when building its node tree. One good thing to say is at least his encoding format distinguishes floats from integers and accounts for NaN and Infinity values.

A first step to improving this library would be to add a SAX style parser so I could build my own representation.

Thanks for the response. Hearing a real world example of a type promotion trap was illuminating.

I pick on printf in particular because most seasoned programmers consider copying and pasting code a smell, but is accepted for printf and friends.

Most of these are all just implementation or platform divergence issues, though what was the FPU emulator issue? That actually seems fundamental to formatted output strategies.
I don't know if that's the reason, but there's no reason formatted output HAS to:

1) block at the caller, ever

2) have its data parameters pushed onto the stack

3) print all or nothing to a single buffer

4) identify the data type or modifier by the first letter of its English name (int, long, etc)

5) have its core modified to add functionality

I know the scope of your project isn't to break ground on formatted output. I've seen the same thing you've done in fastcgi. and in nginx. A pattern that recurs because printf is a clunky interface. And of course each copy has its own little syntax variation. But people accept the printf approach because they were indoctrinated, starting from "Hello World". I know there's something better out there.
Why is it every framework handling run loops or communication makes its own implementation of printf? While printf is ubiquitous, I'd hardly call its semantics or syntax perfect. Why does everyone have to copy the same mistakes over and over again?
Re:Adafruit's Trinket on Friday September 06, 2013 @08:47PM (#6343474)
The g2231 etc certainly are not specced to work from high frequency crystals or oscillators, but in actual use it works:

http://forum.43oh.com/topic/594-use-a-12mhz-external-square-...

Older »