Skip to main content

Posts tagged with 'c'

Using Azure blob storage

March 06, 2014 mgroves 0 Comments
Tags: azure blob csharp

Even though I've been using Windows Azure for quite some time, a lot of the functionality is unexplored territory to me.

Recently, I took a look at Azure Blob Storage, and I was surprised by how simple it was.

Blob storage is simply a way to store stuff (mainly files). That's about the long and short of it. Here's how to get started:

  1. Create a new storage service: on your dashboard, click "+ NEW", then Data Services, then Storage. Pick a URL subdomain, region, and subscription. There you go.
  2. In that service, create one or more containers. This is basically an organizational structure, kinda like a folder. Containers can be public or private.
  3. Put stuff in the container. Each item of "stuff" in this container is called a blob, and each of these items have their own URL.

I don't know of a way to directly upload blobs right from the Azure control panel (yet), but it's very simple to do with some C#. Just add Windows Azure Storage to your project with NuGet (Install-Package WindowsAzure.Storage).

You'll need to create a "connection string" to your storage service. The connection string is just:

DefaultEndpointsProtocol=https;AccountName=yourServiceName;AccountKey=yourAccountKey

Where yourServiceName is whatever your named your service. yourAccountKey can be grabbed right from your Azure Dashboard. Click on the service name and then click "Manage Access Keys" at the bottom of the screen. Copy "Primary Access Key" and paste it in there.

Now you're ready to write some C#. Here's a simple class that I wrote that lets you check for existence of a blob (by name), upload a new blob given a name and a stream (from a file uploaded to a web site, for instance), and a way to delete a blob (again, by name).

It's really that simple. Once you upload some files, go back to your Azure Dashboard and take a peek in the container. You'll see all the blobs there, as well as URIs to get to them.

It's so easy, that I've already moved the images for this site (Cross Cutting Concerns) over to Azure Storage (previously I was storing them off-site with traditional hosting).

Windows Azure dashboard blob container

Some drawbacks that I've noticed, and how I dealt with them:

  • You can get a List of blobs using WindowsAzure.Storage, but you can't really get a total count (at least not without iterating through the whole list). So if you are building a tool to manage these blobs, you may need to store some metadata (like name, uri) in a local database or something (which is what I did for this site). I believe there are already a bunch of tools out there to access containers/blobs that you can use as well: you don't have to build your own.
  • There's no "transaction" or "rollback" when doing blob transactions. You'll need to handle that case yourself. In my case, if something goes wrong with other parts of the "transaction", I'll use DeleteIfExists to remove the blob. Not the most elegant, but it works.

 

Welcome to another "Weekly Concerns". This is a post-a-week series of interesting links, relevant to programming and programmers. You can check out previous Weekly Concerns posts in the archive.

It's Seth Petry-Johnson's birthday this weekend. That doesn't really tie into this week's Weekly Concerns, but I guess you could check out Seth's blog! It will also be David Giard's birthday as well: you should check out his excellent Technology and Friends podcast/TV show. Episode 144 is particularly good.

If you have an interesting link that you'd like to see in Weekly Concerns, leave a comment or contact me.

Web accessibility: contrast

February 28, 2014 mgroves 0 Comments
Tags: html accessibility

I took a look at an issue submitted to an OSS project relating to contrast. The submitter of the issue claims that the text is hard to read on the Safari web browser. I looked at it in Chrome as well as Safari, and it looked roughly the same. Here it is:

Potentially low contrast text in Safari

Does that look hard to read? To me, I can definitely read it, no problem. But that's a rather selfish point of view: not everyone has the same ability to see as I do. We often hear about making web sites more accesible for users with screen readers (for the blind), but this is a case where it might be fine for someone with very healthy vision, and it might be fine for someone with no vision, but it might not be okay for someone with low vision.

So, I could just ask my Twitter followers what they think, but it would nice if I had a more concrete, objective way of knowing if this issue needs fixed or not. The W3C contrast ratio guidelines (pointed out to me by Jon Plante) gives me that concrete guideline to follow: a contrast ratio of at least 4.5:1. WebAIM's Color Contrast Checker makes it easy for me to do the math.

I opened up the above screenshot in an image editor1, and used it to figure out what the background and foreground colors are (MS Paint can do this, though you'll have to do the decimal-to-hex conversion yourself). The background color is #EFEFEF and the (main) foreground color is #B1B1B8. Here are the results:

WebAIM's Color Contrast Checker showing a failure

So, yes, this issue definitely has merit, so I submitted a pull request to NuGetGallery.

1In many cases, you can simply look at the CSS, but since this markup was in a disabled textbox, the browser actually dims the color. Hence the reason I needed to use an image editor.

 

Welcome to another "Weekly Concerns". This is a post-a-week series of interesting links, relevant to programming and programmers. You can check out previous Weekly Concerns posts in the archive.

  • If you are having trouble understanding how SQL joins work, check out this diagram on SQL joins for a useful visualization.
  • Sometimes it's hard keeping up with security issues with all the software you have installed on your computer(s). I've been using the (free) Secunia PSI (Personal Software Inspector) for years--it keeps me up-to-date on the latest security exploits and can automatically update your software for you.
  • TwitchPlaysPokemon - an experiment to "crowdsource" gameplay. Imagine 60,000+ people using the same controller. This is interesting for its entertainment value, of course, but also a study of emergence. A critic of emergence might point to this as a failure. But I think it demonstrates that emergence might not work if there aren't any real constraints. If each user was limited to maybe one command (per hour, maybe), or there was some sort of majority vote on each command, or some constraint like that, I think the resultant gameplay would be much more interesting. As it stands now, it's probably not any different from just randomly hitting buttons. EDIT: As of today, there is a "democracy/anarchy" feature that allows users to introduce constraints, which appears to be making the game run much smoother.
  • Maybe RSS is going out of style, but I still use it every day. If you wish a web site had an RSS feed, but it doesn't, you might want to check out Feed43 (Feed for Free). It's a scraping tool that I use from time to time when nothing else is available. And remember that Cross Cutting Concerns has an RSS feed.
  • More Pete on Software, as he continues his blog series on PostSharp. This time he explores the automated design patterns feature for background threading that comes with the full commercial version of PostSharp.

If you have an interesting link that you'd like to see in Weekly Concerns, leave a comment or contact me.

I was listening to Econtalk (again). This time the guest was Anthony Gill on the topic of Religion. He brought up a well-known quote quote: "I don't know how Nixon won. I don't know anyone who voted for him". This quote was used to demonstrate the same principal that applies when academic economists don't think that a topic like religion is worth studying.

(By the way, that quote is often attributed to Pauline Kael, but it is somewhat apocryphal).

However, I thought the quote was very interesting, and something that I think can definitely apply to anyone (not just politicians and economists), including developers. It's quite easy to get caught up in the same sort of technological provincialism. Since I've worked with Microsoft tools for most of my career, I've worked with lots of other people who've also worked with Microsoft tools for most of their career. I could easily dismiss Java or Ruby or PHP or whatever with an attitude of "I don't know anyone who uses it, therefore it must not be important".

This phenomenon has its own logical fallacy: the "hasty generalization" or the "unrepresentative sample". It can even take the form of something more ugly like fanboyism or, shall we say, "overly optimistic" viewpoints about technology. I don't want to start a flame war, but I'm sure you can think of a few technologies or products that might apply.

I know that I'm not immune to this phenomenon, but I've tried to take steps to combat it.

First, I'm a heavy Twitter user (follow me @mgroves!). My goal is to follow as many developers as I can in my region of the world (midwest USA). Not just .NET developers or web developers, but any developer: Java, Ruby, COBOL, MUMPS, FoxPro, ColdFusion, anything. I believe that every developer has something that they can teach me, no matter what tool they do their job with. I've often called the people I follow on Twitter my "140 character mentors". I don't agree with everybody. I occassionally groan when I see things tweeted about politics or religion or technology (or whatever) that I don't agree with. But I'd rather be challenged and uncomfortable than stagnant.

Second, I go to conferences and make an effort to talk to people I've never met before and go to sessions that are outside my area of expertise. This has exposed me to all kinds of awkward and/or shocking conversations (ask me about how I first met @PerryNeal sometime), but every new person or new topic can be an opportunity for me to improve, even in a small way. This is especially true at conferences like CodeMash that aren't organized around a specific technology or a specific vendor.

To wrap up: there's a whole world out there outside of your own technology's borders. You don't have to emigrate there, but you can learn something by travelling abroad every now and then.

Edit: I wrote this post before I learned about the passing of Jim Weirich, but I wanted to make special mention of him here. Jim was often considered a "Ruby" guy, but his knowledge and interest expanded far beyond that technology. By attending his sessions, I learned about some advanced ideas of OOP from him and from a book he recommended (What Every Programmer Should Know About Object-Oriented Design), as well as feeling comfortable with Git for the very first time through a live workshop in which he used Git Immersion. I think of him every time I read the book and every time I use Git, and I think he stands as a shining counter-example to the phenomenom I described in this blog post.

Matthew D. Groves

About the Author

Matthew D. Groves lives in Central Ohio. He works remotely, loves to code, and is a Microsoft MVP.

Latest Comments

Twitter