Search posterous

Search all posts and users. Type a name, type a favorite song title, whatever! See what comes up.
  

More posterous blogs











More recommended blogs »

Here are posterous posts filed under coding...

vccv says...

Courtesy of the best startup in the world, I just got a Sprint Mobile USB modem (Sierra Wireless 598U). Of course, once you get a new toy, you have to try it out, so on the way back home, I plugged it in and experienced the novelty of surfing the web while on a moving train. One of the options intrigued me -- it said "click to start NMEA."

What's NMEA, I wondered? Turns out it's a data specification for GPS, sonar, and other devices defined by the National Marine Electronics Association. Even better, it turns out you can actually read data directly from this device from the terminal window:

[vincentc@local ~]$ cat /dev/cu.sierra05 
$GPGSV,3,1,10,03,42,254,29,06,45,240,28,09,18,060,24,14,65,180,26*77
$GPGSV,3,2,10,18,38,057,35,21,29,119,32,22,68,014,29,26,73,097,36*74
$GPGSV,3,3,10,27,14,049,18,19,39,293,*76
 $GPGGA,030642.4,3725.433133,N,12207.936951,W,1,09,1.3,-13.2,M,,,,*0D
$GPVTG,,T,,M,0.0,N,0.0,K,N*2C
$GPRMC,030642.4,A,3725.433133,N,12207.936951,W,0.0,,241109,,,A*5B
$GPGSA,A,3,03,06,09,14,18,21,22,26,27,,,,2.1,1.3,1.6*36
 $PSTIS,*61
....

Each of the lines begins with a code whose meaning can be looked up here. Pretty neat! Seems like it wouldn't be too hard to write a script to parse all of the information. For instance, the two most interesting ones are:

 - $GPGSV tells me which GPS satellites are currently in view

 - $GPGGA tells my current location (3725.433133,N,12207.936951,W or 37d 25.433133' N latitude, 12d 207.936951' W longitude), along with my current altitude

Already pretty interesting and rich data --- not sure exactly what this could be used for, but it's definitely interesting stuff ... and I imagine there could be tons of interesting applications to be made around this data.

Filed under: coding

TechPreacher says...

As announced at PDC 2009, the Microsoft Surface SDK 1.0 SP1 has been released for download at http://www.microsoft.com/surface/Pages/Technical/Learn.aspx.

Surface SDK includes the APIs, documentation, and tools to help you develop Surface touch-enabled applications on your workstation. No Surface unit is required for development and testing, a Surface simulator allows you to test multi-touch input – just attach as many mice as you want touch points - and 2D-barcode / tag recognition.

Before you download the Surface SDK, make sure you read the Setting Up a Development Environment article to learn about the hardware and software requirements for developing Surface applications on a workstation.

Make sure to follow the Surface blog if you are interested in Surface development.

Filed under: coding

Mason says...

It's been a while since I've been so engrossed in an idea that keeps me up late. I've missed this feeling, the thrill of making something real.

Filed under: coding

Yifei says...

On the path of bootstrapping a startup, I’ve had a fair share of experience coding websites and drafting legal documents. These experiences have made me appreciate a side of both activities that I previously hadn’t thought much about:

Creativity within structure.

Coding and contracts are basically just languages – like any other language conceived by people. They each contain their own unique set of nouns, verbs, patterns, and nuances.

But coding and legal-ese are different from most in that they are characterized by extremely rigid formalities and limitations on usage. The purpose of this is to maintain some degree of consistency across each field. 

You might think that a highly structured, uncompromising language takes away the author’s ability to be creative.

(And here’s where my realization comes:)

It doesn’t.

Ask an experienced web developer about “elegant code” and you’ll be treated to a passionate monologue about form and functionality, succinctness, and clean documentation.

I haven’t had a similar conversation with a lawyer (I can’t afford it), but my guess is that there is a similar reverence for the “elegant contract” – the one that uses a few words as possible to deliver the maximum effect, written in language that ordinary mortals can understand.

My present experience tells me that boundaries are actually conducive to creativity. Presented with limitations and challenges, smart individuals are going to find ways to make the best of what they have. And those results can oftentimes be beautiful.

The greater lesson here is that within every craft, there is an art form. 

Within every seemingly mundane chore is a medium for expression.

It's just a choice we each have to make.

Filed under: Coding

vccv says...

Debugging third-party APIs is painful and tedious. Often times, you'll have to inspect all of the parameters passed to the third-party, make sure they're all there, not malformed, located in the appropriate place, etc.. You could monkey-patch your code to spit these parameters out, but this is also painful. Not only do you have to write more code, but often times the parameters are being modified by some other piece of code after you've logged.

What would be nice is a way to spit out the headers on their way out the door over the wire. That way, you're can see what the third-party sees. Found a nice tool called ngrep that does exactly that. It compiled with no problems on Mac OS X in 10 seconds and started running beautifully:

 

vincentc@local ~]$ sudo ngrep -Wbyline -d en1 port 80
interface: en1 (192.168.1.0/255.255.255.0)
filter: (ip) and ( port 80 )
#
T 192.168.1.3:58716 -> 74.125.19.17:80 [A]
 POST /mail/channel/bind?VER=6&it=45250&at=xn3j34m2pyx=j12w3b-8lzkxt&t=1 HTTP/1.1.
Host: mail.google.com.
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5.
 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8.
Accept-Language: en-us,en;q=0.5.
Accept-Encoding: gzip,deflate.
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7.
Keep-Alive: 300.
Connection: keep-alive.
 Content-Type: application/x-www-form-urlencoded; charset=UTF-8.
Referer: htp://mail .google.com/mail/?ui=2&view=js&name=js&ver=suByI-6Q4II.en.&am=!6zf2FVl6CnB3fth99j1pWy.
 Content-Length: 46.
Cookie: GMAIL_LF=1; S=gmail=fM4yyZY0467bXi71KiVpNQ:gmproxy=eRlqhEcR-oT419BlbGUa9g; GX=DQPOGrd680ZqSK5OXwAl13tBJUp_K79Y4Z9eSknff5gzoKH_gIBlQ9lKXRyx5nPHkqziJso6k_QNM6kC5Sy-xQw0mjV8aWYpr-VRObldXWZgqP2GjjQJBwY9UgMw; GMAIL_AT=xn3j34m2pycti4gjvoyvs2tyyxs0hn; gmailchat= PREF=ID=bbd521a14581b7049:LD=en:NR=10:TM=1242260735:LM=1257471614:GM=1:S=GV8TdngB2-ZjTbi8; SID=DAADFz2eJZ3gDFlQHZE_xjVZk59zWPUG_DNwKt1t6
 ##

Filed under: coding

TechPreacher says...

These tutorials are for everyone wanting to get to know Silverlight and Expression Blend quickly.  The tutorials have been created to learn about the features of Silverlight by simply drawing, resizing, dragging and dropping elements on the design surface of Blend. No code or prior Silverlight knowledge needed.

The content is provided at a high-level to cover a wide array of topics in a short time. Links to more detailed information are provided at the end of each tutorial.

1. Drawing an emoticon in Expression Blend
First steps in getting to know the tools and workspace in Blend

2. Element Transformations
Learn to use Scale, Rotate, Skew and 2.5D Transformations

3. Get Started with Animation
A Quick Overview on Creating Time-Based Animations

4. Playing Video with the MediaElement
Using the flexible MediaElement control as a reusable Surface

5. Arranging Pictures to Learn Layout
Use the Grid, StackPanel, ScrollableViewer and Border to position Images

6. A Look at Text in Silverlight
Learn about Displaying Text, Font Properties and Embedding Fonts

7. Import an Adobe Photoshop File into Blend
Convert the assets from a Photoshop file into Interactive Controls

8. Styling and Skinning Controls
Customize the Look by Setting Properties and Building Templates

9. Styling and working with Design-Time Data
Explore how Templates and Bindings are used to display dynamic data

10. Giving Behaviors a Test Drive
A brief overview and walkthrough of the Behaviors included with Blend

Filed under: coding

TechPreacher says...

The Windows Azure Service Management CmdLets are a set of PowerShell cmdlets wrapping the Windows Azure Service Management API. These cmdlets make is simple to script out your deployments, upgrades, and scaling of your Windows Azure applications.

Samples and documentation are available on the download page: http://code.msdn.microsoft.com/azurecmdlets

Filed under: coding

TechPreacher says...

This is the ultimate learning resource, when it comes to Visual Studio 2010 and the .NET Framework 4. Released together with Beta 2 of Visual Studio 2010 and labeled “October Preview”, the training kit contains presentations, hands-on labs, demos and training videos to all topics important to Visual Studio / .NET developers.

 

Download Link

 

This is the complete list of contents as posted by jolson88:

 

Presentations

  • What’s New in .NET Framework 4
  • What’s New in Visual Studio 2010
  • Introduction to ASP.NET MVC
  • Introduction to Managed Extensibility Framework
  • Introduction to .NET RIA Services
  • Introduction to “Velocity”
  • Parallel Computing for Managed Developers
  • Web Deployment with Visual Studio 2010
  • What’s New in ASP.NET AJAX 4
  • What’s New in ASP.NET Web Forms 4
  • What’s New in C# and VB
  • What’s New in ADO.NET Data Services
  • What’s New in Entity Framework 4
  • What’s New in Windows Presentation Foundation 4
  • What’s New in Windows Workflow 4

 

Hands-On Labs

  • Introduction to ADO.NET Data Services
    • Exercise 1: Creating and Consuming ADO.NET Data Services
    • Exercise 2: Consuming ADO.NET Data Services using ASP.NET AJAX
    • Exercise 3: Extending Data Services with Service Operations and Interceptors
    • Exercise 4: Adding Client-Side Paging with Row Count
  • ASP.NET AJAX 4
    • Exercise 1: Leveraging a Client-Side Template
    • Exercise 2: Using the DataView Control
    • Exercise 3: Creating Custom Markup Extensions
    • Exercise 4: Declaratively Instantiating Behaviors
  • Creating Plan My Night – ASP.NET MVC Application
    • Exercise 1: Creating an ASP.NET MVC Application, Plan My Night
    • Exercise 2: Creating Entity Framework Data Model
    • Exercise 3: Adding AJAX For Searching Activities
  • Enhancing Plan My Night – ASP.NET MVC Application
    • Exercise 1: Adding Caching using “Velocity”
    • Exercise 2: Structuring an Application using MVC Areas
  • Introduction to ASP.NET Web Forms 4
    • Exercise 1: Controlling Server Control ClientIds
    • Exercise 2: Enabling Bi-Directional Routing Support
    • Exercise 3: Granular ViewState
  • Microsoft Office Programmability in C# and Visual Basic
  • Introduction to F#
    • Exercise 1: Types in F#
    • Exercise 2: Using the Let keyword
    • Exercise 3: Functions
    • Exercise 4: Lists
    • Exercise 5: Pattern Matching and Recursion
    • Exercise 6: Types and Discriminated Unions
  • Introduction to the Managed Extensibility Framework
    • Exercise 1: Using MEF To Dynamically Add Modules to an Application
    • Exercise 2: Dynamically extending a form
  • Introduction to “Velocity”
    • Exercise 1: Setting up and running “Velocity”
    • Exercise 2: Programming directly against “Velocity” as a generic object cache
    • Exercise 3: Using Velocity’s SessionState provider with ASP.NET
    • Exercise 4 (Optional): Configure “Velocity” Cache in a cluster
  • Introduction to Workflow 4
    • Exercise 1: Hello Workflow
    • Exercise 2: Refactoring Workflows
    • Exercise 3: The CodeActivity
    • Exercise 4: Dynamic Workflows with XAML
    • Exercise 5: Testing Workflows
    • Exercise 6: WorkflowApplication
    • Exercise 7: Adding If/Else Logic
    • Exercise 8: Error Handling
    • Exercise 9: Activity Designers
    • Exercise 10: Hosted Designer
  • Introduction to Parallel Extensions
    • Exercise 1: Parallelize existing algorithm using static Parallel helper class
    • Exercise 2: Create and run parallelized Tasks
    • Exercise 3: Using the Task<T> class to create and run tasks that return a value
    • Exercise 4: Parallelizing LINQ queries using PLINQ
  • Test-Driven Development in Visual Studio 2010
  • WCF Service Discovery
    • Exercise 1: Ad-Hoc Discovery
    • Exercise 2: Metadata Extensions
    • Exercise 3: Announcements
    • Exercise 4: Discovery Proxy
    • Exercise 5: Legacy Discovery
  • Web Development in Visual Studio 2010
    • Exercise 1: Using HTML Code Snippets
    • Exercise 2: Web.config Transformations
    • Exercise 3: Packaging and Deploying Web Applications
    • Exercise 4: Packaging and Deploying Web Applications for IIS
  • Building a Data-Driven Master/Detail Business Form using WPF 4
  • Multi-touch Gesture – MFC
  • Multi-touch WMTouch – MFC
  • Ribbon – MFC
  • Taskbar – MFC

 

Demos

  • ContosoAutomotive (Parallel Extensions + MEF + WPF)
  • AdventureWorks AJAX
  • ASP.NET AJAX Ten-In-One
  • Managed Languages Ten-In-One
  • Barrier
  • CountdownEvent
  • Hello Visual Studio 2010
  • Introduction to the Managed Extensibility Framework
  • Parallel Baby Names
  • Parallel For Loop
  • Parallel LINQ (PLINQ)
  • Parallel Tasks
  • “Velocity”

 

Filed under: coding

TechPreacher says...

At Shape next week I will be presenting on this topic, but if you need the full overview on what’s new for web developers in ASP.NET 4.0 and Visual Studio 2010 Beta 2 – download now if you haven’t done so! – there is a fantastic whitepaper on the subjet at http://www.asp.net/learn/whitepapers/aspnet40/. For offline reading, there is a Word document version available for download.

Filed under: coding

jake says...

Update: renamed mcerlang to erlmc to avoid namespace conflicts with the model checker.

» http://github.com/JacobVorreuter/erlmc

the protocol

The binary protocol was introduced with memcached version 1.3. It provides a more efficient and extensible alternative to the text-based protocol that preceded it. All of the operations supported by the original protocol are available in the new protocol, and for this reason erlmc uses only the binary protocol for client-server communication.

download erlmc

download erlmc-0.2.tgz
  -or-
git clone git://github.com/JacobVorreuter/erlmc.git

unpack and install erlmc

** ensure that memcached is running at this point (>= version 1.3)

 tar xvf erlmc-0.2.tgz
 cd erlmc-0.2
 make
 make test (optional)
 sudo make install 

start erlmc

Open an Erlang shell and start erlmc.

 $jacobvorreuter> erl
 Eshell V5.7.2  (abort with ^G)
 1> erlmc:start().
 ok
 2> erlmc:stats().
 [{{"localhost",11211},
 [{evictions,"0"},
 {total_items,"7"},
 {curr_items,"0"},
 {bytes,"0"},
 {conn_yields,"0"},
 {threads,"5"},
 {cmd_set,[...]},
 {cmd_get,...},
 {...}|...]}]
 

The client will connect with the instance of memcached running on localhost, port 11211 by default. To connect to a different server or multiple server instances you must specify a list of server configurations when starting erlmc:

 1> erlmc:start([{"localhost", 22222, 1}]).
 ok.
 2> erlmc:start([{"localhost", 11211, 5}, {"localhost", 22122, 5}]).
 ok. 

The third element in the server config tuple is the connection pool size (number of open sockets).

basic operations

 3> erlmc:get(hello).
 <<>>
 4> erlmc:set(hello, <<"World">>).
 <<>>
 5> erlmc:get(hello).
 <<"World">>

Uninitialized keys will return an empty binary as will the set operation. Keys can be any Erlang term, however they are converted to strings in the client to allow for hashing over a continuum. Values to be cached must be passed in as binary data.

cache expiration

A third argument can be passed to write operation functions to specify the expiration in seconds.

 6> erlmc:set(abc, <<"def">>, 3).
 <<>>
 7> erlmc:get(abc).
 <<"def">>
 8> timer:sleep(4000).
 ok
 9> erlmc:get(abc).
 <<>>
 

distributed memcached and connection pooling

Distributed caching is done by associating a given key with a server instance running memcached. That association must be consistent so that you only have to perform a lookup on one server to determine if data has been cached for that key. This is done with a consistent key hashing function and a continuum. You can imagine a continuum as being a circle with placeholders for your memcached servers spaced around the edge. Each server instance gets multiple placeholders around the circle (100 is a good number). The distribution is determined in erlmc by hashing the server's host and port and a random number into a 128 bit, unsigned integer:

 1> <<Int:128/unsigned-integer>> = erlang:md5("localhost" ++"11211" ++ integer_to_list(random:uniform(65000))).
 <<101,189,232,82,109,65,199,7,215,240,94,78,204,56,14,55>>
 2> Int.
 135238083730090345086709718695252856375

server placement around the continuum

Here you can see a sample continuum with two servers and two placeholders each. Assume we've generated four keys by hashing the server hosts, ports and random ints and placed them around the continuum based on their values. The 128 bit uints are abbreviated to fit on the image:

If we were to add a third server to the continuum, it might look like the image below. Note that the placement any new servers on the continuum is random and becomes more evenly distributed when more placeholders are used for each server.

using the continuum to determine which server a cache key belongs to

The point of the continuum is to reliably associate a given cache key with a server. The way to do this is to hash the cache key to a 128 bit uint, place that value on the continuum in the correct spot and move clockwise around until the next largest value is encountered. That is the key for the server to use.

 1> <<Int:128/unsigned-integer>> = erlang:md5("zyx").
 <<250,201,126,87,150,57,190,63,16,219,103,26,68,98,237,145>>
 2> Int.
 333353213137747226088668276759233490321 

In the example above we've hashed the key "zyx" to the number 333...321 and placed that on the continuum. We then move clockwise around the continuum to find the next server, which happens to be "localhost" 11211 in this case. That is the server that we map the "zyx" key to.

So let's fire up another memcached server instance on a different port and try some distributed caching:

 $jacobvorreuter> memcached -d -m 1024 -p 22122 -l localhost
 $jacobvorreuter> erl
 Eshell V5.7.2  (abort with ^G)
 1> erlmc:start([{"localhost", 11211, 1}, {"localhost", 22122, 1}]).
 ok
 2> erlmc:stats().
 [{{"localhost",11211},
 [{evictions,"0"},
 {total_items,"0"},
 {curr_items,"0"},
 {bytes,"0"},
 {cmd_flush,"0"},
 {cmd_set,[...]},
 {cmd_get,...},
 {...}|...]},
 {{"localhost",22122},
 [{evictions,"0"},
 {total_items,"0"},
 {curr_items,"0"},
 {bytes,"0"},
 {cmd_flush,[...]},
 {cmd_set,...},
 {...}|...]}] 

The erlmc:stats/0 function will return a proplist of [{{Host, Port}, Stats}].

 3> erlmc:set("abc", <<"abc">>).
 <<>>
 4> erlmc:set("zyx", <<"zyx">>).
 <<>>
 5> erlmc:stats().
 [{{"localhost",11211},
 [{evictions,"0"},
 {total_items,"1"},
 {curr_items,"1"},
 {bytes,"64"},
 {cmd_set,[...]},
 {cmd_get,...},
 {...}|...]},
 {{"localhost",22122},
 [{evictions,"0"},
 {total_items,"1"},
 {curr_items,"1"},
 {bytes,"64"},
 {cmd_flush,[...]},
 {cmd_set,...},
 {...}|...]}] 

Now, if we set two keys there's a 33% chance that they'll be distributed between the two servers. We can see in the output above that the stats function returns a total_items value of "1" for both servers. Success!

Documentation for erlmc is available at http://github.com/JacobVorreuter/erlmc

Filed under: coding