Note-to-self:

ffmpeg -i input.mp4 -x264opts keyint=15:min-keyint=15 -c:v libx264 -preset slow -crf 22 output.mp4

Links:

Tagged with:  

HomebrewThe water report for Thornton, CO doesn’t contain all the information you need to properly adjust your water for home brewing. Fortunately, the water analysts for the city are very helpful. Here is an excerpt from the response I got when I asked for more details:

The City of Thornton does in fact have two separate water sources and we don’t always use both so the character of your water can actually vary a bit throughout the year. Thornton owns a significant share of the water in Standley Lake in Arvada. This water comes from Clear Creek. The Coors Beer commercials are accurate. This water is very clean and low in pollutants as I will summarize below.

Our second water source is the South Platte River. We divert water from the South Platte and store it in our gravel lakes until it is needed. While still better than many water sources, The South Platte is certainly exposed to more contaminants then our Standley Lake water.

In most years, water is drawn from Standley Lake nearly all year – only ceasing for maintenance to the treatment plant. Meanwhile, water from the South Platte is used to supplement our supply when demand spikes in the summertime.

Typically, we start using South Platte water in March and we might stop using it around October or November. This year we turned off our South Platte supply in late September, so the City is currently receiving only Standley Lake water. It is difficult to guess what ratio of our two water supplies you might receive at your residence when we do utilize both sources.

Now that you know the reasons behind the variability in Thornton’s water quality, I’ll throw several numbers at you which should represent your water quality at different times of year. These values were measured at a residence near your location that we sample year round. This residence is located near [redacted]. All values are in ppm:

Standley Lake (Winter) – Both (Summer) – South Platte Only
Calcium 56.3 85* 97.1
Magnesium 8.4 14* 18.1
Total Hardness 152 276 280
Calcium Hardness 100 200 236
Sulfate 51 92* 137
Chloride 36 76* 74
Bicarbonate 52.1 139.2 173.4

* = estimates based on the average of both sources during this time frame

Hopefully that’s enough detail to answer your questions. If you have any more questions or need more specific data certainly let me know and I’d be happy to help.

Tagged with:  

I wanted to play with Django recently, so I needed to enable python support in lighttpd. I found a few links about using the default lighttpd.conf file, but I have a custom (minimalist) lighttpd.conf file that I don’t want to pollute with unnecessary options. It turns out that enabling python support through mod_cgi is quite trivial:

1. Open lighttpd.conf

2. Add ".py" to the static-file.exclude-extensions variable to prevent people from viewing the raw python code:

static-file.exclude-extensions = ( ".py" )

3. Add "mod_cgi" to the server.modules variable:

server.modules = ( "mod_cgi" )

4. Add the association between *.py files and the python interpreter to the cgi.assign variable:

cgi.assign = ( ".py" => "/usr/bin/python" )

5. Make sure you have a “breakage” log defined… this helps debugging because python errors will get written here:

server.breakagelog = "/var/log/lighttpd/breakage.log"

6. Restart lighttpd

For more mod_cgi configuration options, read this.

 

There are a few ways on linux to see if the network stack is dropping packets, or just having problems in general:

1. ifconfig

 ... 
 RX packets:522 errors:0 dropped:0 overruns:0 frame:0
 TX packets:406 errors:0 dropped:0 overruns:0 frame:0
 ...

2. cat /proc/net/dev

Inter-| Receive ... 
 face | bytes packets errs drop fifo frame ... 
 eth0:  87689 785 0 0 0 0 ...
 ...

3. cat /proc/net/udp

 so local_address rem_address ... drops
 277: 00000000:0044 00000000:0000 ... 0 
 ...

4. cat /proc/net/snmp

...
Tcp: ...
Udp: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors
Udp: 453 0 0 452 0 0
...

You can also see this on a per-process basis using cat /proc/<pid>/net/{udp,dev,snmp}

Check out iftop also.

 

Ebonicode++: Hackin C++ Gangsta Style

On December 3, 2011, in Code Monkey, by Tom

A little part of me died doing this to Bjarne, but I couldn't resist.

“Foshizzle” is a modified version of the Clang compiler which supports Ebonicode++ (an alternate C++ syntax). Foshizzle supports all the existing features of Clang, but with extensions to more fully express your gansta style. All the regular C++ syntax still works, but you can now substitute Ebonicode++ keywords and operators (see below).

Here’s a sample method that calculates factorials (Note: the semicolons can be replaced with a certain expletive):

int factorialz(int n)
{
    int rezult be 1;
    slongas (n bepimpin 0)
    {
        rezult be rezult dimes n;
        dissin n;
    }
    putou rezult;
}

 

I can’t take all the credit. I was inspired by the Iowa State students that first created Ebonicode (webpage no longer available).

Here are my Clang modifications: ebpp-clang30rc4.patch

Build instructions are near the end of this post.

Continue reading »

Tagged with:  

Adding stdint.h to Visual Studio

On November 13, 2011, in Code Monkey, by Tom

Yes, stdint.h and inttypes.h are missing from Microsoft Visual Studio. As a result, anyone who’s written cross-platform C\C++ code for Windows has probably seen this error:

error C2146: syntax error : missing ';' before identifier 'foo'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

The fact is that Visual Studio doesn’t implement C99… it implements C89 (for compatibility reasons). So, you don’t have access to familiar types like:

  • int8_t, int16_t, int32_t, int64_t
  • uint8_t, uint16_t, uint32_t, uint64_t
  • INT8_MIN, INT8_MAX, etc
  • The fprintf macros PRId32, PRIu32, etc
  • strtoimax(), etc

Fortunately, Alexander Chemeris has written msinttypes: an implementation of stdint.h and inttypes.h for Microsoft Visual Studio. It is licensed under the BSD license, so the headers are actually usable commercially (no viral GPL). This following quote probably goes without saying (emphasis mine):

Note though, that just adding these headers does not make Visual Studio compiler fully C99 compliant.

This project has saved me a bunch of unwanted coding. Thanks Alex!

Tagged with:  

Here’s a video done by Ed Catmull (founder of Pixar) in 1972 while at the University of Utah. It’s purported to be the first digitally rendered film. It’s just amazing how far we’ve come since these early pioneering days.

The math that we take for granted for rendering 3D was being invented, real time, to create this video. (Ed’s credited for having working out that math to handle things like texture mapping, 3D anti-aliasing and z-buffering.)

The story behind the video and how it was found recently is pretty cool too. Props to Robby Ingebretsen for sharing this!


40 Year Old 3D Computer Graphics (Pixar, 1972) from Robby Ingebretsen on Vimeo.

Tagged with:  

Here’s a great interview with Microsoft Technical Fellow and author of the CLR garbage collector, Patrick Dussud.

How does GC, work, generally? Why is it important? The GC inside of the CLR is of a specfic type – ephemeral, concurrent (the server version has always been concuurent and now with Background GC on the client in CLR 4, GC is concurrent on the client as well, but there are differences…)

Tagged with:  

Thomas Becker has a great article explaining C++11′s rvalue references and how they allow move semantics and perfect forwarding.

I particularly liked his summary of the 3 things you need to remember about rvalue references:

  1. By overloading a function like this:
    
    void foo(X& x); // lvalue reference overload
    void foo(X&& x); // rvalue reference overload
    


    you can branch at compile time on the condition “is foo being called on an lvalue or an rvalue?” The primary (and for all practical purposes, the only) application of that is to overload the copy constructor and copy assignment operator of a class for the sake of implementing move semantics. If and when you do that, make sure to pay attention to exception handling, and use the new noexcept keyword as much as you can.

  2. std::move turns its argument into an rvalue.
  3. std::forward allows you to achieve perfect forwarding if you use it exactly as shown:
    
    template<typename T, typename Arg>
    shared_ptr<T> factory(Arg&& arg)
    {
        return shared_ptr<T>(new T(std::forward<Arg>(arg));
    }

I also like his definition of lvalues and rvalues in the introduction:

The original definition of lvalues and rvalues from the earliest days of C is as follows: An lvalue is an expression e that may appear on the left or on the right hand side of an assignment, whereas anrvalue is an expression that can only appear on the right hand side of an assignment.

In C++, this is still useful as a first, intuitive approach to lvalues and rvalues. However, C++ with its user-defined types has introduced some subtleties regarding modifiability and assignability that cause this definition to be incorrect. There is no need for us to go further into this. Here is an alternate definition which, although it can still be argued with, will put you in a position to tackle rvalue references: An lvalue is an expression that refers to a memory location and allows us to take the address of that memory location via the & operator. An rvalue is an expression that is not an lvalue. 

Tagged with:  

Connecting Linux to a Cisco VPN server using a PCF file is easy (even from within a VirtualBox virtual machine). First, I wouldn’t bother with Cisco’s Linux client… especially if you are running 64bit. You have to patch a source file and mod the Makefile. Using VPNC is so much easier.

NOTE: I only had the PCF file provided by work, and the group password was encrypted. If you know your group password, then you can just run VPNC directly or write a conf file yourself.

My setup:

  • Fedora 12 x86_64
  • Running in VirtualBox 4.1.6 with bridged networking (I didn’t try it with NAT)
  • Connecting to a Cisco VPN server at work

Connecting:

  1. Install VPNC (`sudo yum install vpnc` in Fedora)
  2. Download the pcf2vpnc Perl script (cached)
  3. Convert your Cisco PCF file to VPNC conf format: `perl pcf2vpnc company.pcf vpnc.conf`
  4. Connect to the VPN server: `sudo vpnc ./vpnc.conf` (you will be prompted for you username and password)
  5. (optional) Run `ifconfig` to see the tunnel interface that was created
eth0     Link encap:Ethernet  HWaddr 08:00:DE:AD:BE:EF
         inet addr:192.168.1.10  Bcast:192.168.1.255  Mask:255.255.255.0
         ...

lo       Link encap:Local Loopback
         inet addr:127.0.0.1  Mask:255.0.0.0
         ...

tun0     Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
         inet addr:10.200.100.1  P-t-P:10.220.116.219  Mask:255.255.255.255
         ...

Disconnecting:

  1. Run `sudo vpnc-disconnect` (don’t forget the `sudo`)

That’s it. Cheers!