tag:blogger.com,1999:blog-5846191275572058202024-03-13T02:22:04.670+01:00Plain Old Stanstanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.comBlogger229125tag:blogger.com,1999:blog-584619127557205820.post-90163661205605942472021-12-11T21:51:00.001+01:002021-12-11T21:51:27.801+01:00Example of a PostgreSQL function to convert json string literal to a table.<p>Was not able to google one up readily, so created this sample:</p>
<script src="https://gist.github.com/staninprague/bd246a1343d1c4d4802206758a854958.js"></script>
Hope it might help someone!stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-8857547478503190452021-10-22T14:10:00.001+02:002021-10-22T14:11:13.931+02:00TIL: Proxmox "pct create" -rootfs parameter and disk size.<p> Got confused by that -rootfs parameter of proxmox when creating a new container with "pct create", so documenting it here.</p><div style="background-color: white; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px; white-space: pre;"><span style="color: maroon;"><blockquote>-rootfs local:2</blockquote></span></div>translates into (when creating container with id 1062, /etc/pve/lxc/1062.conf):<div><div style="background-color: white; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px; white-space: pre;"><blockquote>rootfs: local:1062/vm-1062-disk-0.raw,<b>size=2G</b></blockquote></div></div>so local:2 then stands for the "local" volume and 2GB as a disk size.<br /><br />Using size=2G sub-parameter led to the size of 1062G, interestingly. Not sure if this is a bug in proxmox (v7.0) or what.stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-29644454292363243102019-12-07T22:58:00.001+01:002019-12-07T23:03:48.096+01:00Ubuntu 18.04 server and ESXI on Intel NUC Hades Canyon.<div dir="ltr" style="text-align: left;" trbidi="on">
This post is just to confirm that dual boot Ubuntu 18.04.3 server and ESXI 6.7 U3 on Intel NUC Hades Canyon is possible and to describe some pitfalls/obstacles I had to jump through.<br />
<br />
My configuration for the Intel NUC Hades Canyon is Kingston dual ranked 2x16GB + 2xSamsung EVO 670 500GB.<br />
<br />
I first thought I'd do it with RAID in BIOS, but both ESXI and Ubuntu server just ignored this option anyway and second, I read that actually it is a good idea to avoid this BIOS RAID option in order to be able to read/use disks after the CPU/board failure.<br />
<br />
<div style="line-height: 18px;">
<div style="background-color: white; font-family: menlo, monaco, "courier new", monospace; font-size: 12px; white-space: pre;">
<span style="color: maroon; font-weight: bold;">#1 Installing ubuntu 18.04.3 server on Intel NUC Hades Canyon</span></div>
<div style="background-color: white; font-family: menlo, monaco, "courier new", monospace; font-size: 12px; white-space: pre;">
<br /></div>
I should tell I was a long time user of Digital Ocean, Host Europe and so on - preinstalled Ubuntu server was it for me. Somehow this time I bumped into "live" version of Ubuntu server and started to install it with the outcome of installation not seeing the disks to install Ubuntu, "Unfortunately Probing for devices to install to failed.":<div style="background-color: white; font-family: menlo, monaco, "courier new", monospace; font-size: 12px; white-space: pre;">
<br /></div>
<div style="background-color: white; font-family: menlo, monaco, "courier new", monospace; font-size: 12px; white-space: pre;">
<a href="https://bugs.launchpad.net/subiquity/+bug/1841333">https://bugs.launchpad.net/subiquity/+bug/1841333</a></div>
<div style="background-color: white; font-family: menlo, monaco, "courier new", monospace; font-size: 12px; white-space: pre;">
<br /></div>
This "problem" was the reason for the part #2 of this post - installing ESXI. I only got to the article above and understanding that I picked the wrong Ubuntu version after I have ESXI successfully installed as a boot option for disk 1.<br /><br />Here is the image for Ubuntu 18.04.3 "not live" server, just for a reference:<div style="background-color: white; font-family: menlo, monaco, "courier new", monospace; font-size: 12px; white-space: pre;">
<br /></div>
<div style="background-color: white; font-family: menlo, monaco, "courier new", monospace; font-size: 12px; white-space: pre;">
<a href="http://cdimage.ubuntu.com/releases/18.04.3/release/ubuntu-18.04.3-server-amd64.iso">http://cdimage.ubuntu.com/releases/18.04.3/release/ubuntu-18.04.3-server-amd64.iso</a></div>
<br />I also ran into Ubuntu 18.04 server installation getting stuck at 66% while running'update-grub':<br /><br /><div>
<a href="https://unix.stackexchange.com/questions/511289/ubuntu-18-04-server-installation-gets-stuck-at-66-while-runningupdate-grub">https://unix.stackexchange.com/questions/511289/ubuntu-18-04-server-installation-gets-stuck-at-66-while-runningupdate-grub</a></div>
<div style="background-color: white; font-family: menlo, monaco, "courier new", monospace; font-size: 12px; white-space: pre;">
<br /></div>
After killing the offending process, to exit busybox I used:<br /><br />```<br />exit<br />```<br /><br />and then probably Ctrl+F1<div style="background-color: white; font-family: menlo, monaco, "courier new", monospace; font-size: 12px; white-space: pre;">
<br /></div>
<div style="background-color: white; font-family: menlo, monaco, "courier new", monospace; font-size: 12px; white-space: pre;">
<span style="color: maroon; font-weight: bold;">#2 Installing VMWare ESXI Hypervisor</span></div>
<div style="background-color: white; font-family: menlo, monaco, "courier new", monospace; font-size: 12px; white-space: pre;">
<br /></div>
My main problem with ESXI installation was creating a bootable ESXI image on my mac. After a bit of research I was lucky enough to find Unetbootin:<div style="background-color: white; font-family: menlo, monaco, "courier new", monospace; font-size: 12px; white-space: pre;">
<br /></div>
<div style="background-color: white; font-family: menlo, monaco, "courier new", monospace; font-size: 12px; white-space: pre;">
<a href="https://unetbootin.github.io/">https://unetbootin.github.io</a></div>
<br />Other than that, ESXI was a breeze to install and use. Btw, I used the "live" version of Ubuntu 18.04.3 server as ESXI ubuntu iso image and it worked just alright, I really liked the ssh from github option when installing.<br />--------<br /><br />This concludes my notes on dual boot Ubuntu 18.04.3 and ESXI on Intel NUC Hades Canyon. Machine performance is outstanding, no heat, no noise. Performance of AWS large instance to paid for itself within 45 days from what I read.<br /><br />Next steps are to study on MAAS, LXD, Juju for the Kubernetes deployment as a target.<br /><br />Also looking forward the next generation of Intel NUC Canyon, the Ghost one!</div>
</div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-88421936803425508752019-02-20T14:47:00.001+01:002019-02-20T14:48:59.120+01:00xCode 10 Swift 4.2 slow autocomplete and compile times. BAD.<div dir="ltr" style="text-align: left;" trbidi="on">
At some point I started to have dismal swift autocomplete delays in xCode 10 and slower compile times. Having googled this and that and optimizing what I could I also found into these type of warnings:<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixSS05MKe83Gn3V7ucvE0bzur8lkUpdmwiPCKUqJUpZz-YGncLItfZTUcZdQga_bKzio3HUMz6eAC6Cyi4MAQC_gyl69K7a6WVbcT3SrPAnDAI0Xmnr90b6Iw4azVYhyKTwa49zQBi59k/s1600/Pasted+Graphic.png" imageanchor="1"><img border="0" height="212" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixSS05MKe83Gn3V7ucvE0bzur8lkUpdmwiPCKUqJUpZz-YGncLItfZTUcZdQga_bKzio3HUMz6eAC6Cyi4MAQC_gyl69K7a6WVbcT3SrPAnDAI0Xmnr90b6Iw4azVYhyKTwa49zQBi59k/s320/Pasted+Graphic.png" width="320" /></a><br />
<br />
My first guess was that longer tuples are causing the problem. I changed this part to use structs, no joy.<br />
<br />
One more part in the code gave me another hint:<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWfo0TuTsmYU4O94eEORVgC6TehU6Vi6qqDEAaLh7rda6lMTBSpxykvRXXyyXtuvCMMZl3Bhuqc_vFcQZQWOIyJy085vwv1m5QJePkDg0NhEruKrx5ioDV4W8V_tpUlZMamA9vkjHJDLg/s1600/Pasted+Graphic+1.png" imageanchor="1"><img border="0" height="80" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWfo0TuTsmYU4O94eEORVgC6TehU6Vi6qqDEAaLh7rda6lMTBSpxykvRXXyyXtuvCMMZl3Bhuqc_vFcQZQWOIyJy085vwv1m5QJePkDg0NhEruKrx5ioDV4W8V_tpUlZMamA9vkjHJDLg/s320/Pasted+Graphic+1.png" width="320" /></a><br />
<br />
Looked to me as if just adding up literals via "+" would be tricky for swift compiler's type checking.<br />
<br />
Changing everything above to String(format:) resolved the type checking speed.<br />
<br />
If you ask on using string interpolation with \() - it didn't solve the problem. Plus I don't like these messy strings when they get longer.<br />
<br />
I have no good words for the guys that work on Swift programming language and its design/tools. I don't think this part and types of optimization should really ever bother us, regular devs.<br />
<br />
Bad, bad, bad.... I wish I could have loved Swift more. I love the language even if I don't think it is superior that much to Objective-C. Moving to it from Objective C with all new and updated stuff, but this is simply bad.<br />
<br />
P.S. You can find a really good digest of Swift compile time optimizations here:<br />
<br />
<a href="https://github.com/fastred/Optimizing-Swift-Build-Times">https://github.com/fastred/Optimizing-Swift-Build-Times</a></div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-66502466387074643052019-01-01T14:23:00.001+01:002019-01-01T14:53:17.568+01:00TIL - Elixir Jason.Encoder - handling optional fields<div dir="ltr" style="text-align: left;" trbidi="on">
At some point along my learning road I had a location struct with the following fields:<br />
<br />
@derive Jason.Encoder<br />
<div style="background-color: white; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px; white-space: pre;">
<span style="color: blue;">defstruct</span> latitude: -<span style="color: #09885a;">999</span>, longitude: -<span style="color: #09885a;">999</span>, speed: -<span style="color: #09885a;">1.0</span>, altitude: -<span style="color: #09885a;">1.0</span>, bearing: -<span style="color: #09885a;">1.0</span></div>
<div style="background-color: white; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px; white-space: pre;">
<br /></div>
I added one more field:<br />
<div>
<br /></div>
<div>
<div style="background-color: white; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px; white-space: pre;">
<span style="color: blue;">defstruct</span> latitude: -<span style="color: #09885a;">999</span>, longitude: -<span style="color: #09885a;">999</span>, speed: -<span style="color: #09885a;">1.0</span>, altitude: -<span style="color: #09885a;">1.0</span>, bearing: -<span style="color: #09885a;">1.0</span>, <b>timestamp: <span style="color: #09885a;">0.0</span></b></div>
</div>
<div style="background-color: white; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px; white-space: pre;">
<b><span style="color: #09885a;"><br /></span></b></div>
And my tests for encoding the struct values after reading these older location records from a file started to fail.<br />
<div>
<br /></div>
<div>
Turns out this @derive part is generating the code similar to this:</div>
<div>
<br /></div>
<div>
<div style="line-height: 18px;">
<div style="background-color: white; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; white-space: pre;">
<span style="color: blue;">defimpl</span> Jason.Encoder, for: [Location] <span style="color: blue;">do</span></div>
<div style="background-color: white; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; white-space: pre;">
<b><span style="color: blue;">def</span> encode(%{altitude: <span style="color: green;">_</span>, bearing: <span style="color: green;">_</span>, latitude: <span style="color: green;">_</span>, longitude: <span style="color: green;">_</span>, speed: <span style="color: green;">_</span>, timestamp: <span style="color: green;">_</span>} = value, opts)</b> <span style="color: blue;">do</span></div>
<div style="background-color: white; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; white-space: pre;">
Jason.Encode.map(Map.take(value, [:altitude, :bearing, :latitude, :longitude, :speed, :timestamp]), opts)</div>
<div style="background-color: white; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; white-space: pre;">
<span style="color: blue;">end</span></div>
<div style="background-color: white; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; white-space: pre;">
<span style="color: blue;">end</span></div>
<div style="background-color: white; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; white-space: pre;">
<span style="color: blue;"><br /></span></div>
<i>ref: <a href="https://hexdocs.pm/jason/Jason.Encoder.html#content">https://hexdocs.pm/jason/Jason.Encoder.html#content</a></i><br />
<div style="background-color: white; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; white-space: pre;">
<span style="color: blue;"><br /></span></div>
So older records can't be matched by this automatically generated definition. </div>
</div>
<div style="line-height: 18px;">
<br /></div>
<div style="line-height: 18px;">
Considering that as a part of "support older data with a fallback value for the new field" exercise and based on Jason.Encoder documentation:</div>
<div style="line-height: 18px;">
<br /></div>
<div style="line-height: 18px;">
<b>1. </b>I removed the @derive Jason.Encoder line to avoid the automatic protocol implementation generation.</div>
<div style="line-height: 18px;">
<b>2. </b>Provided own implementation that supports the old data stored:</div>
<div style="line-height: 18px;">
<br /></div>
<div style="line-height: 18px;">
<div style="line-height: 18px;">
<div style="background-color: white; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; white-space: pre;">
<div style="line-height: 18px;">
<div>
<span style="color: blue;">require</span> Jason</div>
<br />
<div>
<span style="color: blue;">defimpl</span> Jason.Encoder, for: [Location] <span style="color: blue;">do</span></div>
<div>
<span style="color: green;"># Matches the default implementation of @derive Jason.Encoder</span></div>
<div>
<span style="color: blue;">def</span> encode(%{altitude: <span style="color: green;">_</span>, bearing: <span style="color: green;">_</span>, latitude: <span style="color: green;">_</span>, longitude: <span style="color: green;">_</span>, speed: <span style="color: green;">_</span>, <b>timestamp: <span style="color: green;">_</span></b>} = value, opts) <span style="color: blue;">do</span></div>
<div>
Jason.Encode.map(Map.take(value, [:altitude, :bearing, :latitude, :longitude, :speed, :timestamp]), opts)</div>
<div>
<span style="color: blue;">end</span></div>
<div>
<span style="color: green;"># Support for older data</span></div>
<div>
<b><span style="color: blue;">def</span> encode(%{altitude: <span style="color: green;">_</span>, bearing: <span style="color: green;">_</span>, latitude: <span style="color: green;">_</span>, longitude: <span style="color: green;">_</span>, speed: <span style="color: green;">_</span>} = value, opts)</b> <span style="color: blue;">do</span></div>
<div>
Jason.Encode.map(Map.take(value, [:altitude, :bearing, :latitude, :longitude, :speed]), opts)</div>
<div>
<span style="color: blue;">end</span></div>
<div>
<span style="color: blue;">end</span></div>
</div>
</div>
<div style="background-color: white; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; white-space: pre;">
<span style="color: blue;"><br /></span></div>
This it for my Today I Learnt.</div>
<div style="line-height: 18px;">
<br /></div>
References:</div>
<div style="line-height: 18px;">
<i><a href="https://hexdocs.pm/jason/Jason.Encoder.html#content">https://hexdocs.pm/jason/Jason.Encoder.html#content</a></i></div>
<div style="line-height: 18px;">
<i><a href="https://github.com/michalmuskala/jason">https://github.com/michalmuskala/jason</a></i><br />
<br />
And as this post started with adding a timestamp field, here you can read on timestamps in Elixir. From the Jason.Encoder author:<br />
<a href="https://michal.muskala.eu/2017/02/02/unix-timestamps-in-elixir-1-4.html"><i>https://michal.muskala.eu/2017/02/02/unix-timestamps-in-elixir-1-4.html</i></a></div>
</div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-16888975030604231692017-08-14T14:16:00.002+02:002017-08-14T14:16:53.699+02:00Copying comments in Google spreadsheet into a column<div dir="ltr" style="text-align: left;" trbidi="on">
Will copy every comment on a cell in a column into a cell next to the source column (the one with the comments):<div>
<br /></div>
<div>
<div>
function commentsToColumn() {</div>
<div>
// find selection (the source comments)</div>
<div>
var workbook = SpreadsheetApp.getActiveSpreadsheet();</div>
<div>
var sheet = workbook.getActiveSheet();</div>
<div>
var source = sheet.getActiveSelection();</div>
<div>
<br /></div>
<div>
// determine target (the column to the left of the selection)</div>
<div>
var target = source.offset(0, +1);</div>
<div>
<br /></div>
<div>
// copy comments</div>
<div>
comments = source.getComments();</div>
<div>
target.setValues(comments);</div>
<div>
}</div>
</div>
<div>
<br /></div>
<div>
If you need more info for usage, please ask in comments :).</div>
</div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-43011000805702604142017-07-02T10:41:00.000+02:002017-07-02T10:41:58.649+02:00iOS 11 beta 1,2 - NSString sizeWithAttributes - breaking change and potential bug<div dir="ltr" style="text-align: left;" trbidi="on">
Edge behavior of [NSString sizeWithAttributes] seems to be changed in iOS 11 beta 1 and 2. When asked for the<br />
<div>
<br /></div>
<div>
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3e1e81}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000}
span.s1 {font-variant-ligatures: no-common-ligatures; color: #000000}
span.s2 {font-variant-ligatures: no-common-ligatures}
span.s3 {font-variant-ligatures: no-common-ligatures; color: #703daa}
</style>
<br />
<div class="p1">
<span class="s1">float</span><span class="s2"> size <b>around</b> </span><span class="s3">0.0</span><span class="s2">;</span></div>
<div class="p2">
<span class="s2"> </span></div>
<div class="p1">
<span class="s2"> </span><span class="s4">NSString</span><span class="s2"> *testString = </span><span class="s5">@"Some test string"</span><span class="s2">;</span></div>
<div class="p3">
<span class="s6"> </span><span class="s4">NSString</span><span class="s6"> *fontName = </span><span class="s2">@".SFUIText-Semibold"</span><span class="s6">;</span></div>
<div class="p2">
<span class="s2"> </span></div>
<div class="p1">
<span class="s2"> </span><span class="s4">UIFont</span><span class="s2"> *targetFont = [</span><span class="s4">UIFont</span><span class="s2"> </span><span class="s7">fontWithName</span><span class="s2">:fontName </span><span class="s7">size</span><span class="s2">:size];</span></div>
<div class="p2">
<span class="s2"> </span></div>
<div class="p1">
<span class="s2"> </span><span class="s4">CGSize</span><span class="s2"> stringUISize = [testString </span><span class="s7">sizeWithAttributes</span><span class="s2">:@</span></div>
<div class="p1">
<span class="s2"> {</span></div>
<div class="p1">
<span class="s2"> </span><span class="s4">NSFontAttributeName</span><span class="s2">: targetFont</span></div>
<div class="p1">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; min-height: 13.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12f1b}
span.s1 {font-variant-ligatures: no-common-ligatures; color: #ba2da2}
span.s2 {font-variant-ligatures: no-common-ligatures}
span.s3 {font-variant-ligatures: no-common-ligatures; color: #272ad8}
span.s4 {font-variant-ligatures: no-common-ligatures; color: #703daa}
span.s5 {font-variant-ligatures: no-common-ligatures; color: #d12f1b}
span.s6 {font-variant-ligatures: no-common-ligatures; color: #000000}
span.s7 {font-variant-ligatures: no-common-ligatures; color: #3e1e81}
</style>
</div>
<div class="p1">
<span class="s2"> }];</span></div>
<div class="p2">
<span class="s2"><br /></span></div>
You may get very different from iOS 7- 10 values. Here is the test:<br />
<br /></div>
<div>
<script src="https://gist.github.com/staninprague/2ffff0038bea5cdf41ede27255297dac.js"></script>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
While running it on iOS 7-10, everything converges to zero string UI width:<br />
<br />
<div class="p1">
<span class="s1"><b>2017-07-02 10:11:45.996 speedometer[23301:7084973] attempted font size: 1, calculated string width: 12.157471, delta: -12</b></span></div>
<div class="p1">
<span class="s1"><b>2017-07-02 10:11:45.997 speedometer[23301:7084973] attempted font size: 0, calculated string width: 4.052490, delta: -4</b></span></div>
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000}
span.s1 {font-variant-ligatures: no-common-ligatures}
</style>
<br />
<div class="p1">
<span class="s1"><b>2017-07-02 10:11:46.005 speedometer[23301:7084973] attempted font size: 0, calculated string width: 0.000000, delta: 0</b></span></div>
<br />
while on iOS 11 beta 1 and 2 the same test case is "stuck" on value 97 something on iPhone 6 Plus:<br />
<br />
<div class="p1">
<span class="s1"><b>2017-07-02 08:29:07.157511+0200 speedometer[36517:257340] attempted font size: 4, calculated string size: 36.437256, delta: -36</b></span></div>
<div class="p1">
<span class="s1"><b>2017-07-02 08:29:07.158646+0200 speedometer[36517:257340] attempted font size: 3, calculated string size: 28.340088, delta: -28</b></span></div>
<div class="p1">
<span class="s1"><b>2017-07-02 08:29:07.159723+0200 speedometer[36517:257340] attempted font size: 2, calculated string size: 20.242920, delta: -20</b></span></div>
<div class="p1">
<span class="s1"><b>2017-07-02 08:29:07.160738+0200 speedometer[36517:257340] attempted font size: 1, calculated string size: 12.145752, delta: -12</b></span></div>
<div class="p1">
<span class="s1"><b><span style="color: red;">2017-07-02 08:29:07.161953+0200 speedometer[36517:257340] <span style="font-size: x-small;">attempted font size: 0, calculated string size: 4.048584</span>, delta: -4</span></b></span></div>
<div class="p1">
<span class="s1"><b><span style="color: red;">2017-07-02 08:29:07.166740+0200 speedometer[36517:257340] <span style="font-size: x-small;">attempted font size: 0, calculated string size: 97.166016</span>, delta: -97</span></b></span></div>
<div class="p1">
<span class="s1"><b><span style="color: red;">2017-07-02 08:29:07.167756+0200 speedometer[36517:257340] <span style="font-size: x-small;">attempted font size: -1, calculated string size: 97.166016</span>, delta: -97</span></b></span></div>
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000}
span.s1 {font-variant-ligatures: no-common-ligatures}
</style>
<br />
<div class="p1">
<span class="s1"><b><span style="color: red;">2017-07-02 08:29:07.168736+0200 speedometer[36517:257340] attempted font size: -2, calculated string size: 97.166016, delta: -97</span></b></span></div>
<div class="p1">
<span class="s1"><b><br /></b></span></div>
Looks to me as a broken "contract" and invariant. One would really expect the consistent behavior as it was since iOS7 and having the width of the string calculated as zero for zero font size and zero it should be downwards? Also string width jumping from about approaching zero values to <b style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;"><span style="color: red;">97.166016</span></b> when value got a bit on below zero looks inconsistent. Probably a missing unit test :)!</div>
<div>
<br /></div>
<div>
For me it looks like a bug and I'm reporting it to Apple now. Hopefully it will be fixed to the same consistent behavior as it used to be on iOS 7 - 10.</div>
<div>
<br /></div>
<div>
Defensive coding is like an alloc/release for me, I try to make it right and upfront, but doing static analysis later I found myself being "mentally away" way too often.</div>
<div>
<br /></div>
<div>
Yours and wishing you happy coding!</div>
<div>
Stan.</div>
</div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-40435136101090806342017-04-11T17:01:00.000+02:002019-02-26T20:17:01.917+01:00UINavigationController - ask for confirmation on Back<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Didn't expect this to be such a problem, but once you tap into the UINavigationController things become hairy.<br />
<br />
<b>Requirement:</b><br />
<br />
When user leaves a screen by tapping on a "back" in navigation bar and there are changed data in the screen I should ask for a confirmation and keep user at the current UIViewController if she decided to continue editing the data.<br />
<br />
<b>Solution.</b><br />
<br />
You may run into this: <a href="http://stackoverflow.com/questions/1214965/setting-action-for-back-button-in-navigation-controller/19132881#19132881">http://stackoverflow.com/questions/1214965/setting-action-for-back-button-in-navigation-controller/19132881#19132881</a> (particularly this: <a href="https://github.com/onegray/UIViewController-BackButtonHandler">https://github.com/onegray/UIViewController-BackButtonHandler</a>).<br />
<br />
Once, I was trying to solve the keyboard accessory to be shown each time for each UITextField on shouldBeginEditing by writing a category for a UITextField. And here is something I learned in a hard way:<br />
<br />
When you plan or see any category re-writing the existing framework method, <b><span style="color: red;">STOP! </span>Simple as this and <a href="http://stackoverflow.com/questions/5272451/overriding-methods-using-categories-in-objective-c">go read on what can turn wrong with this</a>.</b><br />
<b><br /></b>
The solution mentioned above use this:<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3
4
5</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">@implementation</span> <span style="color: #bb0066; font-weight: bold;">UINavigationController</span> <span style="color: #997700; font-weight: bold;">(ShouldPopOnBackButton)</span>
<span style="color: #008800; font-weight: bold;">-</span> (<span style="color: #333399; font-weight: bold;">BOOL</span>)<span style="color: #0066bb; font-weight: bold;">navigationBar:</span>(UINavigationBar <span style="color: #333333;">*</span>)<span style="color: #996633;">navigationBar</span> <span style="color: #0066bb; font-weight: bold;">shouldPopItem:</span>(UINavigationItem <span style="color: #333333;">*</span>)<span style="color: #996633;">item</span> {
<span style="color: #008800; font-weight: bold;">if</span>([self.viewControllers count] <span style="color: #333333;"><</span> [navigationBar.items count]) {
</pre>
</td></tr>
</tbody></table>
</div>
<br /></div>
<div>
No go for me, no need to study, excuse for being abrupt :). But one part of code from this solution turned actually to be useful.<br />
<br />
One of the comments on another post: <a href="http://stackoverflow.com/questions/20327165/popviewcontroller-strange-behaviour">http://stackoverflow.com/questions/20327165/popviewcontroller-strange-behaviour</a> got me here: <a data-saferedirecturl="https://www.google.com/url?q=http://blog.macca.tech/2013/11/ios-prevent-back-button-navigating-to.html&source=gmail&ust=1551289221105000&usg=AFQjCNE9vrCuz09Sz-c42BznIMqfjD6ghA" href="http://blog.macca.tech/2013/11/ios-prevent-back-button-navigating-to.html" rel="nofollow" style="color: #1155cc; font-family: Arial, Helvetica, sans-serif;" target="_blank">http://blog.macca.tech/2013/<wbr></wbr>11/ios-prevent-back-button-<wbr></wbr>navigating-to.html</a><br />
<br />
And was not I lucky? It really makes sense, no private APIs, framework's UIViewController gets the chance to do its stuff always. What I wanted to improve though was that "safeDelegate" property and the way it is established. So I added a new method (into UISafeNavigationController.m):<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">-</span>(<span style="color: #333399; font-weight: bold;">id</span><span style="color: #333333;"><</span>UISafeNavigationDelegate<span style="color: #333333;">></span>) <span style="color: #0066bb; font-weight: bold;">popDelegate</span>
{
UIViewController <span style="color: #333333;">*</span>topController <span style="color: #333333;">=</span> [self topViewController];
<span style="color: #008800; font-weight: bold;">if</span> ([topController conformsToProtocol<span style="color: #333333;">:</span><span style="background-color: #ffaaaa; color: red;">@</span>protocol(UISafeNavigationDelegate)]) {
<span style="color: #008800; font-weight: bold;">return</span> (<span style="color: #333399; font-weight: bold;">id</span><span style="color: #333333;"><</span>UISafeNavigationDelegate<span style="color: #333333;">></span>)topController;
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #007020;">nil</span>;
}
</pre>
</td></tr>
</tbody></table>
</div>
<br /></div>
And then you can just substitute safeDelegate with popDelegate:<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">-</span> (UIViewController <span style="color: #333333;">*</span>)<span style="color: #0066bb; font-weight: bold;">popViewControllerAnimated:</span>(<span style="color: #333399; font-weight: bold;">BOOL</span>)<span style="color: #996633;">animated</span>
{
<span style="color: #008800; font-weight: bold;">if</span> (<span style="color: red;">self.popDelegate</span> <span style="color: #333333;">&&</span> <span style="color: #333333;">!</span>[<span style="color: red;">self.popDelegate</span> navigationController<span style="color: #333333;">:</span>self
<span style="color: #997700; font-weight: bold;">shouldPopViewController:</span>[self.viewControllers lastObject]
<span style="color: #997700; font-weight: bold;">pop:</span><span style="color: #333333;">^</span>{ [super popViewControllerAnimated<span style="color: #333333;">:</span>animated]; }])
{
<span style="color: red;"><span style="font-weight: bold;">if</span> (self.navigationBar) {
[self restoreViewsForNavigationBar<span style="color: #333333;">:</span>self.navigationBar];
}</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #007020;">nil</span>;
}
<span style="color: #008800; font-weight: bold;">return</span> [super popViewControllerAnimated<span style="color: #333333;">:</span>animated];
}
</pre>
</td></tr>
</tbody></table>
</div>
<br />
Also note lines 7-9 where I call a new method (borrowed from the first stackoverflow solution that I actually criticize :)):<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">-</span>(<span style="color: #333399; font-weight: bold;">void</span>) <span style="color: #0066bb; font-weight: bold;">restoreViewsForNavigationBar:</span> (UINavigationBar <span style="color: #333333;">*</span>) navigationBar
{
<span style="color: #008800; font-weight: bold;">for</span>(UIView <span style="color: #333333;">*</span>subview <span style="color: #008800; font-weight: bold;">in</span> [navigationBar subviews]) {
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #6600ee; font-weight: bold;">0.</span> <span style="color: #333333;"><</span> subview.alpha <span style="color: #333333;">&&</span> subview.alpha <span style="color: #333333;"><</span> <span style="color: #6600ee; font-weight: bold;">1.</span>) {
[UIView animateWithDuration<span style="color: #333333;">:</span><span style="color: #6600ee; font-weight: bold;">.25</span> animations<span style="color: #333333;">:^</span>{
subview.alpha <span style="color: #333333;">=</span> <span style="color: #6600ee; font-weight: bold;">1.</span>;
}];
}
}
}
</pre>
</td></tr>
</tbody></table>
</div>
<br />
This is to avoid the back arrow in the navigation bar looking as disabled when answer from our controller to the shouldPop is NO.<br />
<br />
Then protocol method in the related view controller may look like:<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">-</span> (<span style="color: #333399; font-weight: bold;">BOOL</span>)<span style="color: #0066bb; font-weight: bold;">navigationController:</span>(UINavigationController <span style="color: #333333;">*</span>)<span style="color: #996633;">navigationController</span>
<span style="color: #997700; font-weight: bold;">shouldPopViewController:</span>(UIViewController <span style="color: #333333;">*</span>)<span style="color: #996633;">controller</span> <span style="color: #0066bb; font-weight: bold;">pop:</span>(<span style="color: #333399; font-weight: bold;">void</span>(<span style="color: #333333;">^</span>)())<span style="color: #996633;">pop</span>
{
<span style="color: #008800; font-weight: bold;">if</span> (<span style="color: #333333;">!</span>_item.<span style="color: #333399; font-weight: bold;">id</span>) {
UIAlertController <span style="color: #333333;">*</span>alert <span style="color: #333333;">=</span> [UIAlertController alertControllerWithTitle<span style="color: #333333;">:</span>LSSTRING(<span style="background-color: #fff0f0;">@"Save the item?"</span>) message<span style="color: #333333;">:</span>LSSTRING(<span style="background-color: #fff0f0;">@"You are closing this screen by using Back button and have not saved the item."</span>) preferredStyle<span style="color: #333333;">:</span>UIAlertControllerStyleAlert];
[alert addAction<span style="color: #333333;">:</span>[UIAlertAction actionWithTitle<span style="color: #333333;">:</span>LSSTRING(<span style="background-color: #fff0f0;">@"Save and close"</span>) style<span style="color: #333333;">:</span>UIAlertActionStyleDefault handler<span style="color: #333333;">:^</span>(UIAlertAction <span style="color: #333333;">*</span>action) {
[self done<span style="color: #333333;">:</span><span style="color: #007020;">nil</span>];
}]];
[alert addAction<span style="color: #333333;">:</span>[UIAlertAction actionWithTitle<span style="color: #333333;">:</span>LSSTRING(<span style="background-color: #fff0f0;">@"Don't save and close"</span>) style<span style="color: #333333;">:</span>UIAlertActionStyleDestructive handler<span style="color: #333333;">:^</span>(UIAlertAction <span style="color: #333333;">*</span>action) {
[self doCancellationCleanup];
<span style="color: #008800; font-weight: bold;">if</span> (pop) {
pop();
}
}]];
[alert addAction<span style="color: #333333;">:</span>[UIAlertAction actionWithTitle<span style="color: #333333;">:</span>LSSTRING(<span style="background-color: #fff0f0;">@"Cancel"</span>) style<span style="color: #333333;">:</span>UIAlertActionStyleCancel handler<span style="color: #333333;">:^</span>(UIAlertAction <span style="color: #333333;">*</span>action) {
}]];
[alert show];
<span style="color: red;"><span style="font-weight: bold;">return</span> <span style="color: #007020;">false</span>;</span>
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #007020;">true</span>;
}
</pre>
</td></tr>
</tbody></table>
</div>
<br />
Hope this can help someone! All the credit goes to Hong Kong Web Entrepreneur guy! Once again, here: <a data-saferedirecturl="https://www.google.com/url?q=http://blog.macca.tech/2013/11/ios-prevent-back-button-navigating-to.html&source=gmail&ust=1551289221105000&usg=AFQjCNE9vrCuz09Sz-c42BznIMqfjD6ghA" href="http://blog.macca.tech/2013/11/ios-prevent-back-button-navigating-to.html" rel="nofollow" style="color: #1155cc; font-family: Arial, Helvetica, sans-serif;" target="_blank">http://blog.macca.tech/2013/<wbr></wbr>11/ios-prevent-back-button-<wbr></wbr>navigating-to.html</a><br />
<br />
[UPDATE] In the end I had to rework the final part presented here - showing the confirmation as the way it is presented was not releasing the controller correctly and was not cleaning up the views as well. Quite bigger effort is required to get it right and it is not that generic in the end. But this is a good start! :).</div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com2tag:blogger.com,1999:blog-584619127557205820.post-63992690911287227702017-04-09T13:24:00.000+02:002017-04-09T13:24:14.053+02:00Debugging in elixir. Old erlang version got into my way.<div dir="ltr" style="text-align: left;" trbidi="on">
Today, some dialyzer stuff, but mainly debugging with Elixir was my study subject and so first I ran into iex telling me "<span class="typ" style="background-color: #eff0f1; border: 0px; color: #2b91af; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;">Could</span><span class="pln" style="background-color: #eff0f1; border: 0px; color: #303336; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;"> not find </span><span class="lit" style="background-color: #eff0f1; border: 0px; color: #7d2727; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;">'wxe_driver.so'</span>" on running :debugger.start(). Then I read that debugger starts anyway, so I tried simple :int.ni(Module), but was greeted with "no beam found for Elixir.Module". Read more and it pointed to Erlang version being lower than 19. Really iex and elixir --version were telling its 18 that is being started. Using brew upgrade erlang or elixir, brew reinstall - same thing. A year ago I installed erlang from the official installer here (<a href="https://www.erlang-solutions.com/resources/download.html">https://www.erlang-solutions.com/resources/download.html</a>). Looked there and there is an even version manager for the Erlang on OSX now?! Cool:<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-nqVd3lwjWREPD21DtY0Baxy8Gq-WYW7wToVSiaGArDMVlmNC2B2NKcd0zFLaDsvUEDvbePwayDmwgIBPhM8omXE4bBw9QT1LNWWprjM4b4raBF9nTLPi_X7n_ZHtl2JItxH5MW13esU/s1600/erlang-manager.png" imageanchor="1"><img border="0" height="223" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-nqVd3lwjWREPD21DtY0Baxy8Gq-WYW7wToVSiaGArDMVlmNC2B2NKcd0zFLaDsvUEDvbePwayDmwgIBPhM8omXE4bBw9QT1LNWWprjM4b4raBF9nTLPi_X7n_ZHtl2JItxH5MW13esU/s320/erlang-manager.png" width="320" /></a><br />
<br />
This surely helped to have version of erlang as 19.3 for elixir now and all the debugger stuff worked as expected.<br />
<br />
I'm looking more and more into the <a href="http://theerlangelist.com/article/spawn_or_not">Sasa Juric blackjack example</a> as I'm kind of getting a bit sad about the book I wanted to read as a practical guide to building elixir/OTP apps: <a href="https://pragprog.com/book/lhelph/functional-web-development-with-elixir-otp-and-phoenix">https://pragprog.com/book/lhelph/functional-web-development-with-elixir-otp-and-phoenix</a><br />
I'm kinda on Sasa's side of analysis how the functional apps should be built and the book mentioned is not leading in the right way I believe. I'm still at its start though, author may still refactor his approach later... :).<br />
<br />
Sasa uses dialyzer in his example and I read before that it is a good idea to use it, so studied today on this and typespecs in Elixir as well: <a href="http://elixir-lang.org/getting-started/typespecs-and-behaviours.html">http://elixir-lang.org/getting-started/typespecs-and-behaviours.html</a>. I also loved a TDD example on building roman numbers converter here: <a href="https://medium.com/@barruumrex/seeking-simple-satisfaction-2a098902ddff">https://medium.com/@barruumrex/seeking-simple-satisfaction-2a098902ddff</a><br />
<br />
<br /></div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-22317581888919219952017-04-05T13:05:00.001+02:002017-04-05T13:17:34.937+02:00Elixir - bind the match subject in case statement<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Before I forget again on how to bind the whole match subject in case statement in Elixir:<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXwHgohM4jHb92l4EXfNrOsfnGIiLOoc_JIUjxxzE6KivU7M6DC16U8geAp3wLK7Ob4_lmMMbQQfP30xeSzwTuZjhMSx0lRKJHFd_L2C9a2wVVU6ejz9RBjjIrRioO5tPtmnTJZ-7h-iA/s1600/elixir-case-push-to-variable.png" imageanchor="1"><img border="0" height="74" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXwHgohM4jHb92l4EXfNrOsfnGIiLOoc_JIUjxxzE6KivU7M6DC16U8geAp3wLK7Ob4_lmMMbQQfP30xeSzwTuZjhMSx0lRKJHFd_L2C9a2wVVU6ejz9RBjjIrRioO5tPtmnTJZ-7h-iA/s320/elixir-case-push-to-variable.png" width="320" /></a><br />
<div>
<br /></div>
<div>
"state" as fn argument name and "state" in case surely are having the different scope, that's just I wanted to have the same name saying "state" :).</div>
<div>
<br /></div>
Reading now <a href="https://pragprog.com/book/lhelph/functional-web-development-with-elixir-otp-and-phoenix">"Functional Web Development with Elixir, OTP, and Phoenix"</a>, so this is my version of authors to_string:<br />
<div>
<br /></div>
<div>
<div>
def to_string(coordinate) do</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span> "(in_island:#{island(coordinate)}, guessed:#{guessed?(coordinate)})"</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>end</div>
<div>
<br /></div>
<div>
I thought I'd write it in a way that I would not call the wrapping functions on Agent for each interpolated field, plus would avoid changing to_string implementation with every struct change.</div>
<div>
<br /></div>
<div>
By the way, new cool link for learning Elixir:</div>
<div>
<br /></div>
<div>
<a href="https://elixirschool.com/">https://elixirschool.com</a></div>
</div>
<div>
<br />
Also, just in time for reading the book mentioned above comes an article from Saša Jurić: <br />
<a href="http://theerlangelist.com//article/spawn_or_not">To spawn, or not to spawn?</a> Definitely going to validate the book suggested solution/architecture with what Saša Jurić is writing.<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #e4af0a}
</style><br /></div>
<div>
Done with learning for today, back to creating some added value to my customers!</div>
</div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-31664038012733846722017-03-30T18:12:00.002+02:002017-03-30T18:12:58.110+02:00xcode 8.3 CompileStoryboard Internal error. UICGColor encodeWithCoder. Please file a bug at bugreport.apple.com and attach ... <div dir="ltr" style="text-align: left;" trbidi="on">
Was dancing with my voodoo drum for a few minutes after upgrading to xcode 8.3 today. One of my storyboards that have existed for last 3 years suddenly started to cause the compile error:<div>
<br /></div>
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 12.0px; text-indent: -12.0px; font: 11.0px Menlo}
</style>
<div>
<span style="font-family: Menlo; font-size: 11px; text-indent: -12px;">CompileStoryboard bLocNote/taxi/EditTariffStoryboard.storyboard</span></div>
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 12.0px; text-indent: -12.0px; font: 11.0px Menlo}
</style>
<div class="p1">
2017-03-30 17:48:00.332 Interface Builder Cocoa Touch Tool[29650:5173036] *** Assertion failure in -[UICGColor encodeWithCoder:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.7.47/UIColor.m:1549</div>
<div class="p1">
2017-03-30 17:48:08.466 ibtoold[29647:5172916] [MT] IBPlatformTool: Wrote failed marshalling request diagnostics to path: /var/folders/8j/x30frbx948l8djrb6ff7mljc0000gn/T/IB-agent-diagnostics_2017-03-30_17-48-08_415000</div>
<div class="p1">
/* com.apple.ibtool.errors */</div>
<div>
<span style="font-family: Menlo; font-size: 11px; text-indent: -12px;">/Users/stanislavdvoychenko/Documents/code/speedo/bLocNote/taxi/EditTariffStoryboard.storyboard: error: Internal error. Please file a bug at bugreport.apple.com and attach "/var/folders/8j/x30frbx948l8djrb6ff7mljc0000gn/T/IB-agent-diagnostics_2017-03-30_17-48-08_415000".</span> </div>
<div>
<br /></div>
Was compiling fine just an hour ago on xcode 8.2.1! Ok, it tells something on not liking the UIColor, and log it mentions further says colors should be RGB or White space. I went by "binary search" removed everything from the storyboard except the table view -> build still fails. Only value catching the eye was "Tracking" color for the section view saying showing a black stripe with no color name, I have many of these assigned in other places though, guess it is still somehow different in this storyboard, so I reselected a "black" color for it:<div>
<br /></div>
<div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP_sqWiAAkWzi3m5uM_PhXskFMbatv7WB-O-kIppXbyQry0yWCsaEQ2BqKC2IldnlFGmwp2-xFsXtujmDCvl1TPQFlvrps0z7xpW3KdlX4X68q_IVrrGhYHFSudJwsLlEOXvht7-3zrxQ/s1600/xcode83-storyboard-error.png" imageanchor="1"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP_sqWiAAkWzi3m5uM_PhXskFMbatv7WB-O-kIppXbyQry0yWCsaEQ2BqKC2IldnlFGmwp2-xFsXtujmDCvl1TPQFlvrps0z7xpW3KdlX4X68q_IVrrGhYHFSudJwsLlEOXvht7-3zrxQ/s320/xcode83-storyboard-error.png" width="242" /></a></div>
<div>
<br /></div>
<div>
And it compiled! Huraaay and back to programming!</div>
</div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-28154504549366214972017-03-16T19:05:00.000+01:002017-03-16T19:26:49.822+01:00Inherited uiviewcontrollers references in one storyboard. This class is not key value coding-compliant for the key ...<div dir="ltr" style="text-align: left;" trbidi="on">
I often inherit my UIViewControllers to add functionality on top of already existing. All works fine, but today I ran into the weird problem. Setup like this:<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-DakWP0z3mGwxrm8VDdbi1ZV1dgTzZ5Kzk2lEcnfKqyR5rbxOmRf4aCvGWyQHC-4t0U2RkkaY6GWW78kTRSaY2YkLLr41UuT_BW7xSF2fqS3jzBlx31qonTIx83gmvzb233Q50gp-0Vg/s1600/inherited-referenced-viewcontrollers.png" imageanchor="1"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-DakWP0z3mGwxrm8VDdbi1ZV1dgTzZ5Kzk2lEcnfKqyR5rbxOmRf4aCvGWyQHC-4t0U2RkkaY6GWW78kTRSaY2YkLLr41UuT_BW7xSF2fqS3jzBlx31qonTIx83gmvzb233Q50gp-0Vg/s320/inherited-referenced-viewcontrollers.png" width="236" /></a><br />
<br />
Where rangeItemEditor view controller inherits from itemEditor view controller. All outlets connected in the parent view controller. On row tap I do performSegue and then this:<br />
<br />
<b>This class is not key value coding-compliant for the key ...</b><br />
<br />
Complaining about one of the outlets. After standard troubleshooting, checking that .destinationViewController is right, bunging my head a bit against the wall and trying [navigationController push] which worked I looked more carefully at the Storyboard ID values for these references. Here is obviously a good one:<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNggS6oaF527vURqg6jBtZAPj4ODO9dxJ9hbIzzoldSC4qpjw5iNafKsIxPb550nYkIZT_jpGUZMnGK1SCHd0mx13bQbDSraZ0ojhhUU5e7IcMckexphIjnd-5RwlflR-zBuM6mYOAYy8/s1600/storyboardId-good.png" imageanchor="1"><img border="0" height="120" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNggS6oaF527vURqg6jBtZAPj4ODO9dxJ9hbIzzoldSC4qpjw5iNafKsIxPb550nYkIZT_jpGUZMnGK1SCHd0mx13bQbDSraZ0ojhhUU5e7IcMckexphIjnd-5RwlflR-zBuM6mYOAYy8/s320/storyboardId-good.png" width="320" /></a><br />
<br />
And the other one, inherited rangeItemEditor had it empty. Filling it in and running again proved the idea that missing Storyboard ID in Identity tab for a references storyboard is a bad thing. I was not clearing this out though, not sure how it happened to be empty.<br />
<br />
Thought I'd share to make your troubleshooting of similar cases faster!<br />
<br />
In the end I got rid of these references in the storyboard and used [navigationController push]. Why? I just really don't want these crashes when xcode UI Editor decides to remove something behind the scenes. I've witnessed this "open the file -> get the mess" already in xcode storyboards and I really better stay safer here with using old gold manual push. Staying away from the magic until it has predictable results :).</div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-44164246545183204292017-02-20T17:45:00.001+01:002017-02-20T17:45:25.037+01:00Working around WITH not being available in older versions of sqlite.<div dir="ltr" style="text-align: left;" trbidi="on">
For one of my iPhone apps I need to rename route points to match their order as they are inserted or deleted, I started with an easy WITH version:<br />
<br />
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400}
span.s1 {font-variant-ligatures: no-common-ligatures}
</style>
<br />
<div class="p1">
<span class="s1">[NSString stringWithFormat:@"WITH wcte (id, wname) AS (SELECT w.id, '%@ ' || (SELECT COUNT(*) + 1 FROM waypoint WHERE vY1 < w.vY1) as wname FROM waypoint w) UPDATE waypoint SET \"name\" = (SELECT wname FROM wcte WHERE id = waypoint.id) WHERE \"name\" LIKE '%@ %%' OR \"name\" is null OR \"name\" = ''", LSSTRING(@"Point"), LSSTRING(@"Point")]</span></div>
<div class="p1">
<span class="s1"><br /></span></div>
And ran into the problem when testing on iOS8.1, obviously its version of sqlite didn't support WITH at that time.<div>
<br /></div>
<div>
So here is the workaround solution for older sqlite versions:</div>
<div>
<br /></div>
<div>
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12f1b}
span.s1 {font-variant-ligatures: no-common-ligatures; color: #000000}
span.s2 {font-variant-ligatures: no-common-ligatures; color: #703daa}
span.s3 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}
span.s4 {font-variant-ligatures: no-common-ligatures}
span.s5 {font-variant-ligatures: no-common-ligatures; color: #78492a}
</style>
<div class="p1">
<span class="s1">[</span><span class="s2">NSString</span><span class="s1"> </span><span class="s3">stringWithFormat</span><span class="s1">:</span><span class="s4">@"UPDATE waypoint SET \"name\" = (SELECT '%@ ' || (SELECT COUNT(*) + 1 FROM waypoint w WHERE w.vY1 < w1.vY1) FROM waypoint w1 WHERE w1.id = waypoint.id) WHERE \"name\" LIKE '%@ %%' OR \"name\" is null OR \"name\" = ''"</span><span class="s1">, </span><span class="s5">LSSTRING</span><span class="s1">(</span><span class="s4">@"Point"</span><span class="s1">), </span><span class="s5">LSSTRING</span><span class="s1">(</span><span class="s4">@"Point"</span><span class="s1">)]</span></div>
<div class="p1">
<span class="s1"><br /></span></div>
Not that nicely looking, but I'm still committed to support iOS8 for a few more months. If you are puzzled by that LSSTRING part - that's just my macro for the LocalizableString as I only want to rename these points that are named automatically and surely I want to name them in the localized manner. Punto it is in Spanish (I hope) :). vY1 is a cryptic name for the order column :).</div>
<div>
<br /></div>
<div>
Would not be publishing at all, but sqlite syntax sometime is surprising in what it can or can't do, so I thought I might save time to someone.</div>
<div>
<br /></div>
<div>
If you are into hiking, fishing, cycling or classic skiing here is the app link, it's free: <a href="https://itunes.apple.com/us/app/id1120906807">https://itunes.apple.com/us/app/id1120906807</a></div>
<div>
<br /></div>
<div>
<br /></div>
</div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-63553691468166768372016-12-09T15:02:00.002+01:002016-12-21T17:34:32.721+01:00Elixir, Phoenix, React, Redux and ES6 - I'm a complete beginner again.<div dir="ltr" style="text-align: left;" trbidi="on">
I started with Erlang and now progressing with Elixir, Phoenix, React, Redux and ES6 stack. Was feeling a bit lost when seeing stuff like this:<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><span style="color: #999999;"> var createStoreWithMiddleware = (0, _redux.applyMiddleware)(reduxRouterMiddleware, _reduxThunk2.default, loggerMiddleware)(_redux.createStore);</span><br />
<div>
<br />
or:<br />
<br />
<span style="color: #999999;">const store = autoRehydrate()(createF8Store)(reducers);</span><br />
<span style="color: #999999;"><br /></span></div>
<div>
Had to remind myself on a simple function chaining, like:</div>
<div>
<span style="color: #999999;"><br /></span></div>
<div>
<div>
<span style="color: #999999;">const p = (store)=>{console.log("I'm an almighty container, you passed me the store: " + store);};</span></div>
<div>
<span style="color: #999999;"><br /></span></div>
<div>
<span style="color: #999999;">const f = (a,b)=>{</span></div>
<div>
<span style="color: #999999;"> console.log("Thanks for a and b: " + a + ", " + b + " it helped me to build a container with I return to you. Pass a store into it!");</span></div>
<div>
<span style="color: #999999;">return p;</span></div>
<div>
<span style="color: #999999;">};</span></div>
<div>
<span style="color: #999999;"><br /></span></div>
<div>
<span style="color: #999999;">f(3,4)("Store is just a name 'John'");</span></div>
</div>
<div>
<br /></div>
<div>
With the output of:</div>
<div>
<br /></div>
<div>
<style type="text/css">
li.li1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Helvetica; color: #008800; -webkit-text-stroke: #008800}
span.s1 {-webkit-text-stroke: 0px #000000}
span.s2 {font-kerning: none}
span.s3 {color: #000000; -webkit-text-stroke: 0px #000000}
span.s4 {font-kerning: none; color: #000000; -webkit-text-stroke: 0px #000000}
ul.ul1 {list-style-type: none}
</style>
<br />
<ul class="ul1">
<li class="li1"><span class="s1"></span><span class="s2">"Thanks for a and b: 3, 4 it helped me to build a container with I return to you. Pass a store into it!"</span></li>
<li class="li1"><span class="s3"></span><span class="s4"><br />
</span><span class="s2">"I'm an almighty container, you passed me the state: Store is just a name 'John'"</span></li>
</ul>
</div>
Beginner mind work play games with me, tendency to get lost on trivial subjects is quite high :):):).<br />
<br />
A list of resources I really appreciated so far:<br />
<br />
React:<br />
<a href="https://facebook.github.io/react/docs">https://facebook.github.io/react/docs</a><br />
<a href="https://egghead.io/courses/react-fundamentals">https://egghead.io/courses/react-fundamentals</a><br />
<a href="https://egghead.io/courses/react-flux-architecture-es6">https://egghead.io/courses/react-flux-architecture-es6</a><br />
<br />
Redux:<br />
<a href="http://redux.js.org/">http://redux.js.org</a><br />
<a href="https://egghead.io/lessons/javascript-redux-reducer-composition-with-combinereducers">https://egghead.io/lessons/javascript-redux-reducer-composition-with-combinereducers</a><br />
<br />
ES6:<br />
<a href="https://ponyfoo.com/articles/es6">https://ponyfoo.com/articles/es6</a><br />
<br />
ES6 and modules (oh, how could have I got so much behind?):<br />
<a href="https://24ways.org/2014/javascript-modules-the-es6-way/">https://24ways.org/2014/javascript-modules-the-es6-way/</a><br />
<a href="https://babeljs.io/learn-es2015/">https://babeljs.io/learn-es2015/</a><br />
<br />
ES6 Promises: <a href="http://www.datchley.name/es6-promises/">http://www.datchley.name/es6-promises/</a><br />
<br />
I also found this article being an awesome walkthrough on getting React/Redux/ES6 and more together in Facebook's makeitopen app:<br />
<a href="http://makeitopen.com/tutorials/building-the-f8-app">http://makeitopen.com/tutorials/building-the-f8-app</a><br />
<br />
Webpack:<br />
<a href="http://ryanchristiani.com/introduction-to-webpack/">http://ryanchristiani.com/introduction-to-webpack/</a><br />
<br />
<b>Elixir and Phoenix: </b><br />
Pragmatic programmers - Elixir programming, Phoenix programming.<br />
Phoenix and Trello clone: <a href="http://codeloveandboards.com/blog/2016/01/14/trello-tribute-with-phoenix-and-react-pt-1/">http://codeloveandboards.com/blog/2016/01/14/trello-tribute-with-phoenix-and-react-pt-1/</a><br />
<br />
<br />
<br />
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #93a1a1; -webkit-text-stroke: #93a1a1; background-color: #002b36}
span.s1 {font-kerning: none; color: #278bd2; -webkit-text-stroke: 0px #278bd2}
span.s2 {font-kerning: none}
span.s3 {font-kerning: none; color: #859900; -webkit-text-stroke: 0px #859900}
</style></div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-55618028957215822672016-06-15T11:19:00.002+02:002016-06-16T13:17:50.926+02:00Me, a troll! My recent MS experience :)<div dir="ltr" style="text-align: left;" trbidi="on">
If I had to show one example for all for my recent Microsoft experience as a developer and user, here it is. The welcome page in VS 2015 opening the xml feed when you click on "More news":<br />
<br />
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiI0rXPGWtljXKZBK_mmT9we-cTw7xYA4C6uKliMcfXG0km3Fgi3RyzawvvtlPoWpatvt3BPT4BF58MHy5bCgcHj8DwnMqRfRhB_ZVXmq_rsMsmSk9kdwe4FI84zviYtGQWYaxE5pJg9bg/s1600/Capture.PNG" imageanchor="1"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiI0rXPGWtljXKZBK_mmT9we-cTw7xYA4C6uKliMcfXG0km3Fgi3RyzawvvtlPoWpatvt3BPT4BF58MHy5bCgcHj8DwnMqRfRhB_ZVXmq_rsMsmSk9kdwe4FI84zviYtGQWYaxE5pJg9bg/s400/Capture.PNG" width="258" /></a></div>
<div style="text-align: left;">
I will not be telling here how I'm trying to keep my ASUS tablet in sync with time after upgrading to Windows 10. The above is enough declaration of "we are not for humans" and "we don't really care" :). </div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
This is me, a troll in the MS land. I used to be a regular guy here. Sorry. I'm working hard on my escape plan now.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Stan.<br />
<br />
P.S. To my problem with Windows 10 time. Given how different apps in windows fail differently based on that time sync problem and learning Erlang at the moment, it was quite up to point to read about Erlang time here: <a href="http://learnyousomeerlang.com/time">http://learnyousomeerlang.com/time</a>, wishing you a good read! :).</div>
</div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-28157949754002121892016-05-26T16:11:00.002+02:002016-05-26T16:43:48.211+02:00Symbolicating bitcode crash logs in XCode<div dir="ltr" style="text-align: left;" trbidi="on">
As of Xcode version 7.3 there is still a problem with symbolicating the bitcode crash logs. I've attempted several solutions, <a href="https://gist.github.com/anonymous/cdb5ba3791cfd7d312c2">here</a> and <a href="http://www.charmcitygavin.com/2016/02/15/how-i-symbolicated-a-apple-tv-crash-report-from-a-bitcode-build/">here</a>, <b>but</b> here is what I came to:<br />
<br />
1. Crash logs provided are for the dSYMs that Apple also provides. Just go to the iTunes connect and download them:<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp7ZsnEtHNM8_pmT2IFc1eFss4K_s2omPG-SWP9Pca0j7KeReC6lFwCjgw13TgD3s4BjhzJXrcLXCn4gRt0kfKbavrnVfFt_7Vc9SbndX8yCnvGwM67tbDWq60mPI56U6SfRNS5sA4y_U/s1600/downloadDSYM.png" imageanchor="1"><img border="0" height="366" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp7ZsnEtHNM8_pmT2IFc1eFss4K_s2omPG-SWP9Pca0j7KeReC6lFwCjgw13TgD3s4BjhzJXrcLXCn4gRt0kfKbavrnVfFt_7Vc9SbndX8yCnvGwM67tbDWq60mPI56U6SfRNS5sA4y_U/s640/downloadDSYM.png" width="640" /></a><br />
<br />
Once you have them right click on the crash in xcode -> "Show in finder" and copy to some target directory - that's actually a crashpoint file you are going to get.<br />
<br />
My target directory is now ~\Desktop\crashes and here is how it looks:<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhda3iusB17WkCeJ9915JhPa9EBBv3ivJLFi3eFu1VdzrfpBSrg6cbcTNzTiPh_PKSv2r4vjivrrNQYpMx50AwQSYt8kY2hD-EXJWKtANVvwTxgsQQD1h94G8O_IPCUlunHmeFN1SS6_6E/s1600/resym-dir.png" imageanchor="1"><img border="0" height="353" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhda3iusB17WkCeJ9915JhPa9EBBv3ivJLFi3eFu1VdzrfpBSrg6cbcTNzTiPh_PKSv2r4vjivrrNQYpMx50AwQSYt8kY2hD-EXJWKtANVvwTxgsQQD1h94G8O_IPCUlunHmeFN1SS6_6E/s640/resym-dir.png" width="640" /></a><br />
<br />
Where #1 are dSYMs as copied from the iTunes connect. #2 is the crashpoint saved from the crash organizer window in xCode. #4 is a crash log extracted from the crashpoint file (right click and "show package contents")<br />
<br />
To get #3 - a symbolicatecrash app, execute this in the target directory (xcode 7.3):<br />
<br />
<br />
<div class="p1">
<span style="background-color: #cccccc;">cp /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash symbolicatecrash</span></div>
<div class="p1">
<br /></div>
<div class="p1">
For different versions of xcode the location of symbolicatecrash will be different.</div>
<div class="p1">
<br /></div>
<div class="p1">
To get symbolicatecrash ready to operate execute:</div>
<div class="p1">
<span style="background-color: #cccccc;"><br /></span></div>
<div class="p1">
</div>
<div class="p1">
<span style="background-color: #cccccc;">export DEVELOPER_DIR='/Applications/Xcode.app/Contents/Developer'</span></div>
<div class="p1">
<br /></div>
<div class="p1">
Only one step is left! That's to get your crash log symbolicated:</div>
<div class="p1">
<br /></div>
<div class="p1">
</div>
<div class="p1">
<span style="background-color: #cccccc;">./symbolicatecrash a.crash dSYMs/ > a.log</span></div>
<div class="p1">
<br /></div>
<div class="p1">
And the output file a.log is looking like:</div>
<div class="p1">
<br /></div>
<div class="p1">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpUNPXAuFplHyb2pb93JnblPL0eCgKcO-i52skEOnDAZeI7lYp8n54e3m6L703YJEVGI-GlotV2aoaM-T6Ur2c5Mqtd2Ycj5g75-tvNL3hd-zxMLDkZJfrFwP4Gaqg5L86Ej6XlnKwbZc/s1600/symbolicated.png" imageanchor="1"><img border="0" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpUNPXAuFplHyb2pb93JnblPL0eCgKcO-i52skEOnDAZeI7lYp8n54e3m6L703YJEVGI-GlotV2aoaM-T6Ur2c5Mqtd2Ycj5g75-tvNL3hd-zxMLDkZJfrFwP4Gaqg5L86Ej6XlnKwbZc/s640/symbolicated.png" width="640" /></a></div>
<br />
<br />
Way better, is not it?<br />
<br />
There are nuances that I would not touch here, like these dSYM files you downloaded are for different architectures and it would be the best to match your specific crash log to a corresponding dSYM. I'll leave this detail to you, my experience is that function names do match quite well, then it is just about the line of code information you'll be getting. In above picture, given crash and dSYM are matched well, you can see the line of code where the crash exactly happened. Otherwise you'd see +xyz there and that's not that helpful.<br />
<br />
This is it. Please don't judge me strictly, I'm not an expert in any field, as I learnt over time :)! Knowing more than I do? Share your knowledge in the comments!<br />
<br />
Yours,<br />
Stan.<br />
<br /></div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-13959849057879120792016-04-27T13:59:00.002+02:002016-04-27T17:42:51.194+02:00Erlang http response emulator<div dir="ltr" style="text-align: left;" trbidi="on">
Recently I had to implement a "transparent" proxy between Tibco and Blackberry. I thought I'd share the erlang module I wrote to emulate responses from BB as you can't really expect from BB server to give you error responses or timeouts so you can test your proxy part. Here it is:<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96</pre>
</td><td><pre style="line-height: 125%; margin: 0;">-<span style="color: #880000; font-weight: bold;">module</span>(httpemulator).
-<span style="color: #880000; font-weight: bold;">author</span>(<span style="background-color: #fff0f0;">"stanislavdvoychenko"</span>).
-<span style="color: #880000; font-weight: bold;">export</span>([client<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">0</span>, server<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">0</span>,start<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">0</span>,accept<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">1</span>,enter_loop<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">1</span>,loop<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">1</span>]).
<span style="color: #0066bb; font-weight: bold;">client</span>() <span style="color: #333333;">-></span>
{ok, <span style="color: #996633;">Socket</span>} <span style="color: #333333;">=</span> <span style="color: #0e84b5; font-weight: bold;">gen_tcp</span>:<span style="color: #0066bb; font-weight: bold;">connect</span>(<span style="background-color: #fff0f0;">"localhost"</span>, <span style="color: #0000dd; font-weight: bold;">4001</span>,[list, {packet, <span style="color: #0000dd; font-weight: bold;">0</span>}]),
ok <span style="color: #333333;">=</span> <span style="color: #0e84b5; font-weight: bold;">gen_tcp</span>:<span style="color: #007020;">send</span>(<span style="color: #996633;">Socket</span>, <span style="background-color: #fff0f0;">"packet"</span>),
<span style="color: #008800; font-weight: bold;">receive</span>
{tcp,<span style="color: #996633;">Socket</span>,<span style="color: #996633;">String</span>} <span style="color: #333333;">-></span>
<span style="color: #0e84b5; font-weight: bold;">io</span>:<span style="color: #0066bb; font-weight: bold;">format</span>(<span style="background-color: #fff0f0;">"Client received = </span><span style="background-color: #eeeeee;">~p~n</span><span style="background-color: #fff0f0;">"</span>,[<span style="color: #996633;">String</span>]),
<span style="color: #0e84b5; font-weight: bold;">io</span>:<span style="color: #0066bb; font-weight: bold;">format</span>(<span style="background-color: #fff0f0;">"Client result = </span><span style="background-color: #eeeeee;">~p~n</span><span style="background-color: #fff0f0;">"</span>,[<span style="color: #996633;">String</span>]),
<span style="color: #0e84b5; font-weight: bold;">gen_tcp</span>:<span style="color: #0066bb; font-weight: bold;">close</span>(<span style="color: #996633;">Socket</span>)
<span style="color: #008800; font-weight: bold;">after</span> <span style="color: #0000dd; font-weight: bold;">1000</span> <span style="color: #333333;">-></span>
<span style="color: #007020;">exit</span>
<span style="color: #008800; font-weight: bold;">end</span>.
<span style="color: #0066bb; font-weight: bold;">server</span>() <span style="color: #333333;">-></span>
<span style="color: #996633;">Pid</span> <span style="color: #333333;">=</span> <span style="color: #007020;">spawn</span>(<span style="color: #008800; font-weight: bold;">fun</span>()<span style="color: #333333;">-></span> start() <span style="color: #008800; font-weight: bold;">end</span>),
<span style="color: #996633;">Pid</span>.
<span style="color: #0066bb; font-weight: bold;">start</span>() <span style="color: #333333;">-></span>
<span style="color: #0e84b5; font-weight: bold;">io</span>:<span style="color: #0066bb; font-weight: bold;">format</span>(<span style="background-color: #fff0f0;">"Started Server:</span><span style="background-color: #eeeeee;">~n</span><span style="background-color: #fff0f0;">"</span>),
{ok, <span style="color: #996633;">Socket</span>} <span style="color: #333333;">=</span> <span style="color: #0e84b5; font-weight: bold;">gen_tcp</span>:<span style="color: #0066bb; font-weight: bold;">listen</span>(<span style="color: #0000dd; font-weight: bold;">4001</span>, [binary, {packet, <span style="color: #0000dd; font-weight: bold;">0</span>},{reuseaddr, true},{active, false}]),
accept(<span style="color: #996633;">Socket</span>).
<span style="color: #0066bb; font-weight: bold;">accept</span>(<span style="color: #996633;">ListenSocket</span>) <span style="color: #333333;">-></span>
<span style="color: #0e84b5; font-weight: bold;">io</span>:<span style="color: #0066bb; font-weight: bold;">format</span>(<span style="background-color: #fff0f0;">"Accept Server:</span><span style="background-color: #eeeeee;">~n</span><span style="background-color: #fff0f0;">"</span>),
<span style="color: #008800; font-weight: bold;">case</span> <span style="color: #0e84b5; font-weight: bold;">gen_tcp</span>:<span style="color: #0066bb; font-weight: bold;">accept</span>(<span style="color: #996633;">ListenSocket</span>) <span style="color: #008800; font-weight: bold;">of</span>
{ok, <span style="color: #996633;">Socket</span>} <span style="color: #333333;">-></span>
<span style="color: #996633;">Pid</span> <span style="color: #333333;">=</span> <span style="color: #007020;">spawn</span>(<span style="color: #008800; font-weight: bold;">fun</span>() <span style="color: #333333;">-></span>
<span style="color: #0e84b5; font-weight: bold;">io</span>:<span style="color: #0066bb; font-weight: bold;">format</span>(<span style="background-color: #fff0f0;">"Connection accepted </span><span style="background-color: #eeeeee;">~n</span><span style="background-color: #fff0f0;">"</span>, []),
enter_loop(<span style="color: #996633;">Socket</span>)
<span style="color: #008800; font-weight: bold;">end</span>),
<span style="color: #0e84b5; font-weight: bold;">io</span>:<span style="color: #0066bb; font-weight: bold;">format</span>(<span style="background-color: #fff0f0;">"Pid </span><span style="background-color: #eeeeee;">~p~n</span><span style="background-color: #fff0f0;">"</span>,[<span style="color: #996633;">Pid</span>]),
<span style="color: #0e84b5; font-weight: bold;">gen_tcp</span>:<span style="color: #0066bb; font-weight: bold;">controlling_process</span>(<span style="color: #996633;">Socket</span>, <span style="color: #996633;">Pid</span>),
<span style="color: #996633;">Pid</span> <span style="color: #333333;">!</span> ack,
accept(<span style="color: #996633;">ListenSocket</span>);
<span style="color: #996633;">Error</span> <span style="color: #333333;">-></span>
<span style="color: #007020;">exit</span>(<span style="color: #996633;">Error</span>)
<span style="color: #008800; font-weight: bold;">end</span>.
<span style="color: #0066bb; font-weight: bold;">enter_loop</span>(<span style="color: #996633;">Socket</span>) <span style="color: #333333;">-></span>
<span style="color: #888888;">%% make sure to acknowledge owner rights transmission finished</span>
<span style="color: #008800; font-weight: bold;">receive</span> ack <span style="color: #333333;">-></span> ok <span style="color: #008800; font-weight: bold;">end</span>,
loop(<span style="color: #996633;">Socket</span>).
<span style="color: #0066bb; font-weight: bold;">loop</span>(<span style="color: #996633;">Socket</span>) <span style="color: #333333;">-></span>
<span style="color: #0e84b5; font-weight: bold;">io</span>:<span style="color: #0066bb; font-weight: bold;">format</span>(<span style="background-color: #fff0f0;">"Loop Server:</span><span style="background-color: #eeeeee;">~n</span><span style="background-color: #fff0f0;">"</span>),
<span style="color: #008800; font-weight: bold;">case</span> <span style="color: #0e84b5; font-weight: bold;">gen_tcp</span>:<span style="color: #0066bb; font-weight: bold;">recv</span>(<span style="color: #996633;">Socket</span>, <span style="color: #0000dd; font-weight: bold;">0</span>) <span style="color: #008800; font-weight: bold;">of</span>
{ok, <span style="color: #996633;">Data</span>} <span style="color: #333333;">-></span>
<span style="color: #0e84b5; font-weight: bold;">io</span>:<span style="color: #0066bb; font-weight: bold;">format</span>(<span style="background-color: #fff0f0;">"Server got data = </span><span style="background-color: #eeeeee;">~s~n</span><span style="background-color: #fff0f0;">"</span>, [<span style="color: #996633;">Data</span>]),
<span style="color: #996633;">Match</span> <span style="color: #333333;">=</span> <span style="color: #0e84b5; font-weight: bold;">re</span>:<span style="color: #0066bb; font-weight: bold;">run</span>(<span style="color: #996633;">Data</span>, <span style="background-color: #fff0f0;">".*Emulator-Command:</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\s</span><span style="background-color: #fff0f0;">(.+)</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r</span><span style="background-color: #fff0f0;">"</span>, [{capture, [<span style="color: #0000dd; font-weight: bold;">1</span>],list}]),
<span style="color: #008800; font-weight: bold;">case</span> <span style="color: #996633;">Match</span> <span style="color: #008800; font-weight: bold;">of</span>
{match, [<span style="background-color: #fff0f0;">"timeout"</span>]} <span style="color: #333333;">-></span> <span style="color: #996633;">Response</span> <span style="color: #333333;">=</span> timeout(<span style="background-color: #fff0f0;">"timeout"</span>);
{match, [<span style="background-color: #fff0f0;">"protocolviolation"</span>]} <span style="color: #333333;">-></span> <span style="color: #996633;">Response</span> <span style="color: #333333;">=</span> protocol_violation(<span style="background-color: #fff0f0;">"Omitting carriage return, this should cause the protocol violation"</span>);
{match, [<span style="background-color: #fff0f0;">"httperror"</span>]} <span style="color: #333333;">-></span> <span style="color: #996633;">Response</span> <span style="color: #333333;">=</span> http_error(<span style="background-color: #fff0f0;">"500"</span>, <span style="background-color: #fff0f0;">"Internal Server Error"</span>);
_ <span style="color: #333333;">-></span> <span style="color: #996633;">Response</span> <span style="color: #333333;">=</span> response(<span style="background-color: #fff0f0;">"testing"</span>)
<span style="color: #008800; font-weight: bold;">end</span>,
<span style="color: #0e84b5; font-weight: bold;">io</span>:<span style="color: #0066bb; font-weight: bold;">format</span>(<span style="background-color: #fff0f0;">"Match: </span><span style="background-color: #eeeeee;">~p~n</span><span style="background-color: #fff0f0;">"</span>, [<span style="color: #996633;">Match</span>]),
<span style="color: #0e84b5; font-weight: bold;">gen_tcp</span>:<span style="color: #007020;">send</span>(<span style="color: #996633;">Socket</span>, <span style="color: #996633;">Response</span>);
<span style="color: #888888;">%%loop(Socket);</span>
{error, <span style="color: #996633;">Reason</span>} <span style="color: #333333;">-></span>
<span style="color: #0e84b5; font-weight: bold;">io</span>:<span style="color: #0066bb; font-weight: bold;">format</span>(<span style="background-color: #fff0f0;">"Error on socket </span><span style="background-color: #eeeeee;">~p</span><span style="background-color: #fff0f0;"> reason: </span><span style="background-color: #eeeeee;">~p~n</span><span style="background-color: #fff0f0;">"</span>, [<span style="color: #996633;">Socket</span>, <span style="color: #996633;">Reason</span>]),
<span style="color: #0e84b5; font-weight: bold;">gen_tcp</span>:<span style="color: #0066bb; font-weight: bold;">close</span>(<span style="color: #996633;">Socket</span>)
<span style="color: #008800; font-weight: bold;">end</span>.
<span style="color: #0066bb; font-weight: bold;">response</span>(<span style="color: #996633;">Str</span>) <span style="color: #333333;">-></span>
<span style="color: #996633;">B</span> <span style="color: #333333;">=</span> <span style="color: #007020;">iolist_to_binary</span>(<span style="color: #996633;">Str</span>),
<span style="color: #007020;">iolist_to_binary</span>(
<span style="color: #0e84b5; font-weight: bold;">io_lib</span>:<span style="color: #0066bb; font-weight: bold;">fwrite</span>(
<span style="background-color: #fff0f0;">"HTTP/1.0 200 OK</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">Content-Type: text/html</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">Content-Length: </span><span style="background-color: #eeeeee;">~p</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n\r\n</span><span style="background-color: #eeeeee;">~s</span><span style="background-color: #fff0f0;">"</span>,
[<span style="color: #007020;">size</span>(<span style="color: #996633;">B</span>), <span style="color: #996633;">B</span>])).
<span style="color: #0066bb; font-weight: bold;">timeout</span>(<span style="color: #996633;">Str</span>) <span style="color: #333333;">-></span>
<span style="color: #0e84b5; font-weight: bold;">timer</span>:<span style="color: #0066bb; font-weight: bold;">sleep</span>(<span style="color: #0000dd; font-weight: bold;">1000000000</span>),
<span style="color: #996633;">B</span> <span style="color: #333333;">=</span> <span style="color: #007020;">iolist_to_binary</span>(<span style="color: #996633;">Str</span>),
<span style="color: #007020;">iolist_to_binary</span>(
<span style="color: #0e84b5; font-weight: bold;">io_lib</span>:<span style="color: #0066bb; font-weight: bold;">fwrite</span>(
<span style="background-color: #fff0f0;">"HTTP/1.0 200 OK</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">Content-Type: text/html</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">Content-Length: </span><span style="background-color: #eeeeee;">~p</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n\r\n</span><span style="background-color: #eeeeee;">~s</span><span style="background-color: #fff0f0;">"</span>,
[<span style="color: #007020;">size</span>(<span style="color: #996633;">B</span>), <span style="color: #996633;">B</span>])).
<span style="color: #0066bb; font-weight: bold;">protocol_violation</span>(<span style="color: #996633;">Str</span>) <span style="color: #333333;">-></span>
<span style="color: #996633;">B</span> <span style="color: #333333;">=</span> <span style="color: #007020;">iolist_to_binary</span>(<span style="color: #996633;">Str</span>),
<span style="color: #007020;">iolist_to_binary</span>(
<span style="color: #0e84b5; font-weight: bold;">io_lib</span>:<span style="color: #0066bb; font-weight: bold;">fwrite</span>(
<span style="background-color: #fff0f0;">"HTTP/1.0 200 OK</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">Content-Type: text/html</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">Content-Length: </span><span style="background-color: #eeeeee;">~p</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\n\n</span><span style="background-color: #eeeeee;">~s</span><span style="background-color: #fff0f0;">"</span>,
[<span style="color: #007020;">size</span>(<span style="color: #996633;">B</span>), <span style="color: #996633;">B</span>])).
<span style="color: #0066bb; font-weight: bold;">http_error</span>(<span style="color: #996633;">Code</span>, <span style="color: #996633;">Str</span>) <span style="color: #333333;">-></span>
<span style="color: #996633;">B</span> <span style="color: #333333;">=</span> <span style="color: #007020;">iolist_to_binary</span>(<span style="color: #996633;">Str</span>),
<span style="color: #007020;">iolist_to_binary</span>(
<span style="color: #0e84b5; font-weight: bold;">io_lib</span>:<span style="color: #0066bb; font-weight: bold;">fwrite</span>(
<span style="background-color: #fff0f0;">"HTTP/1.0 </span><span style="background-color: #eeeeee;">~s</span><span style="background-color: #fff0f0;"> </span><span style="background-color: #eeeeee;">~s</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">Content-Type: text/html</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">Content-Length: </span><span style="background-color: #eeeeee;">~p</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n\r\n</span><span style="background-color: #eeeeee;">~s</span><span style="background-color: #fff0f0;">"</span>,
[<span style="color: #996633;">Code</span>, <span style="color: #996633;">B</span>, <span style="color: #007020;">size</span>(<span style="color: #996633;">B</span>), <span style="color: #996633;">B</span>])).
</pre>
</td></tr>
</tbody></table>
</div>
<br />
This Erlang module expects you to sent an extra http header Emulator-Command: * where * can be:<br />
<br />
httperror -> returns 500 and Internal Server Error<br />
timeout -> runs a long sleep on Erlang side, causes timeout on a proxy side<br />
protocolviolation -> As I built the proxy in ,net WCF it was funny to see that MS takes only \n in the http headers as a protocol violation, so \r\n is required to keep MS happy.<br />
<br />
anything else there or omitting this header will just return proper http response with "testing" body.<br />
<br />
<span style="color: red;">Disclaimer. I'm only starting to learn Erlang so please take the code with caution of course!</span><br />
<br />
To compile in the erlang shell:<br />
<br />
<span style="background-color: cyan;">c(httpemulator).</span><br />
<br />
To start emulator server:<br />
<br />
<span style="background-color: cyan;">httpemulator:server().</span><br />
<div>
<br /></div>
<div>
To end the emulator process:</div>
<div>
<br /></div>
<div>
<div>
<span style="background-color: cyan;">exit(pid(0,96,0), old).</span></div>
</div>
<div>
<br /></div>
<div>
Pid is returned at the server start.</div>
<div>
<br /></div>
<div>
Hope it can be useful :).</div>
</div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-56200875518905715912016-04-14T13:59:00.000+02:002016-04-28T18:31:33.975+02:00xcode - Configure for analyzing. The scheme is not configured for analyzing. <div dir="ltr" style="text-align: left;" trbidi="on">
I'm used to run analyzing cycle on my apps when moving closer to their public release. This time xcode (7.3 (7D175)) greeted me with:<br />
<br />
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXZ7kA6fQVQOC2Ri7W6c8GnWqFkJJPs_4zx84H_Wrs0Ca4NhTtw2tOO2FdwwseCILacPaT_Vj7Wmv7Ss6vIQpiZGbiKKYUwuGgr5H4guiAV2cxc6H0PbOeJCA4vmH20Oa2AJSXnzX0FyU/s1600/xcode-configure-anlyzing-message.png" imageanchor="1"><img border="0" height="127" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXZ7kA6fQVQOC2Ri7W6c8GnWqFkJJPs_4zx84H_Wrs0Ca4NhTtw2tOO2FdwwseCILacPaT_Vj7Wmv7Ss6vIQpiZGbiKKYUwuGgr5H4guiAV2cxc6H0PbOeJCA4vmH20Oa2AJSXnzX0FyU/s320/xcode-configure-anlyzing-message.png" width="320" /></a></div>
<br />
"Edit the scheme to enable analyzing, or cancel the action." with that "Edit Scheme ..." was not opening anything and I didn't notice anything extra in the schema editor to enable analyzing.<br />
<br />
I even created a clean new project to see if error would be present there as well, and it was.<br />
<br />
So after scratching my head a bit I just set a RUN_CLANG_STATIC_ANALYZER as true for the target/build where I needed it:<br />
<br />
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNHelxPpoDn-8ECMjWzOpStx2hitDw1hyKgB7LoKKo_z37008Z7xbgk4LmmZ1sVs6zVkhCVxDbEs8erXntBx639bxQbMvhj8ZqfVs4Et4BL6DVlxzlokt9MHnPzr5I7wt-4Ihr86I73bg/s1600/xcode-analyze-during-build.png" imageanchor="1"><img border="0" height="106" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNHelxPpoDn-8ECMjWzOpStx2hitDw1hyKgB7LoKKo_z37008Z7xbgk4LmmZ1sVs6zVkhCVxDbEs8erXntBx639bxQbMvhj8ZqfVs4Et4BL6DVlxzlokt9MHnPzr5I7wt-4Ihr86I73bg/s320/xcode-analyze-during-build.png" width="320" /></a></div>
<br />
This way I got the static analysis messages back.<br />
<br />
Hope this can help someone!<br />
<br />
Update. Or as Jaime Santana commented, just "<span style="background-color: white; color: #262626; font-family: Roboto, arial, sans-serif; font-size: 13px; line-height: 18.2px;">launch Analysis from the menu option Menu -> Product -> Analyze". Thank you Jamie, that worked!</span></div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com1tag:blogger.com,1999:blog-584619127557205820.post-9099103883196899132016-02-18T14:56:00.000+01:002016-02-18T14:56:16.276+01:00Note to self - concatenating rows into string with MSSQL<div dir="ltr" style="text-align: left;" trbidi="on">
Here is a sample code:<br />
<br />
select count(a.v2_icid), a.v2_icid,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><b><span style="color: red;">(select distinct(fullname) + ',' AS [text()] from systemuser u </span></b><br />
<b><span style="color: red;"><span class="Apple-tab-span" style="white-space: pre;"> </span>join account acc on acc.ownerid = u.systemuserid </span></b><br />
<b><span style="color: red;"><span class="Apple-tab-span" style="white-space: pre;"> </span>where acc.v2_icid = a.v2_icid For XML PATH ('')) [Users]</span></b><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> from account a<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>where statecode = 0 and a.v2_icid is not null<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>group by a.v2_icid<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>having count(a.v2_icid) > 1<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>order by a.v2_icid</div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-51295995966605306342015-12-07T15:11:00.002+01:002015-12-07T15:21:11.526+01:00So, here is my string dump for x64 in windbg<div dir="ltr" style="text-align: left;" trbidi="on">
Based on <a href="http://stackoverflow.com/questions/5349945/windbg-and-sos-how-do-i-print-dump-a-large-string">this</a> and <a href="http://stackoverflow.com/questions/20343045/how-to-dump-string-using-windbg-poi-function">that</a>.<br />
<br />
$$>a<"c:\_install\dumpstringtofolder.txt" 000007feed816500 1000 c:\temp\stringtest<br />
<br />
and the script:<br />
<br />
$$ Dumps the managed strings to a file<br />
$$ Platform x64<br />
$$ First argument is the string method table pointer<br />
$$ Second argument is the Min size of the string that needs to be used filter<br />
$$ the strings<br />
$$ Third is the path of the file<br />
.foreach ($string {!dumpheap -short -mt ${$arg1} -min ${$arg2}})<br />
{<br />
r@$t0= poi(${$string}+8)*2<br />
.writemem ${$arg3}${$string}.txt ${$string}+c L? @$t0<br />
}<br />
<br />
The only other thing I needed this time is this on one of the strings:<br />
<br />
!gcroot 0000000100e769f0<br />
<br />
To see:<br />
<br />
-> 0000000180006d08 System.Web.Caching.CacheMultiple<br />
-> 00000001800069c8 System.Web.Caching.CacheCommon<br />
-> 00000001800034a8 System.Web.RequestTimeoutManager<br />
....<br />
-> 00000004021b5740 System.Web.SessionState.InProcSessionState<br />
-> 00000004021b5288 System.Web.SessionState.SessionStateItemCollection<br />
....<br />
-> 0000000289779a58 ASP.ordercomposer_orderedit_aspx<br />
<b> -> 000000018c14fe38 XYZ.Ordering.Modules.OrderingViewStatePresister</b><br />
<b><br /></b>
So this time the root of the problem was in keeping viewstate in the session and not really purging not needed view state away. This was one of the legacy apps and reminded everyone the old none-tasty view state solution from MS :). Viva MVC and looking forward the day with no legacy ASP.NET apps we need to support :)!</div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-15378415325320383022014-05-20T23:13:00.001+02:002014-05-20T23:15:31.532+02:00NGINX + PostgreSQL + PostGIS - performance baseline/diff<div dir="ltr" style="text-align: left;" trbidi="on">
Just wanted to share some of the initial benchmark from http_load on the project I'm working right now. Why the excitement? I've been an MS oriented guy for the last 20 years and moving away from IIS and MSSQL (where you can be waiting 20-30 seconds for the initial IIS/.NET/SQL app startup) to <a href="http://nginx.org/">NGINX</a> with PostgreSQL stack is life changing - no exaggeration!<br />
<br />
So here is what I got on <a href="https://www.digitalocean.com/">Digital Ocean</a> lowest spec machine (1 core, 20GB SSD, 512 MB RAM, Ubuntu 12) with a bare NGINX:<br />
<br />
<pre class="prettyprint" style="background-color: #eeeeee; font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace; font-size: 12px; max-width: 70em; overflow: auto; padding: 0.5em;"><span class="lit" style="color: #006666;">34178</span><span class="pln"> fetches</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="lit" style="color: #006666;">10</span><span class="pln"> max parallel</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="lit" style="color: #006666;">683560</span><span class="pln"> bytes</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="kwd" style="color: #000088;">in</span><span class="pln"> </span><span class="lit" style="color: #006666;">5</span><span class="pln"> seconds
</span><span class="lit" style="color: #006666;">20</span><span class="pln"> mean bytes</span><span class="pun" style="color: #666600;">/</span><span class="pln">connection
</span><span class="lit" style="color: #006666;">6835.6</span><span class="pln"> fetches</span><span class="pun" style="color: #666600;">/</span><span class="pln">sec</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="lit" style="color: #006666;">136712</span><span class="pln"> bytes</span><span class="pun" style="color: #666600;">/</span><span class="pln">sec
msecs</span><span class="pun" style="color: #666600;">/</span><span class="pln">connect</span><span class="pun" style="color: #666600;">:</span><span class="pln"> </span><span class="lit" style="color: #006666;">0.0445469</span><span class="pln"> mean</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="lit" style="color: #006666;">0.937</span><span class="pln"> max</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="lit" style="color: #006666;">0.021</span><span class="pln"> min
</span><span class="pln" style="white-space: normal;">msecs</span><span class="pun" style="color: #666600; white-space: normal;">/</span><span class="pln" style="white-space: normal;">first</span><span class="pun" style="color: #666600; white-space: normal;">-</span><span class="pln" style="white-space: normal;">response</span><span class="pun" style="color: #666600; white-space: normal;">:</span><span class="pln" style="white-space: normal;"> </span><span class="lit" style="color: #006666; white-space: normal;">1.41242</span><span class="pln" style="white-space: normal;"> mean</span><span class="pun" style="color: #666600; white-space: normal;">,</span><span class="pln" style="white-space: normal;"> </span><span class="lit" style="color: #006666; white-space: normal;">101.975</span><span class="pln" style="white-space: normal;"> max</span><span class="pun" style="color: #666600; white-space: normal;">,</span><span class="pln" style="white-space: normal;"> </span><span class="lit" style="color: #006666; white-space: normal;">0.257</span><span class="pln" style="white-space: normal;"> min</span></pre>
<br />
And with the full nginx->postgresql with postgis searching for speed limits around submitted location (but only a few limits present in db for a moment):<br />
<br />
<pre class="prettyprint" style="background-color: #eeeeee; font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace; font-size: 12px; max-width: 70em; overflow: auto; padding: 0.5em;"><span class="lit" style="color: #006666;">5574</span><span class="pln"> fetches</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="lit" style="color: #006666;">10</span><span class="pln"> max parallel</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="lit" style="color: #006666;">6.22058e+06</span><span class="pln"> bytes</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="kwd" style="color: #000088;">in</span><span class="pln"> </span><span class="lit" style="color: #006666;">5</span><span class="pln"> seconds
</span><span class="lit" style="color: #006666;">1116</span><span class="pln"> mean bytes</span><span class="pun" style="color: #666600;">/</span><span class="pln">connection
</span><span class="lit" style="color: #006666;">1114.8</span><span class="pln"> fetches</span><span class="pun" style="color: #666600;">/</span><span class="pln">sec</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="lit" style="color: #006666;">1.24412e+06</span><span class="pln"> bytes</span><span class="pun" style="color: #666600;">/</span><span class="pln">sec
msecs</span><span class="pun" style="color: #666600;">/</span><span class="pln">connect</span><span class="pun" style="color: #666600;">:</span><span class="pln"> </span><span class="lit" style="color: #006666;">0.0561055</span><span class="pln"> mean</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="lit" style="color: #006666;">0.37</span><span class="pln"> max</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="lit" style="color: #006666;">0.023</span><span class="pln"> min
msecs</span><span class="pun" style="color: #666600;">/</span><span class="pln">first</span><span class="pun" style="color: #666600;">-</span><span class="pln">response</span><span class="pun" style="color: #666600;">:</span><span class="pln"> </span><span class="lit" style="color: #006666;">8.68285</span><span class="pln"> mean</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="lit" style="color: #006666;">187.733</span><span class="pln"> max</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="lit" style="color: #006666;">0.812</span><span class="pln"> min</span></pre>
<br />
So it got from almost 7k to 1k per second, still that's from the different universe compared to what IIS/.NET would do for me, and look at the machine spec! Plus, $0.0 for nginx + $0.0 for posgre/postgis - pure win!<br />
<br />
-- Stan.</div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-38456909681124218652013-11-29T21:51:00.000+01:002013-11-29T22:54:06.018+01:00Apple MKMapView vs. Google iOS SDK map - CPU, compass image, center and rotate.<div dir="ltr" style="text-align: left;" trbidi="on">
Why I didn't use native Apple's map a year ago when I was going through the options for my apps?<br />
<br />
I was looking for the "live" map that would be able to follow your location, option to rotate so your heading can be always on top of the map and while it rotates it should rotate street names gracefully so they are not shown upside down.<br />
<br />
Should I tell Apple maps for iOS6 failed miserably for all of those requirements. So I used Google's alternative. It gave me great rotation, street names handling and nothing to complain about.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggJqom0CDSYvI1-52EwyUlfdHjXkcVrAYYk0euatwDUXkw_d5iOzjI9YT8PsVsW6YHsyWyraGRlsPTwKFjgewSs7OdArBKmW0IVNXrCJ_QXH7OUQIakCTR4TUpC5HiRLy9Nm-TsUKHUTQ/s1600/google+map+speedo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="317" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggJqom0CDSYvI1-52EwyUlfdHjXkcVrAYYk0euatwDUXkw_d5iOzjI9YT8PsVsW6YHsyWyraGRlsPTwKFjgewSs7OdArBKmW0IVNXrCJ_QXH7OUQIakCTR4TUpC5HiRLy9Nm-TsUKHUTQ/s320/google+map+speedo.png" width="320" /></a></div>
<br />
<br />
<br />
Watching iOS7 location videos made me really intrigued, it looked like "oh, Apple fixed it all and brought us the map that can rotate correctly". I was really keen to try and after two months of fixing my apps for iOS7 and releasing them I finally got to try.... <b>And I'm not sure this is it.</b><br />
<br />
<b>Why?</b><br />
<b><br /></b>
You basically have an option to either center the map yourself or set it up to track by itself:<br />
<br />
<br />
<div class="p1">
[self.map setUserTrackingMode:[MKUserTrackingModeFollow|MKUserTrackingModeFollowWithHeading] animated:[true|false]</div>
<div class="p1">
<br /></div>
<div class="p1">
<b><span style="color: red;">Well, there are few problems here. </span></b></div>
<div class="p1">
<br /></div>
<div class="p1">
<b>Rotate and center sync.<span style="color: blue;"> </span></b>If you want to rotate with one of the automated tracking options, you'd probably need to sync your rotation with the user location tracking animation. Otherwise, for my naive and short attempts the rotation and auto-tracking create weird effect of user location floating around its center. I didn't follow the path of trying to sync that yet and will see if this is worth an effort.</div>
<div class="p1">
<br /></div>
<div class="p1">
<b>Compass image. </b>Small extra annoying factor here is that once you rotate the map (set the map camera heading) to something not equal zero, the "compass" thingy appears in the right upper corner:</div>
<div class="p1">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq6mDd8d97IREs1O_FueYIn8GZt6VYXeA3gKimreJWCOAop5SdipeodHMIAxT1V-sl_wIbLVqvFpEQyUGLvKQ-4OEB-ZROVCOt8cJlc9iNk_atYaOqfXBhaQ8QgCcRti_U5imNiX1BYaU/s1600/applemapcompass.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq6mDd8d97IREs1O_FueYIn8GZt6VYXeA3gKimreJWCOAop5SdipeodHMIAxT1V-sl_wIbLVqvFpEQyUGLvKQ-4OEB-ZROVCOt8cJlc9iNk_atYaOqfXBhaQ8QgCcRti_U5imNiX1BYaU/s1600/applemapcompass.png" /></a></div>
<div class="p1">
<br /></div>
<div class="p1">
<br /></div>
<div class="p1">
My first thought was - "oh, I'l move this thingy where I want or disable it for iPad version as I show heading elsewhere". Let me do a read up, let me google for it, let me study Apple's forum for it... What? I can't do it! I love Apple for things that were decided for us, it is part of their spirit and I'm glad they keep it even stronger now than before!</div>
<div class="p1">
<br /></div>
<div class="p1">
This compass thingy is not a big issue I can move my star button (that happened to be in this place by accident) - I'm not that picky.</div>
<div class="p1">
<br /></div>
<div class="p1">
<b>It has glitches.</b> From time to time it looks like map zoom is being reset for a moment and than re-established again. I can't really correlate it to whatever I'm doing (as I'm doing nothing but set camera's heading and I do for every location change while zoom "blink" only happens once in a longer while). And the first time I rotate it it goes through the field of black and white rectangular and then does it from time to time, probably when tiles has not been loaded yet for some area I suddenly need to expose by programmatic rotation. This never happens to the Google map.<br />
+ When changing programmatically (or by setting the auto option with WithHeading) heading from 360 to 1, Apple's map rotates -360 + 1 degree. Like, this can't be true? I'm probably just silly. But Google does it right, and it makes me feel less silly and more desperate.<br />
+ Compass image shows even when I have enableRotate to NO, but when phone points exactly to 0 heading, the compass image disappears. So when my user will drive exactly in North direction they know it by not seeing the image?! Very consistent!</div>
<div class="p1">
<br /></div>
<div class="p1">
<b>I can center and rotate all by myself.</b></div>
<div class="p1">
<br /></div>
<div class="p1">
I'm a big boy, if I proved it with Google maps I can prove it everywhere?</div>
<div class="p1">
<br /></div>
<div class="p1">
Ok. I'm loosing that extra smooth animation for centering the map should I tell. But it just looks as it does for the Google maps, that would suffice. Seems to work just ok. So I was sitting and looking at that center and rotate I put together thinking "Stan, you are a genius, you proved it!".</div>
<div class="p1">
<br /></div>
<div class="p1">
As I tend to spend few minutes in this state, I felt how my lap is getting hotter, and hotter .... Oh oh, this is my beloved temperature based CPU profiling instrument! </div>
<div class="p1">
<br /></div>
<div class="p1">
So here is the reason of why I'll be thinking twice now if I should use native Apple's map for the live map option, let me provide it here. On the top you'll see Apple's map consumption while centering and rotating and below it you'll see the same task executed by a Google map. If simulators doe this to my mac, I guess I can speculate the same CPU/battery consumption ratio will stay on real devices:</div>
<div class="p1">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjD4X221IfRIVfdJR_n3kI-3uJRqM_aM2xDq18QPEYefcVC4mhLr7hG9ZPorXk1so1IYRV8z4W5w5tcdr3EPluBr6gKtI6_6VNVkMQjW_wlgG-wDGjbEYR_iAwkQR_fx5gTU1JWc0lhBnw/s1600/Screen+Shot+2013-11-29+at+8_Fotor_Collage.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjD4X221IfRIVfdJR_n3kI-3uJRqM_aM2xDq18QPEYefcVC4mhLr7hG9ZPorXk1so1IYRV8z4W5w5tcdr3EPluBr6gKtI6_6VNVkMQjW_wlgG-wDGjbEYR_iAwkQR_fx5gTU1JWc0lhBnw/s640/Screen+Shot+2013-11-29+at+8_Fotor_Collage.png" width="480" /></a></div>
<div class="p1">
<br /></div>
<div class="p1">
My story ends here, enough for this evening, I need to re-group, re-think, re-try, re-study ....</div>
<div class="p1">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjagbfPvkrRnH4oCP0Tx1oFsJeTkEUjuwPCiaE9KzSpsPE_S30OkXV9-kf14yfmoa-x5ewgmBrcwIet_iWyG7NW0GCtqsoYSp60heU-6pV82-h0-4kCEEwBQWyZDB06YyuMHrBeOQcJwEk/s1600/woosah+(1).jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="165" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjagbfPvkrRnH4oCP0Tx1oFsJeTkEUjuwPCiaE9KzSpsPE_S30OkXV9-kf14yfmoa-x5ewgmBrcwIet_iWyG7NW0GCtqsoYSp60heU-6pV82-h0-4kCEEwBQWyZDB06YyuMHrBeOQcJwEk/s320/woosah+(1).jpg" width="320" /></a></div>
<div class="p1">
<br /></div>
<div class="p1">
<br /></div>
<div class="p1">
<br /></div>
<div class="p1">
<br /></div>
<br />
<br />
<br /></div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-13130321533131384032013-09-29T20:37:00.003+02:002013-09-29T22:29:42.531+02:00iOS 7 vs iOS 6 memory consumption. OMG?<div dir="ltr" style="text-align: left;" trbidi="on">
Known thing my app starts slower on iPhone 4 with iOS7 then it is on the same iPhone 4 with iOS6. This is pretty sad, but not the only sad thing...<br />
<div>
<br /></div>
<div>
As I'm profiling now the app before its soon to come release to AppStore, I got to the following screenshots for the fresh app start on iPhone 4 with iOS6:</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbNU3Hh7Sb4JWBh1b5q9IBl6E_GEasu7-uKz8sLOnBe2T3JjIZGyVoXZB4ALLH6iQu-KGfpw1Wv5c4OPa4VXFAOEdKCqJ3CS2QQypfAofdY1M5VgoFlTTPCDBqgFeuMgqb2IlY9WYDKmk/s1600/Screen+Shot+2013-09-29+at+7.43.07+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="289" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbNU3Hh7Sb4JWBh1b5q9IBl6E_GEasu7-uKz8sLOnBe2T3JjIZGyVoXZB4ALLH6iQu-KGfpw1Wv5c4OPa4VXFAOEdKCqJ3CS2QQypfAofdY1M5VgoFlTTPCDBqgFeuMgqb2IlY9WYDKmk/s640/Screen+Shot+2013-09-29+at+7.43.07+PM.png" width="640" /></a></div>
<div>
<br /></div>
<div>
Note the <b>1.55MB</b> number. And now, the sad thing, same fresh start on iPhone5 with iOS7:</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGgEQjCtybhkiM8k2Q8MOImTOf5HD2cVjqbJhIdz1B9LTTRlzZA0_gLQ6iRurSq-HA6CpQZxyllrt9t8KmjkYF3Do2pCHc22SY2tIjbGpjcZ4_nLto-eEZaMXK98Hed1RNUaY74Ztd0Lk/s1600/Screen+Shot+2013-09-29+at+8.15.15+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="294" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGgEQjCtybhkiM8k2Q8MOImTOf5HD2cVjqbJhIdz1B9LTTRlzZA0_gLQ6iRurSq-HA6CpQZxyllrt9t8KmjkYF3Do2pCHc22SY2tIjbGpjcZ4_nLto-eEZaMXK98Hed1RNUaY74Ztd0Lk/s640/Screen+Shot+2013-09-29+at+8.15.15+PM.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Noticed that <b>8.21MB?! </b>I currently only have iOS7 installed on iPhone 5, so I can't compare iPhone 4 iOS7 vs iOS6 consumption, but I believe this iPhone 5/4 factor should not play any role here. It is just iOS thingy. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
While not that sad for iPhone 5/5s, it is pretty bad news for my users that are still on iPhone 4, apps are going to consume more. All apps, not only mine... App startup is becoming definitely heavier and those extra allocations in iOS7 are surely standing for more work done by iOS7 while starting the app.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Having read Steve's biography, it looks to me like a step away from the <a href="http://www.folklore.org/StoryView.py?story=Saving_Lives.txt">"saving lives"</a> approach to plain MS's "throw more memory on it - problem solved".</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
May I be wrong? I hope!</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Yours,</div>
<div class="separator" style="clear: both; text-align: left;">
Stan.</div>
<div>
<br /></div>
</div>
stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-6166178902010414802013-05-02T16:41:00.001+02:002013-05-02T16:46:11.727+02:00A very short note on migrating from Spring.NET 1.1.x to 1.3.x or 2.x<p>I used to have something like this in my code for getting the Spring.NET context:</p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">using</span> (IApplicationContext ctx = ContextRegistry.GetContext())</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> {</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> traceListener =</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> (TraceListener) ctx.GetObject(initializationData);</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> }</pre>
<!--CRLF--></div>
</div>
<p>After upgrade to 1.3.2 I was rewarded with:</p>
<p><font color="#ff0000"><strong>No context registered under name '{0}'. Use the 'RegisterContext' method or the 'spring/context' section from your configuration file.</strong></font></p>
<p>Short investigation showed Spring.NET is not then getting the context initiated again if it was removed (I didn’t realize that) by using/Dispose pattern.</p>
<p>I’ll let it to the conscious of spring.NET authors to decide if this is a correct implementation of disposal pattern from their side, corrected line of code now looks just like:</p>
<p></p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">traceListener =</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> (TraceListener) ctx.GetObject(initializationData);</pre>
<!--CRLF--></div>
</div> stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0tag:blogger.com,1999:blog-584619127557205820.post-49072232803511481912013-04-15T19:50:00.000+02:002013-04-15T19:50:00.339+02:00Sqllite - Month and Year from unixepoch column<p>Just wanted to share how to get month and year from sqllite column that keeps unixepoch numeric value. Without further ado, here is a sample:</p> <div id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">SELECT cast(strftime(<span style="color: #006080">'%m'</span>, datetime(start, <span style="color: #006080">'unixepoch'</span>)) <span style="color: #0000ff">as</span> integer) <span style="color: #0000ff">as</span> month, cast(strftime(<span style="color: #006080">'%Y'</span>, datetime(start, <span style="color: #006080">'unixepoch'</span>)) <span style="color: #0000ff">as</span> integer) <span style="color: #0000ff">as</span> year, * FROM track <span style="color: #0000ff">where</span> month=4</pre>
<!--CRLF--></div>
</div>
<p>Here is what results look like:</p>
<p><a href="http://lh4.ggpht.com/-R2mtVDGWCcU/UWwF23FwtZI/AAAAAAAADXs/Fh-NBeyV104/s1600-h/image%25255B4%25255D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-HcVSD5nuSj8/UWwF3ndEgiI/AAAAAAAADX0/ja-t8VzXbso/image_thumb%25255B2%25255D.png?imgmax=800" width="517" height="76" /></a> </p>
<p>What about null values?</p>
<p>After nullifying end value, and running the following query:</p>
<pre class="csharpcode">SELECT cast(strftime(<span class="str">'%m'</span>, datetime(end, <span class="str">'unixepoch'</span>)) <span class="kwrd">as</span> integer) <span class="kwrd">as</span> month, cast(strftime(<span class="str">'%Y'</span>, datetime(end, <span class="str">'unixepoch'</span>)) <span class="kwrd">as</span> integer) <span class="kwrd">as</span> year, * FROM track</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>the result is:
<p><a href="http://lh3.ggpht.com/-gLCGBu6Xhfg/UWwF4STxtdI/AAAAAAAADX8/0_B2lvXFfMo/s1600-h/image%25255B9%25255D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-VYUuwJTjPpo/UWwF5VmnlJI/AAAAAAAADYE/kI4_CC72A2Q/image_thumb%25255B5%25255D.png?imgmax=800" width="519" height="87" /></a> </p>
<p>What about zeroes in the source column? Here is the result:</p>
<p><a href="http://lh6.ggpht.com/-EHNf4sL6CZM/UWwF6PfhbuI/AAAAAAAADYM/FHlHY9Gvem4/s1600-h/image%25255B16%25255D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-ywn4tvq53ZI/UWwF60I0R-I/AAAAAAAADYU/HAy2AGuFKZg/image_thumb%25255B10%25255D.png?imgmax=800" width="519" height="96" /></a> </p>
<p>What is my take away from all that? From my design perspective I definitely don’t want to have some fields for dates that would be NOT NULL DEFAULT(0), I better have them nullable with null value representing a missing date, not a 0.</p>
<p><a href="http://www.sqlite.org/lang_datefunc.html" target="_blank">Official sqlite date and time functions page</a></p> stanhttp://www.blogger.com/profile/17953164778965672435noreply@blogger.com0