Recently I encountered a Terraform task in which I had a list of roles and a list of policies and I needed to create a AWS resource for every combination of role-policy. In a “regular” programming language this would be a simple nested loop. Thankfully Terraform 0.12 added for_each and for attributes to declare recurring resources. But two problems remained:
I needed some kind of way to nest these for declarations
for_each attributes requires a map with a unique key
So let’s tackle these problems one at a time. Let’s we have 2 lists:
Language Integrated Query (LINQ) is a cool feature of .NET languages like C# that allows you to perform SQL-like query right within the language against language’s data structures (lists, arrays etc.) But one drawback of LINQ – you have to know in advance, at compile time which fields to select, what filter conditions would be. Sometimes there’s a need to supply these at runtime – e.g. user selects which fields they want to see
Thankfully there exists Dynamic LINQ Library that allows you to supply LINQ parameters as a string akin Dynamic SQL. Here’s an example of such query from the library’s homepage:
var query = db.Customers
.Where("City == @0 and Orders.Count >= @1", "London", 10)
.OrderBy("CompanyName")
.Select("new(CompanyName as Name, Phone)");
Now, one thing that LINQ can do is query XML. So in theory if we load, say, this XML:
First things first. DISCLAMER: Everything described here is a hack upon a crude hack and most likely, barring a divine intervention, won’t work in final product. And I apologize in advance to Pebble dev team if my attempts at “hacking” seem silly. Now to business. Pebble SDK offers very cool framebuffer API that allows developers to address display memory of the watch directly. This makes possible creation of many cool special effects (matter of fact EffectLayer library uses framebuffer extensively). Rocky.js is JavaScript incarnation of Pebble SDK and it made me wonder whether it offers framebuffer access. Turned out it is hidden, but it’s there. At least at the latest commit at the time of this article it is. If you take a look at source file html-bindings.js you will see that binding function looks something like this:
Rocky.bindCanvas = function(canvas, options) {
//...
var framebufferPixels = new Uint8Array(module.HEAPU8.buffer,
framebufferPixelPTR,
canvasW * canvasH);
//...
var binding = {
//...
}
//...
return binding;
};
If you’re joining a grown crowd of cordcutters (people who disconnect their Cable TV services) you’re not a stranger to streaming. Devices like Roku and Chromecast go a long way to provide all your TV shows and movies need.
Amazon Fire TV and Fire Stick are the latest additions to the streaming gadgets. One advantage they have over other devices they run Android (albeit heavily modified). This gives you ability to install (sideload) ordinary Android apps onto these gadgets. There’re multiple tutorials on how to do it from desktop computers, but you have to download apps APKs onto desktop. Wouldn’t it be easier if you could do this directly from your phone? Continue reading 'Sideload APKs directly from your phone to FireTV/FireStick'»
JSON.NET is a very popular framework to process JSON data in .NET. We recently upgraded from v4 to v6 and noticed strange thing it started to output null to JSON strings created by JsonTextWriter object.
For example if JSON produced by v4 would look like this:
that extra “null” makes it invalid and unusable JSON.
The .NET function to create JSON writes it into a StringBuilder and is pretty straighforward.
It starts with call to WriteStartObject method of JsonTextWriter
Then it creates parameter name via WritePropertyName
Depending on whether primitive value or raw string needs to be written WriteValue or WriteRaw methods are used respectfully
Repeat steps 2 and 3 as needed
Call to WriteEndObjectto finish writing.
This worked perfectly well when version 4 of Newtonsoft.Json.dll was used. After upgrading to version 6 last method – “WriteEndObject” began to output “null” to resulting JSON.
The solution is to use WriteRawValue method instead of WriteRaw – it still outputs raw string, but at the end WriteEndObject doesn’t output “null” anymore.
I encountered weird issue using Infragistics ASP.NET WebDataMenu control. If total width of top-level items was bigger than menu’s width and scrolling kicked in – Google Chrome browser produces unexpected results.
Consider following basic markup for Infragistics WebDataMenu:
It’s a pretty basic markup that defines 10-item horizontal menu with a limited width, so scrolling is enabled. Code in the Initialize event handler would handle some calculation based on menu dimensions and other items on the page would be affected by these calculations. Continue reading 'Infragistics WebDataMenu delayed resizing in Chrome'»
Infragistics WebDataMenu ASP.NET control comes both with predefined stylesets and allows you granularly overwrite any of the styles. For example definition like this
will create a horizontal dropdown menu in default “Office 2007 Blue” styleset but allows you to overwrite individual styles via exposed CSS properties.
Infragistics WebHierarchicalDataGrid offers a nice ability to custom load-on-demand data via its ContainerGridDataBinding event. It is very useful during paging or displaying grid children – you can make a DB call and provide data a just needed for current page or child.
But it has a drawback – if you need to programmaticaly sort the grid by manipulating SortedColumns collection – grid thinks it needs to rebind the data and is calling ContainerGridDataBinding event handler again thus making it execute DB call again – which is redundant and may hinder performance. In a typical scenario you have your binding code:
Protected Sub xmyGrid_ContainerGridDataBinding(sender As Object, e As GridControls.DataBindingEventArgs) Handles xmyGrid.ContainerGridDataBinding
e.Cancel = True
e.DataSource = MakeDbCallToGetCurrentData()
e.SelectArguments.TotalRowCount = iTotalNumberOfRecords
End Sub
and somewhere else add sorting
Protected Sub xmyGrid_PreRender(sender As Object, e As EventArgs) Handles xmyGrid.PreRender
xmyGrid.Behaviors.Sorting.SortedColumns.Add(sCol1Key, SortDirection.Ascending)
xmyGrid.Behaviors.Sorting.SortedColumns.Add(sCol2Key, SortDirection.Descending)
End Sub
Sorting code in the second event handler is causing grid to perform second call to ContainerGridDataBinding. The solution is to move sorting code inside of ContainerGridDataBinding handler:
Protected Sub xmyGrid_ContainerGridDataBinding(sender As Object, e As GridControls.DataBindingEventArgs) Handles xmyGrid.ContainerGridDataBinding
e.Cancel = True
e.DataSource = MakeDbCallToGetCurrentData()
e.SelectArguments.TotalRowCount = iTotalNumberOfRecords
xmyGrid.Behaviors.Sorting.SortedColumns.Add(sCol1Key, SortDirection.Ascending)
xmyGrid.Behaviors.Sorting.SortedColumns.Add(sCol2Key, SortDirection.Descending)
End Sub
Since at this point grid already bound to data – columns are already available. And since we’re inside of ContainerGridDataBinding – the call to it is not repeated.
applied to a DOM element will render nice flat scrollbars:
Yes, it’s not standard CSS, but other browsers offer similar extensions (WebKit, I am looking at you). So, it works nice and well, but what if you want to style scrollbars of an IFRAME? Continue reading 'Style IFRAME scrollbars in IE'»
Would set style of grid header and rows via external CSS class. You would expect that simple defining classes like this:
.HeaderStyle { /* style definition goes here */ }
.RowStyle { /* style definition goes here */ }
should do the trick, but you may experience some unwanted, erratic behavior: styles getting lost, styles getting mixed up (row would get a header style and vise versa).
To fix this we should let grid know that header style should apply only to header row (THEAD/TH HTML elements) and row style applies only to rows with data (TBODY/TD elements). This is done via slight adjustments of the above CSS to point it to specific elements:
This way there’s no confusion, styles apply exactly were they belong. Also you may need to set grids MergeStyles property to False and make each class fully define it’s element (including fonts, colors, backgrounds etc.)