All My Brain Where stuff from my brain lands

October 1, 2014

Site Dust…

Filed under: Web — Dennis @ 8:18 am

Been years since I updated things on this site. I thought I’d take a bit and get a new theme.

Pardon the dust for a bit while I work things out. Feel free to contact me if something on the site isn’t working and you need it to 🙂

August 29, 2014

Slow site lately

Filed under: System Administration — Tags: , , — Dennis @ 9:04 am

Over the last few weeks I noticed this site becoming steadily slower. Turns out I had an unusual amount of requests for /xmlrpc.php.. which in turn caused the server to use up all it’s http processes answering bogus rpc queries for ping backs and whatnot that the nice script kiddies all over the world are trying to exploit I guess.

So… took care of that. Hopefully things are back to normal. I’ll have to go back and re-evaluate if I actually want any of that functionality I guess.

August 1, 2014

3d printing services in American Fork

Filed under: 3d printing — Tags: — Dennis @ 9:26 pm

So the last project I worked on at work required some hardware enclosures, handles and a couple odds and ends that we decided to design ourselves and 3D print. So lucky me, I’ve entered the 3D printing arena. Been having enough fun doing it that I’ve started offering printing services to the local market.

My MakeXYZ Profile
My 3d hubs Profile
My Thingiverse Profile

June 6, 2014

Writing binary data with Verilator

Filed under: Programming — Tags: , , — Dennis @ 11:31 am

This is definitely one I know the masses are waiting to find out how to do. 🙂

So you are simulating a verilog design with Verilator and you want to output part of your design data to a file in binary format. (Example you’re outputting an image.)

So lets say you want to do this:

fd=$fopen("somefile.dat", "wb");
$fwrite ( fd, "%c", data );

And you expect a file with binary data but instead you get a text file.

Well in Verilator you can embed c statements. So you can do this instead:

$c( "fwrite( (void*) &", data,", 1, 1, (FILE*)", fd, ");" );

There. Fixed.

September 26, 2013

Printing on one line with Python

Filed under: Programming — Tags: — Dennis @ 9:54 am

Ok so I’ve been using Python for a long time and have written a lot of lines of Python code. But this one is pretty simple and I’m kind of embarrassed that somehow I didn’t know about it.

In the past, I’ve used sys.stdout when I wanted to print multiple things on one line, e.g., you want to print periods to show progress.

import sys
for i in range (10):
 sys.stdout.write ( "%d.." % i )

I also knew you could use print with more than one item.

print 1,2,3, "Hi"

But the other day I inadvertently found that you can continue to print on one line if you just leave the trailing comma….

for i in range(10):
  print "%d.." % i, # no newline appended
print # add a newline after the loop.

And who cares you say??? Well now I don’t have to import sys and use sys.stdout when a simple print can do just fine 🙂

March 6, 2013

Fun with C++11 Lambdas

Filed under: Programming — Tags: , — Dennis @ 1:26 pm

So I got a c++11 book. I’ve been following a few of the language differences and features for a while, but I decided to break down and actually understand it all. I decided to have some fun with lambdas today. Lambdas are a very useful language feature that lots of dynamic languages have (JavaScript, Python, <insert your favorite there is plenty>). For some additional readying you might read about Closures and Functors.

Anyway, so here you go:

Basic syntax

[...] {...} // simplest form
// or showing all the optional arguments
[...] (...) mutable throwSpec -> retType {...}

What does that all mean?

The brackets are a parameter list of values you can pass in for usage in the lambda from the context in which the lambda is being created. You could pass in local variables or this for instance. You can pass by a value or reference. Unlike other languages, if you pass by reference and the value is deleted, your lambda might have unexpected results or crash.

The parenthesis are the parameters you pass in when you call the lambda. Declared like a parameter list for any other function. auto is nice but if you need the type (like to return a lambda from a function) you can use the functional header.


using namespace std;

function getTheLambda()
    int x=7;
    // will return an undefined value because x is going to be removed from
    // the stack when this function exits.
    return [&x] (int a, int b) { return x+a+b; };

int main(int argc, char* argv[])

    auto m = [] (int y) { cout << "lamda value: " << y << endl; };
    // call it

    auto l=getTheLambda();
    cout << "Lambda Result: " << l(1,2) << endl;

    return 0;

For me it printed:

lamda value: 3
Lambda Result: 32770

If you change the first lamba in the function to "x" instead of "&x" you'll get the expected result of 10.

I can't wait to pass a lambda to a thread and use it as some type of callback!

« Newer PostsOlder Posts »

Powered by WordPress

%d bloggers like this: