RSSAmplifier

Blog

The Blog of Dan Esparza

Recent content on The Blog of Dan Esparza

danesparza.netRSS feed ↗40 posts

Latest posts

Using Go's json.Number to Handle Quoted and Unquoted Numbers in JSON

When working with JSON in Go, it’s common to encounter numeric values represented both as numbers and as strings. This inconsistency can lead to issues during unmarshaling, as Go’s encoding/json package expects a consistent type. Fortunately, Go provides the json.Number type to handle such scenarios gracefully. The Challenge Consider the following JSON snippets: {'value': 123}…

Use Branches With Go Modules

When developing with Go on a team, it is useful to have a good branching strategy so you can work together as a team and not tromp on each others changes. But how do you use Go modules with a branching strategy? It’s easy to refer to another project (even at a certain version) – but branches seem to offer a bit of a challenge. The official guidance involves using the specific commit…

A modern Javascript workflow

Let&rsquo;s talk about your development workflow. If you&rsquo;re still including all of your scripts in your pages using a <script> tag, you&rsquo;re doing it wrong. A modern front-end workflow includes some kind of dependency management solution, and some kind of bundling / minification process. Prereqs: Package management and Git console npm Even if you don&rsquo;t use Node.js for your server…

NuGet tips

Created in 2010, NuGet is a free and open source package manager for the Microsoft development platform. NuGet has become the defacto way of distributing tools and libraries in the Microsoft developer community. If you&rsquo;re interested in working with NuGet, here are some tips and tricks that will be helpful to you. Creating NuGet packages Creating NuGet packages from scratch can be daunting…

Use Keepass and dropbox to manage your passwords

Interested in using a password manager for all your passwords? You should be. Services like OpenId are catching on, but aren&rsquo;t as widespread as originally hoped. You might visit hundreds of different sites a year that use a login and password. Using the same password for every website and service is a terrible idea: A hacker just needs to compromise one of the services you visit and…

Using Windows Authentication with IISExpress

I do a lot of development with websites in Visual Studio 2013 nowadays. I&rsquo;ve discovered that in order to use IISExpress with Windows Authentication, I had to jump through some hoops. You may find yourself banging your head on the wall trying to get IISExpress to work with Windows auth &ndash; so here are few tips for you. Update your web.config Make sure your web.config file both enables…

Things your Dad never told you about NLog

I&rsquo;ve had cause to work with NLog a lot lately. In working with it, I have discovered some surprises and tricks that I thought I would share. Log levels matter You should think carefully about your log levels as you start adding logging to your app. Trace should probably be used sparingly, because when you turn on log level &lsquo;Trace&rsquo; that means you&rsquo;re pretty much logging…

netsh, Windows 2003 and httpcfg

In a previous article, I talked about working with HttpListener. Remember: HttpListener uses http.sys. It&rsquo;s necessary to tell http.sys that a process & user should be allowed to listen to a certain port before that process starts listening. This is called &lsquo;url reservation&rsquo;. In Windows Vista and Windows server 2008, the way to do url reservation is with netsh.exe. My development…

Debugging .NET network and certificate issues

Dear Reader, I learned some important things the hard way this week, so I thought I&rsquo;d share the fruits of my agony. You must reserve ports when working with HttpListener I&rsquo;m used to letting IIS handle the details of hosting a web service for me, so I wasn&rsquo;t familiar with the ins and outs of netsh. If you self host with OWIN, this apparently gets taken care of for you &ndash; so…

Gotchya using data attributes with jQuery

Today I discovered an interesting &lsquo;gotchya&rsquo; when using HTML5 data attributes with jQuery. jQuery supports getting these data attributes with the jQuery.data() syntax &hellip; but beware: it will automatically strip hyphens and camel-case hyphenated attributes. In other words, if you try to use the following HTML: <div data-role="page" data-last-value="43" data-hidden="true"…

Hosting a blog on S3 - cheaper and simpler

A few months ago, I covered how to setup a blog using S3, Cloudfront and Route 53 that was dirt cheap, reliable, and fast. Today, I&rsquo;m going to walk through an even simpler and cheaper setup that is just as fast Overview Hugo is (still) our foundation. Hugo generates a static site based on Markdown based posts. Getting started with Hugo is a breeze &ndash; it&rsquo;s not as complicated as…

Hosting a blog on S3 and Cloudfront

Creating a blog that is easy-to-use, lightning fast, inexpensive, has fewer security problems than Wordpress, and never has downtime might seem impossible … but I think I&rsquo;ve found a way. Easy to use Hugo is our foundation. OK &ndash; I&rsquo;ll admit that Hugo isn&rsquo;t exactly easy to use for a non-geek. If you already know a bit of HTML & Javascript, it&rsquo;s a perfect fit for this…

Using generic lists in code

For best performance it&rsquo;s usually not a good idea to initialize variables in .NET. When it comes to software maintenance costs, List initialization is a different story, however. I&rsquo;ve seen 2 different patterns used when creating lists in C# code recently. One is simply to declare the list and implicitly or explicitly initialize it to null: public List<SomeObject> MyListProperty { get;…

Flushing the ASP.NET Output cache using code

When looking to speed up content that will be served from an ASP.NET MVC controller, one of the options I evaluate is the built in Output caching mechanism. Output caching is great because it&rsquo;s easy to setup, easy to maintain and it can give a big improvement for a small amount of code. Sometimes, the cached item will need to be flushed (and regenerated / recached). The built in mechanisms…

Managing a job hunt: Part 3 (phone screens)

This post is the third in a series of posts about managing a programmer job hunt (including hunting for a job in another city). You might be interested in the other parts: Part 1 (the initial research) Part 2 (the sanity check)

Managing a job hunt: Part 2 (the sanity check)

This post is the second in a series of posts about managing a programmer job hunt (including hunting for a job in another city). You might be interested in the other parts: Part 1 (the initial research)

Managing a job hunt: Part 1 (the initial research)

I recently switched jobs (and switched states ) and used several approaches that I haven&rsquo;t heard used anywhere else, so I wanted to share what worked and what didn&rsquo;t work.

Using MS Onenote to manage bug and release information

The problem Interruptions cause a real problem with lost time during software development. Jeff Atwood summarizes this nicely: The solution: taking notes We&rsquo;re already using the computer to program, I figure it makes more sense to take notes on the computer (vs pen and paper). After trying to use Evernote and getting frustrated with the lack of a decent print view or formatting options, I…

Using wildcards with git operations

I&rsquo;ve been using the awesome &lsquo;git&rsquo; source code control system for the past year now. The transition from Subversion to git was prompted mostly by my desire to use the awesome application hosting platform AppHarbor, but I picked up git with ease and haven&rsquo;t looked back. One of the things I&rsquo;ve learned about using git in conjunction with Visual Studio 2010 is that git…

What version of jQuery is a site using?

To quickly find the version of jQuery that a site is using, you can simply type the following into the browser bar of the site: javascript:alert(jQuery.fn.jquery) This will get the version of jQuery and display it in a javascript pop-up dialog.

Find out if 2 date ranges overlap using Javascript

I recently discovered an ingeniously simple way to see if 2 date ranges overlap using only Javascript: var e1start = e1.start.getTime(); var e1end = e1.end.getTime(); var e2start = e2.start.getTime(); var e2end = e2.end.getTime(); return (e1start > e2start && e1start < e2end || e2start > e1start && e2start < e1end); Simple, eh? One more quick note: ff you need extra help with designing your app…

Fun with Javascript pointers

I just spent the last hour trying to debug some Javascript code that wasn&rsquo;t working the way I expected. It turns out I was dealing with the shallow copying behavior of Javascript. If you deal in Javascript objects regularly, you need to know this information! Here is a quick example that illustrates what I saw while debugging today: // First object, with a simple string property args1 = {};…

Using Remember the Milk as a desktop task list

Using the free and excellent service Remember the Milk as your tasklist is great &ndash; but sometimes you need a nice simple tasklist you can keep close at hand on your desktop. If you use Google Chrome as your browser, there is a very easy way to do this. In Chrome, visit: http://www.rememberthemilk.com/services/modules/googleig/ (this should bring up your task list in Remember the Milk in a…

Using the CollectionAssert class in a C# unit test

Unit testing with collections can be tricky, especially when you&rsquo;re trying to compare collections. Enter the lowly &lsquo;CollectionAssert&rsquo; class in C#: // Assert: // 1.) These items are not null // 2.) These items are of type MyClass // 3.) The expected collection is the same as the actual collection CollectionAssert.AllItemsAreNotNull(actual);…

A re-introduction to the Chrome dev tools

Here is a great presentation on the Chrome developer tools by Paul Irish and Pavel Feldman . PDF notes available from Google . A delightful Chrome Developer tools cheatsheet is also available in PDF and PNG formats from Paul&rsquo;s colleague Boris Smus .

Getting a 401.1 error when using IIS and NTLM security

Sometimes as a developer, it&rsquo;s necessary to setup a website on your local IIS system to use NTLM or Windows based authentication. In an effort to make things a bit more secure in the OS, Microsoft has also made things a bit more difficult for developers when trying to setup NTLM locally for a specific website. If you find yourself getting a 401.1 error after configuring a local website to…

Using jQuery on Google&#39;s CDN but having a plan B

For personal projects or (even not so personal projects) using Google&rsquo;s CDN hosted jQuery libraries is a no brainer. But what happens when you need a plan B? Or what happens when you realize that you need to have a fallback plan just in case Google is banned in a country where you have website visitors? Well, the answer is a pretty neat trick I just learned. Taking advantage of the fact that…

Using the dig dns tool on Windows 7

Traditionally, nslookup is the tool of choice when trying to find out information about IP addresses or DNS information in Windows. In the Linux world, nslookup has been deprecated for a long time. The preferred way to query for dns information from the command line is the Domain Information Groper or &lsquo; dig &rsquo; dns tool. Interested in learning more about DNS and dig? Check out this book:…

jQuery tip: Operate on more than one item at the same time

Sometimes it&rsquo;s useful to perform an action on more than one item on the page at the same time - like when hiding or showing a series of elements all at the same time. With jQuery selector syntax, this is very easy. First, if you&rsquo;re not familiar with basic CSS or jQuery selectors, you should probably start there. Once you&rsquo;re familiar with that basic syntax however, you&rsquo;ll be…

Using Gravatar images with C# / ASP.NET

Including profile pictures in your application from the nifty (and free!) gravatar service is very easy, assuming you&rsquo;ve already got an &rsquo;email&rsquo; field for your users that you&rsquo;re tracking. To use the system, you just need to form a url that points to the user&rsquo;s profile image (using a hash of their email address) and use that url in an image tag. The url looks something…

Tips for using jQuery validation

<div id="content" style="padding: 10px;"> <form id="frmTest" method="get"> Lots of other content here<br /> Lots of other content here<br /> Lots of other content here<br /> Lots of other content here<br /> Lots of other content here<br /> Lots of other content here<br /> <input id="txtEmail" name="txtEmail" type="text" class="required email"/> <br /> <input id="txtName" name="txtName" type="text"…

Working with JSON dates in Javascript

/Date(1224043200000)/ var date = new Date(parseInt(jsonDate.substr(6))); date.toDateString();

Using HTML 5 local storage

HTML 5 includes a significant bump in what the browser itself can store (up from 4k for total cookie storage to something on the order of 5-10mb). Here&rsquo;s a simple code sample that illustrates how to access local storage in HTML5: // First, make sure our browser supports HTML 5 local storage if (typeof(localStorage) == 'undefined' ) { alert('Your browser does not support HTML5 localStorage.…

Using SQL tinyint columns

DataSet ds = GetDataSetFromStoredProc("stored_proc_name", new SqlParameter("@parameter_name", value_id)); var retItems = from dstable in ds.Tables[0].AsEnumerable() select new ClassThing() { PrimaryKeyId = dstable.Field<int>("some_column_name") };

jQuery API browser

Creating a CDN with Amazon Cloudfront

Amazon&rsquo;s Cloudfront service is truly awesome. It&rsquo;s a powerful, flexible, inexpensive way to get a content distribution network up and running so that you can play with the big boys on a startup budget. Getting up and running is a snap. First, make sure you&rsquo;ve signed up for Amazon web services S3 and Cloudfront services. Signing up is free, but understand that Amazon charges…

Using the jQuery UI &#39;transfer&#39; effect

When using the jQuery UI &rsquo;transfer&rsquo; effect for the first time, you might think the effect isn&rsquo;t working. The documentation is sparse, but the call looks simple enough: // Use transfer effect $("#txtProduct").effect("transfer", { to: $("#test") }, 1000); If you add this to your page, add the html elements to make this work, and then run this code you&rsquo;ll notice &hellip;…

How to delete data from multiple tables at once in SQL

The short answer is you can&rsquo;t. But there is a very nice workaround. I was perusing StackOverflow and came across this article talking about how to capture information from deleted rows and then use them in a join using the deleted pseudo table: How do I delete from multiple tables using INNER JOIN in SQL server - Stack Overflow begin transaction; declare @deletedIds table ( id int ); delete…

Performing a join using LINQ

So what do you do when you&rsquo;re using the nifty new &rsquo;entity framework&rsquo; and you&rsquo;re getting data back with LINQ queries and you&rsquo;ve reached the point where you want to get data back based on criteria in a related table? Well, if you&rsquo;re not using a stored proc to do it for you &ndash; you&rsquo;ve got to do a join. The join syntax in LINQ is similar to SQL syntax, but…

ASP.NET MVC2 custom validation helper

RedGate reflector and ASP.NET MVC2 rock. Using this extension method: /// <summary> /// If the given model field has validation errors, this will emit the given CSS class name /// </summary> /// <typeparam name="TModel"></typeparam> /// <typeparam name="TProperty"></typeparam> /// <param name="htmlHelper"></param> /// <param name="expression"></param> /// <param name="cssClassToEmit"></param> ///…