tag:blogger.com,1999:blog-111603052024-03-13T09:10:57.560+05:30SolutionEOD Blog of a ProgrammerYogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.comBlogger86125tag:blogger.com,1999:blog-11160305.post-60359066755984325542024-03-13T09:10:00.000+05:302024-03-13T09:10:25.883+05:30Heavy Memory Usage of the Regression Test in XCTest<p></p>While recently wrestling with a regression test for my Swift project using the XCTest framework, I ventured into the tumultuous world of a heavily multithreaded application. Ensuring the absence of timing issues was like defusing a bomb – one wrong wire, and boom! So, what's a developer to do? Run the code tens of thousands of times, of course (or even more for the marathon runners of applications), and keep your fingers crossed for any anomalies.<br /><br />My trusty XCTest framework was the stage, and my test code, which cheerfully returned results asynchronously, demanded I master the classic XCTest dance of expectation(...) and waitForExpectations(...) moves. All seemed well as the test passed with flying colors for a few thousand iterations. However, as I ambitiously cranked up the numbers, strange gremlins began to pop up. The memory usage skyrocketed, adding a whopping 90 MB per 10,000 iterations – definitely not a feature I had intended to implement!<br /><br />I dove into the depths of Instruments, yet no memory leaks waved back at me. Puzzling! Yet, I noticed waitForExpectations was having a bit too much fun allocating objects like NSString left and right. My online detective work on Google and StackOverflow turned up zilch – it seemed I was charting uncharted waters.<p></p>Refusing to be defeated, me and my digital buddy ChatGPT kept on going into the uncharted territory with me as novis to Swift while ChatGPT blind beyond 20 ft. I scrutinized the allocation patterns revealed by Instruments with a detective's eye. This careful observation led to a pivotal "Eureka!" moment. It dawned on me to employ an <span style="font-family: courier;">autoreleasepool</span> within the scope of each iteration. This strategic move, akin to a well-crafted chess play, was not just a stroke of luck but a calculated decision based on the insights gleaned. And, like a charm, this adept adjustment worked wonders, effectively dispelling the memory bloat gremlins back into the abyss from whence they came.<br /><br /><br />Here is a sample test code anyone can run in our XCTest project, to reproduce the issue and verify the solution. <br /><br /><ol style="background: rgb(247, 247, 247); box-sizing: border-box; color: #cccccc; font-family: monospace; font-size: 15px; margin: 0px; padding: 0px 0px 0px 55px;"><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="kw1" style="box-sizing: border-box; color: #b833a1;">func</span> testAsyncOperationInLoop<span class="br0" style="box-sizing: border-box;">(</span><span class="br0" style="box-sizing: border-box;">)</span> <span class="br0" style="box-sizing: border-box;">{</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="kw1" style="box-sizing: border-box; color: #b833a1;">let</span> iterationCount = <span class="nu0" style="box-sizing: border-box; color: #1c00cf;">50000</span> <span class="co1" style="box-sizing: border-box; color: #008312;">// Number of iterations in the loop</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> </div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="kw1" style="box-sizing: border-box; color: #b833a1;">for</span> i <span class="kw1" style="box-sizing: border-box; color: #b833a1;">in</span> <span class="nu0" style="box-sizing: border-box; color: #1c00cf;">1</span><span class="sy0" style="box-sizing: border-box;">...</span><span class="me1" style="box-sizing: border-box; color: #508187;">iterationCount</span> <span class="br0" style="box-sizing: border-box;">{</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> autoreleasepool <span class="br0" style="box-sizing: border-box;">{</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> </div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="co1" style="box-sizing: border-box; color: #008312;">// Create a new expectation for each iteration of the loop</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="kw1" style="box-sizing: border-box; color: #b833a1;">let</span> expectation = <span class="kw1" style="box-sizing: border-box; color: #b833a1;">self</span>.<span class="me1" style="box-sizing: border-box; color: #508187;">expectation</span><span class="br0" style="box-sizing: border-box;">(</span>description<span class="sy0" style="box-sizing: border-box;">:</span> <span class="st0" style="box-sizing: border-box; color: #c41a16;">"Async operation <span class="es0" style="box-sizing: border-box;">\(</span>i)"</span><span class="br0" style="box-sizing: border-box;">)</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> </div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="kw1" style="box-sizing: border-box; color: #b833a1;">if</span> i <span class="sy0" style="box-sizing: border-box;">></span> <span class="nu0" style="box-sizing: border-box; color: #1c00cf;">0</span> <span class="sy0" style="box-sizing: border-box;">&&</span> i <span class="sy0" style="box-sizing: border-box;">%</span> <span class="br0" style="box-sizing: border-box;">(</span><span class="nu0" style="box-sizing: border-box; color: #1c00cf;">10000</span><span class="br0" style="box-sizing: border-box;">)</span> <span class="sy0" style="box-sizing: border-box;">==</span> <span class="nu0" style="box-sizing: border-box; color: #1c00cf;">0</span> <span class="br0" style="box-sizing: border-box;">{</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="kw3" style="box-sizing: border-box; color: #508187;">print</span><span class="br0" style="box-sizing: border-box;">(</span><span class="st0" style="box-sizing: border-box; color: #c41a16;">"breaking for a breath"</span><span class="br0" style="box-sizing: border-box;">)</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="br0" style="box-sizing: border-box;">}</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> </div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="co1" style="box-sizing: border-box; color: #008312;">// Simulate an asynchronous operation</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> DispatchQueue.<span class="me1" style="box-sizing: border-box; color: #508187;">global</span><span class="br0" style="box-sizing: border-box;">(</span><span class="br0" style="box-sizing: border-box;">)</span>.<span class="me1" style="box-sizing: border-box; color: #508187;">asyncAfter</span><span class="br0" style="box-sizing: border-box;">(</span>deadline<span class="sy0" style="box-sizing: border-box;">:</span> .<span class="me1" style="box-sizing: border-box; color: #508187;">now</span><span class="br0" style="box-sizing: border-box;">(</span><span class="br0" style="box-sizing: border-box;">)</span> <span class="sy0" style="box-sizing: border-box;">+</span> <span class="nu0" style="box-sizing: border-box; color: #1c00cf;">1.0</span><span class="sy0" style="box-sizing: border-box;">/</span><span class="nu0" style="box-sizing: border-box; color: #1c00cf;">100000</span><span class="br0" style="box-sizing: border-box;">)</span> <span class="br0" style="box-sizing: border-box;">{</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> expectation.<span class="me1" style="box-sizing: border-box; color: #508187;">fulfill</span><span class="br0" style="box-sizing: border-box;">(</span><span class="br0" style="box-sizing: border-box;">)</span> <span class="co1" style="box-sizing: border-box; color: #008312;">// Fulfill the expectation once the operation is completed</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="br0" style="box-sizing: border-box;">}</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> </div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="co1" style="box-sizing: border-box; color: #008312;">// Wait for the expectation to be fulfilled, with a timeout</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> waitForExpectations<span class="br0" style="box-sizing: border-box;">(</span>timeout<span class="sy0" style="box-sizing: border-box;">:</span> <span class="nu0" style="box-sizing: border-box; color: #1c00cf;">2</span><span class="br0" style="box-sizing: border-box;">)</span> <span class="br0" style="box-sizing: border-box;">{</span> error <span class="kw1" style="box-sizing: border-box; color: #b833a1;">in</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="kw1" style="box-sizing: border-box; color: #b833a1;">if</span> <span class="kw1" style="box-sizing: border-box; color: #b833a1;">let</span> error = error <span class="br0" style="box-sizing: border-box;">{</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> XCTFail<span class="br0" style="box-sizing: border-box;">(</span><span class="st0" style="box-sizing: border-box; color: #c41a16;">"waitForExpectations errored: <span class="es0" style="box-sizing: border-box;">\(</span>error)"</span><span class="br0" style="box-sizing: border-box;">)</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="br0" style="box-sizing: border-box;">}</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="br0" style="box-sizing: border-box;">}</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="br0" style="box-sizing: border-box;">}</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="br0" style="box-sizing: border-box;">}</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> </div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="kw3" style="box-sizing: border-box; color: #508187;">print</span><span class="br0" style="box-sizing: border-box;">(</span><span class="st0" style="box-sizing: border-box; color: #c41a16;">"All iterations completed"</span><span class="br0" style="box-sizing: border-box;">)</span></div></li><li class="li1" style="-webkit-user-select: text; background: rgb(255, 255, 255); border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; box-sizing: border-box; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace, serif; font-size: 13px; margin: 0px 0px 0px -7px; overflow-wrap: break-word; padding: 0px 8px; position: relative; vertical-align: top;"><div class="de1" style="background-attachment: scroll; background-clip: border-box; background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; box-sizing: border-box; font-family: monospace; font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 1em; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: 1.2em; margin: 0px; padding: 0px; vertical-align: top;"> <span class="br0" style="box-sizing: border-box;">}</span></div></li></ol>Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com0tag:blogger.com,1999:blog-11160305.post-3063893900665815072024-02-07T21:26:00.000+05:302024-02-07T21:26:19.460+05:30Decoding the Mystery: How Food Label Decoder Simplifies Your Grocery Shopping<p style="text-align: left;">This blog is about a custom ChatGPT model that you can use if you have ChatGPT 4 account. Follow this link to use the custom model:<a href="https://chat.openai.com/g/g-c2AWb78Mr-food-label-decoder"> https://chat.openai.com/g/g-c2AWb78Mr-food-label-decoder </a></p><div style="text-align: left;"><br /></div><div style="text-align: left;">In today’s fast-paced world, our dependence on packaged foods has become more a necessity than a choice. Amidst the rush of daily life, who has the time to decode the complex list of ingredients on the back of every package? Yet, understanding these labels is crucial, as it's about more than just counting calories—it's about knowing what we're truly feeding ourselves and our loved ones.</div><h2 style="text-align: left;">The Hidden Truth Behind Packaged Foods</h2><div style="text-align: left;">Packaged food items are a marvel of modern convenience, but this convenience often comes with a hidden cost. To stay competitive, ensure a long shelf life, and appeal to consumer tastes, companies often resort to using a range of additives, preservatives, and sugars. These ingredients can be cleverly disguised under scientific names, making them nearly impossible for the average shopper to recognize.<br /><p style="text-align: left;">Moreover, with the ever-evolving "health trends," many products are marketed as "healthy" options, leveraging buzzwords like "natural," "organic," or "low-fat." However, a closer inspection of their ingredient lists often reveals a different story. How many times have you picked up a product, enticed by its health claims, only to find it packed with unpronounceable chemicals or excessive sugars?</p></div><h2 style="text-align: left;">Enter the Food Label Decoder</h2><div style="text-align: left;">This is where the <a href="https://chat.openai.com/g/g-c2AWb78Mr-food-label-decoder" target="_blank">Food Label Decoder</a> comes into play—a tool designed to bridge the gap between confusing labels and informed dietary choices. Powered by ChatGPT's Artificial Intelligence, it offers a simple yet revolutionary approach: just take a picture of the food label, share any specific dietary preferences or health concerns, and let the AI do the rest.<br /><a href="https://chat.openai.com/g/g-c2AWb78Mr-food-label-decoder">The Decoder </a>breaks down the jargon into simple, understandable terms. It evaluates the major ingredients, sugars, preservatives, artificial components, potential allergens, and more. It even gives a health snapshot using emojis, making it easier to grasp the nutritional value at a glance.</div><h2 style="text-align: left;">Why Trust Food Label Decoder?</h2><div style="text-align: left;">You might wonder, why trust an AI with something as personal as your dietary choices? The answer is simple: because it was created to solve real, everyday dilemmas—ones that I faced in my own life. Choosing between Product A and Product B, both claiming to be the healthier option, was a constant struggle due to the coded language of ingredients lists.<br /><p style="text-align: left;">Food Label Decoder was born out of a need for transparency and simplicity. It cuts through the marketing noise, offering clear, unbiased information. It doesn't just tell you what's in your food; it helps you understand what that means for you, based on your unique health goals or dietary restrictions.</p></div><h2 style="text-align: left;">Making Informed Choices Has Never Been Easier</h2><div style="text-align: left;">The beauty of the Food Label Decoder lies in its simplicity and accessibility. It empowers you to make informed decisions, turning the daunting task of reading labels into a quick, straightforward process. Whether you're navigating dietary restrictions, managing health conditions, or simply striving for a healthier lifestyle, the Decoder is your personal guide in the complex world of food shopping.</div><h2 style="text-align: left;">Act on Your Health</h2><div><p style="text-align: left;">So, the next time you find yourself standing in the grocery aisle, perplexed by the list of ingredients on a product, remember that help is just a <a href="https://chat.openai.com/g/g-c2AWb78Mr-food-label-decoder" target="_blank">click away</a>. The Food Label Decoder is more than just a tool; it's a movement towards a healthier, more informed society. It's time to take control of what we eat, one product at a time.</p>Why not start today? Take the first step towards becoming a more informed consumer and see the difference it makes in your shopping habits. After all, the best dietary choices are those made with confidence and clarity. Let's embark on this journey together, towards a healthier, happier you.</div><div><br /></div>Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com0tag:blogger.com,1999:blog-11160305.post-32424219958075324342022-09-07T23:21:00.004+05:302022-09-15T00:37:28.633+05:30Useful Perforce Commands<p> Perfoce Commands are especially useful when you are working on multiple branches and you don't want to download all branches but want to get some information. </p><p>Before you proceed make sure you understand how wild cards work in perforce command: <a href="https://www.perforce.com/manuals/cmdref/Content/CmdRef/filespecs.html " rel="nofollow" target="_blank">https://www.perforce.com/manuals/cmdref/Content/CmdRef/filespecs.html </a></p><p><span style="font-size: large;">Search Text</span> in All Readme.txt at any subfolder level of <span style="color: red; font-family: Consolas;">//depot/xxx/yyy/abc/</span></p><p></p><p class="MsoNormal"><span style="color: red; font-family: Consolas;">p4 grep -i -e
"mytext" //depot/xxx/yyy/abc/.../Readme.txt<o:p></o:p></span></p><p class="MsoNormal"><span style="font-family: Consolas;"><span style="font-size: 14.6667px;">or (to cover .md and .txt files)</span></span></p><p class="MsoNormal"><span style="font-family: Consolas; font-size: 11pt; mso-ansi-language: EN-IN; mso-bidi-font-family: Calibri; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><span style="color: red;">p4 grep -s -e -i "punta"
//depot/iView/GTM_Branches/Release/.../Readme.*</span></span></p><p class="MsoNormal"><span style="font-family: inherit;"><span style="font-size: large;"><br /></span></span></p><p class="MsoNormal"><span style="font-family: inherit;"><span style="font-size: large;">Search Dire</span><span style="font-family: inherit;"><span style="font-size: large;">ctory</span> </span></span><span style="font-size: 11pt;"><span style="font-family: inherit;">by name</span></span></p><p class="MsoNormal"><span style="color: red; font-family: Consolas;">p4 dirs -i
"//depot/xxx/yyy/abc/*/def/dir_to_search"<o:p></o:p></span></p><p></p><p class="MsoNormal"><span>also,</span></p><p class="MsoNormal">
</p><p class="MsoNormal"><span style="color: red; font-family: Consolas;">p4 dirs -i
"</span><span style="color: red; font-family: Consolas;">//depot/xxx/yyy/abc/*/def/*dir_to_search*</span><span style="color: red; font-family: Consolas;">"<o:p></o:p></span></p><p>for searching file, use "files" command instead of "dirs command.</p><p class="MsoNormal">Use @@1 instead of * for single level search</p><p><span style="font-size: large;">Get Last Check-in</span> info for a <span style="font-size: large;">directory</span></p><p></p><p class="MsoNormal"><span style="color: red; font-family: Consolas;">p4 changes -m 1
"</span><span style="color: red; font-family: Consolas;">//depot/xxx/yyy/abc/*/def</span><span style="color: red; font-family: Consolas;">/…"<o:p></o:p></span></p><br /><p></p><p><span style="font-size: large;">Diff between two files</span></p><p><span style="color: red; font-family: Consolas;">p4 diff</span> <span style="color: red; font-family: Consolas;">"</span><span style="color: red; font-family: Consolas;">//depot/xxx/def.txt" </span><span style="color: red; font-family: Consolas;">"</span><span style="color: red; font-family: Consolas;">//depot/yyy/def.txt"</span></p><p><span style="font-size: large;">File Sizes </span>by name</p><p><span style="color: red; font-family: Consolas;">p4 sizes -h </span><span style="color: red; font-family: Consolas;">"</span><span style="color: red; font-family: Consolas;">//depot/.../def.txt" </span></p><p><span style="color: red; font-family: Consolas;"><br /></span></p><p><br /></p><p><br /></p>Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com0tag:blogger.com,1999:blog-11160305.post-53661395812103695732021-10-07T17:26:00.019+05:302021-10-07T18:00:48.171+05:30Break the sleep and leave the scope immediately immediately!<p>I wanted to write a quick and dirty code... but I didn't want to make it lousy in execution. Had simple requirement: <b>Run a piece of code in a separate thread every 6 seconds but have ability to terminate (almost) immediately. </b>Like any other lousy programmer, I didn't want to implement a timer (which is lengthy process in C++). So I stumbled upon <a href="https://www.tutorialspoint.com/how-do-i-terminate-a-thread-in-cplusplus11" rel="nofollow" target="_blank">a solution</a> which uses <span style="font-family: courier;">std::future</span> to terminate the sleep immediately and doesn't execute anything once the future times out. Even if I was using <span style="font-family: courier;">while </span>loop instead of <span style="font-family: courier;">do..while</span>, it would have come out of <u>the scope </u>immediately. I am publishing it here as my example is more clear and that "Bad bad code." is present in that solution. Happy programming!</p><p><br /></p><p>to compile: > <span style="font-family: courier;">g++ -pthread test.cpp</span></p><p><span style="font-family: courier;"><br /></span></p>
<div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #557799">#include <thread></span>
<span style="color: #557799">#include <iostream></span>
<span style="color: #557799">#include <assert.h></span>
<span style="color: #557799">#include <chrono></span>
<span style="color: #557799">#include <future></span>
<span style="color: #008800; font-weight: bold">using</span> <span style="color: #008800; font-weight: bold">namespace</span> std;
<span style="color: #333399; font-weight: bold">void</span> <span style="color: #0066BB; font-weight: bold">threadFunction</span>(std<span style="color: #333333">::</span>future<span style="color: #333333"><</span><span style="color: #333399; font-weight: bold">void</span><span style="color: #333333">></span> future){
std<span style="color: #333333">::</span>cout <span style="color: #333333"><<</span> <span style="background-color: #fff0f0">"Starting the thread"</span> <span style="color: #333333"><<</span> std<span style="color: #333333">::</span>endl;
<span style="color: #008800; font-weight: bold">do</span> {
std<span style="color: #333333">::</span>cout <span style="color: #333333"><<</span> <span style="background-color: #fff0f0">"Executing the thread....."</span> <span style="color: #333333"><<</span> std<span style="color: #333333">::</span>endl;
<span style="color: #888888">//std::this_thread::sleep_for(std::chrono::milliseconds(6000)); //bad bad code</span>
} <span style="color: #008800; font-weight: bold">while</span> (future.wait_for(std<span style="color: #333333">::</span>chrono<span style="color: #333333">::</span>milliseconds(<span style="color: #0000DD; font-weight: bold">6000</span>)) <span style="color: #333333">==</span> std<span style="color: #333333">::</span>future_status<span style="color: #333333">::</span>timeout);
std<span style="color: #333333">::</span>cout <span style="color: #333333"><<</span> <span style="background-color: #fff0f0">"Thread Terminated"</span> <span style="color: #333333"><<</span> std<span style="color: #333333">::</span>endl;
}
main(){
std<span style="color: #333333">::</span>promise<span style="color: #333333"><</span><span style="color: #333399; font-weight: bold">void</span><span style="color: #333333">></span> signal_exit; <span style="color: #888888">//create promise object</span>
std<span style="color: #333333">::</span>future<span style="color: #333333"><</span><span style="color: #333399; font-weight: bold">void</span><span style="color: #333333">></span> future <span style="color: #333333">=</span> signal_exit.get_future();<span style="color: #888888">//create future objects</span>
std<span style="color: #333333">::</span><span style="color: #008800; font-weight: bold">thread</span> my_thread(<span style="color: #333333">&</span>threadFunction, std<span style="color: #333333">::</span>move(future)); <span style="color: #888888">//start thread, and move future</span>
std<span style="color: #333333">::</span>this_thread<span style="color: #333333">::</span>sleep_for(std<span style="color: #333333">::</span>chrono<span style="color: #333333">::</span>seconds(<span style="color: #0000DD; font-weight: bold">7</span>)); <span style="color: #888888">//wait for 7 seconds</span>
std<span style="color: #333333">::</span>cout <span style="color: #333333"><<</span> <span style="background-color: #fff0f0">"Threads will be stopped soon...."</span> <span style="color: #333333"><<</span> std<span style="color: #333333">::</span>endl;
signal_exit.set_value(); <span style="color: #888888">//set value into promise</span>
my_thread.join(); <span style="color: #888888">//join the thread with the main thread</span>
std<span style="color: #333333">::</span>cout <span style="color: #333333"><<</span> <span style="background-color: #fff0f0">"Doing task in main function"</span> <span style="color: #333333"><<</span> std<span style="color: #333333">::</span>endl;
}
</pre></div>
Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com0tag:blogger.com,1999:blog-11160305.post-27297155892140621862020-09-22T00:37:00.004+05:302020-09-22T00:43:01.916+05:30Simple GroupBy Function in for Python<p>After a lot of research I found that Python has no good groupby function that you can use in a single line (like Linq GroupBy of C#). For that, I've made a sample reusable groupby function that works with one or more keys, I wouldn't say it has great performance (actually far from it). But, it works and it is easier to use :) </p><p>You may want to make changes based on your input:</p><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><div><span style="color: #c586c0;">import</span> copy</div><div><span style="color: #c586c0;">import</span> itertools</div><br /><div><span style="color: #569cd6;">def</span> yogee<span style="color: #dcdcaa;">_groupby</span>(<span style="color: #9cdcfe;">coll</span>, <span style="color: #9cdcfe;">keys</span>):</div><br /><div> copied_collection = copy.deepcopy(coll)</div><div> master_key = <span style="color: #ce9178;">""</span></div><br /><div> <span style="color: #c586c0;">if</span> <span style="color: #dcdcaa;">len</span>(keys) > <span style="color: #b5cea8;">1</span>:</div><div> copied_collection = copy.deepcopy(coll)</div><div> <span style="color: #c586c0;">for</span> key <span style="color: #c586c0;">in</span> keys:</div><div> master_key = master_key + key</div><div> </div><div> <span style="color: #c586c0;">for</span> an_element <span style="color: #c586c0;">in</span> copied_collection:</div><div> element_key = <span style="color: #ce9178;">""</span></div><div> <span style="color: #c586c0;">for</span> key <span style="color: #c586c0;">in</span> keys:</div><div> element_key = element_key + an_element[key]</div><div> an_element[master_key] = element_key</div><div> <span style="color: #c586c0;">else</span>:</div><div> master_key = keys[<span style="color: #b5cea8;">0</span>]</div><br /><div> grouped = {}</div><div> sorted_collection = <span style="color: #dcdcaa;">sorted</span>(copied_collection, <span style="color: #9cdcfe;">key</span> = <span style="color: #569cd6;">lambda</span> <span style="color: #9cdcfe;">item</span>: item[master_key])</div><div> <span style="color: #c586c0;">for</span> k, g <span style="color: #c586c0;">in</span> itertools.groupby(sorted_collection, <span style="color: #569cd6;">lambda</span> <span style="color: #9cdcfe;">item</span>: item[master_key]):</div><div> group = <span style="color: #4ec9b0;">list</span>(g)</div><div> <span style="color: #c586c0;">if</span> <span style="color: #dcdcaa;">len</span>(keys) > <span style="color: #b5cea8;">1</span>:</div><div> <span style="color: #c586c0;">for</span> an_element <span style="color: #c586c0;">in</span> group:</div><div> an_element.pop(master_key, <span style="color: #569cd6;">None</span>)</div><div> </div><div> grouped[k] = group</div><div> <span style="color: #c586c0;">return</span> grouped</div><br /><div><span style="color: #569cd6;"><br /></span></div><div><span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">test_groupby_2</span>():</div><div> test_data = [</div><div> {</div><div> <span style="color: #ce9178;">"E1"</span>: <span style="color: #ce9178;">"V1"</span>,</div><div> <span style="color: #ce9178;">"E2"</span>: <span style="color: #ce9178;">"V2"</span>,</div><div> <span style="color: #ce9178;">"E3"</span>: [<span style="color: #ce9178;">"V31"</span>,<span style="color: #ce9178;">"V32"</span>,<span style="color: #ce9178;">"V33"</span>,<span style="color: #ce9178;">"V34"</span>],</div><div> <span style="color: #ce9178;">"E3"</span>: {<span style="color: #ce9178;">"E31"</span>:<span style="color: #ce9178;">"V31"</span>,<span style="color: #ce9178;">"E32"</span>: <span style="color: #ce9178;">"V32"</span>,<span style="color: #ce9178;">"E33"</span>: <span style="color: #ce9178;">"V33"</span>,<span style="color: #ce9178;">"E34"</span>:<span style="color: #ce9178;">"V34"</span>}</div><div> },</div><div> {</div><div> <span style="color: #ce9178;">"E1"</span>: <span style="color: #ce9178;">"W1"</span>,</div><div> <span style="color: #ce9178;">"E2"</span>: <span style="color: #ce9178;">"W2"</span>,</div><div> <span style="color: #ce9178;">"E3"</span>: [<span style="color: #ce9178;">"W31"</span>,<span style="color: #ce9178;">"W32"</span>,<span style="color: #ce9178;">"W33"</span>,<span style="color: #ce9178;">"W34"</span>],</div><div> <span style="color: #ce9178;">"E3"</span>: {<span style="color: #ce9178;">"E31"</span>:<span style="color: #ce9178;">"W31"</span>,<span style="color: #ce9178;">"E32"</span>: <span style="color: #ce9178;">"W32"</span>,<span style="color: #ce9178;">"E33"</span>: <span style="color: #ce9178;">"W33"</span>,<span style="color: #ce9178;">"E34"</span>:<span style="color: #ce9178;">"W34"</span>}</div><div> },</div><div> {</div><div> <span style="color: #ce9178;">"E1"</span>: <span style="color: #ce9178;">"V1"</span>,</div><div> <span style="color: #ce9178;">"E2"</span>: <span style="color: #ce9178;">"V2"</span>,</div><div> <span style="color: #ce9178;">"E3"</span>: [<span style="color: #ce9178;">"VV31"</span>,<span style="color: #ce9178;">"VV32"</span>,<span style="color: #ce9178;">"VV33"</span>,<span style="color: #ce9178;">"VV34"</span>],</div><div> <span style="color: #ce9178;">"E3"</span>: {<span style="color: #ce9178;">"E31"</span>:<span style="color: #ce9178;">"VV31"</span>,<span style="color: #ce9178;">"E32"</span>: <span style="color: #ce9178;">"VV32"</span>,<span style="color: #ce9178;">"E33"</span>: <span style="color: #ce9178;">"VV33"</span>,<span style="color: #ce9178;">"E34"</span>:<span style="color: #ce9178;">"VV34"</span>}</div><div> },</div><div> {</div><div> <span style="color: #ce9178;">"E1"</span>: <span style="color: #ce9178;">"V1"</span>,</div><div> <span style="color: #ce9178;">"E2"</span>: <span style="color: #ce9178;">"V22"</span>,</div><div> <span style="color: #ce9178;">"E3"</span>: [<span style="color: #ce9178;">"X31"</span>,<span style="color: #ce9178;">"X32"</span>,<span style="color: #ce9178;">"X33"</span>,<span style="color: #ce9178;">"X34"</span>],</div><div> <span style="color: #ce9178;">"E3"</span>: {<span style="color: #ce9178;">"E31"</span>:<span style="color: #ce9178;">"X31"</span>,<span style="color: #ce9178;">"E32"</span>: <span style="color: #ce9178;">"X32"</span>,<span style="color: #ce9178;">"E33"</span>: <span style="color: #ce9178;">"X33"</span>,<span style="color: #ce9178;">"E34"</span>:<span style="color: #ce9178;">"X34"</span>}</div><div> },</div><div> ]</div><div> grouped = yogee_groupby(test_data, [<span style="color: #ce9178;">"E1"</span>, <span style="color: #ce9178;">"E2"</span>])</div><div> <span style="color: #dcdcaa;">print</span>(grouped)</div><div> grouped = yogee_groupby(test_data, [<span style="color: #ce9178;">"E1"</span>])</div><div> <span style="color: #dcdcaa;">print</span>(grouped)</div><br /><div>test_groupby_2()</div></div><p><br /></p><p><br /></p>Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com0tag:blogger.com,1999:blog-11160305.post-91921054360890375062016-01-26T01:20:00.003+05:302021-10-07T17:42:56.195+05:30Anonymous method with Parameters 'i' -> Thread -> Iteration with 'i' -> Mess!<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: left;">
Problem:</div>
<div class="separator" style="clear: both; text-align: left;">
You see IndexOutOfRangeException with message "Index was outside the bounds of the array." when you thread out an anonymous method with iterator value as parameter.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiy6N6WhFA_VuqIRImYc31N5EP-7Mv3a2hdGlZzEwfQxyet2PaJv68WnS9F1kgfj6BUenjF_CJC2bPH3neZAskQhqSTHmwaf4L0RMCKA0zl0JxgjwXNCGQBCzDXrUV0k2Ygq2kK6Q/s1600/ThreadSurprise.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiy6N6WhFA_VuqIRImYc31N5EP-7Mv3a2hdGlZzEwfQxyet2PaJv68WnS9F1kgfj6BUenjF_CJC2bPH3neZAskQhqSTHmwaf4L0RMCKA0zl0JxgjwXNCGQBCzDXrUV0k2Ygq2kK6Q/s1600/ThreadSurprise.png" /></a></div>
<br />
Cause:<br />
Surprised? How is it possible to see value i >= 4 (it was 4) in the 'for' loop there?<br />
Well, it's 'possible' if your have written code as above.<br />
<br />
Secret is that the anonymous method doesn't get called unless the Thread created doesn't becomes live. Once thread becomes live, it searches for it's anonymous method which is: MethodToCompute(NumberOfIterationPerThread[i])<br />
Here, value of 'i' might have changed as 'for' loop to create thread runs in a different thread!<br />
<br />
Solution:<br />
solution is NOT to pass any value to threaded anonymous method which the parent thread may modify. In above case, I would create an extra variable to store value to pass to anonymous method which will be threaded out.<br />
<br />
<pre class="brush: c++, cpp" name="code"> for (int i = 0; i < NumberOfThreads; i++)
{
int iterationToRun = NumberOfIterationPerThread[i]; //magic line!
threads[i] = new Thread(new ThreadStart(() => MethodToCompute(iterationToRun)));
threads[i].IsBackground = true;
threads[i].Start();
}
</pre>
<br /></div>
Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com0tag:blogger.com,1999:blog-11160305.post-14593530502790521402015-06-10T22:26:00.000+05:302015-06-11T00:31:26.641+05:30NDK Directory Location on Windows 7<div dir="ltr" style="text-align: left;" trbidi="on">
I am not big fan of Android on Windows 7 but that's what I've at present and now I've to install NDK for some reason. So, I downloaded Android NDK from <a href="https://developer.android.com/ndk/downloads/index.html" rel="nofollow">https://developer.android.com/ndk/downloads/index.html</a>
According to the documentation, I've to double click the NDK download
and it will automatically extract file. I ran and now I don't know where
it has extracted the files are. I have to mention installed NDK path (ndk.dir) in "local.properties" (btw, I am using Android Studio). After searching whole C: suing below DOS command (I saw my nkd folder was "android-ndk-r10e"),<br />
<br />
<br />
dir /b /s /ad | findstr "android-ndk-r10e"<br />
<br />
Found the directory. As I've downloaded 64 bit NDK, it's<br />
<br />
"C:\Windows\SysWOW64\android-ndk-r10e" <br />
<br />
on my 64bit Windows 7 machine.<br />
<br />
Hope this helps and you don't have to search C: like me.</div>
Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com0tag:blogger.com,1999:blog-11160305.post-31721793197078302132014-09-19T00:34:00.000+05:302015-08-05T21:02:43.395+05:30The Ultimate Rounding Function<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Your search for any requirement for rounding function is over. You need to round amount to quarter? dime? nickel? penny? a dollar? 10 dollar? Below function of single linen can provide you more than what you are looking for. for sure!</div>
<pre class="brush: c#, csharp" name="code"> decimal NearestOfPenny(decimal amountToRound)
{
return UltimateRoundingFunction(amountToRound, 0.01m, 0.5m);
}
decimal NearestOfNickel(decimal amountToRound)
{
return UltimateRoundingFunction(amountToRound, 0.05m, 0.5m);
}
decimal NearestOfDime(decimal amountToRound)
{
return UltimateRoundingFunction(amountToRound, 0.10m, 0.5m);
}
decimal NearestOfQuarter(decimal amountToRound)
{
return UltimateRoundingFunction(amountToRound, 0.25m, 0.5m);
}
decimal NearestOfDollar(decimal amountToRound)
{
return UltimateRoundingFunction(amountToRound, 1m, 0.5m);
}
decimal UpwardDollarOnlyIfReminderIsMoreThan70Cents(decimal amountToRound)
{
return UltimateRoundingFunction(amountToRound, 1m, 0.3m);
//i.e. 0.70 will round up. but 0.69 will be rounded to 0.. this magic is from value of 'fairness'.
}
//amountToRound => input amount
//nearestOf => .25 if round to quater, 0.01 for rounding to 1 cent, 1 for rounding to $1
//fairness => btween 0 to 0.9999999___.
// 0 means floor and 0.99999... means ceiling. But for ceiling, I would recommend, Math.Ceiling
// 0.5 = Standard Rounding function. It will round up the border case. i.e. 1.5 to 2 and not 1.
// 0.4999999... Non-standard rounding function. Where border case is rounded down. i.e. 1.5 to 1 and not 2.
// 0.75 means first 75% values will be rounded down, rest 25% value will be rounded up.
decimal UltimateRoundingFunction(decimal amountToRound, decimal nearstOf, decimal fairness)
{
return Math.Floor(amountToRound / nearstOf + fairness) * nearstOf;
}
</pre>
</div>
Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com1tag:blogger.com,1999:blog-11160305.post-14304036265323976952014-08-30T18:55:00.002+05:302014-08-30T19:07:55.501+05:30Completely Read-Only Object as Return Value<div dir="ltr" style="text-align: left;" trbidi="on">
<b>NOTE: I am not proposing a 'secure' code. It's just to make your code dumb proof, not hack proof.</b><br/>
At the pinnacle of the insanity, when you have that bong affecting your normal senses, you may want to return that object from your beloved method which cannot be modified in anyway. You cannot even create a new object of the class that you are returning to have exclusive access to your return type. Anyways, whatever it can be used (?) for, it's here:<br />
</div>
<pre class="brush: c#">
using System;
using System.Collections.ObjectModel;
using System.Security.Permissions;
public class ReadOnlyClassAsReturnValue
{
private int sampleInt;
// make regular property read-only by creating only 'get' call
public int SampleInt
{
get { return sampleInt; }
}
private bool[] sampleCollection;
// Collections need to be made ReadOnlyCollection<T> .
// NOTE: Though ReadOnlyCollection<T> can be casted as IList<T>, never
// do that. It allows someone to to change collection in compilte
// time only to realized during runtime that it cannot be changed
public ReadOnlyCollection<bool> SampleCollection
{
get { return Array.AsReadOnly(sampleCollection); } //gives ReadOnlyCollection<T>
}
// 'private' varialbes can only be assigned in contructor. If any variable need to be assigned after
// object is created, it need to be made 'internal'.
protected string sampleString = "x";
public string SampleString
{
get { return sampleString; }
}
// Contructor is made 'protected' as this class is to be used by serious consumers only.
// If ultimate (dumb) user is going to be outside your assembly, you can make it
// 'internal' instead of 'prorected' eliminating need to override this class and
// providing more protection than 'protected' (and 'proected internal').
protected ReadOnlyClassAsReturnValue(int sampleInt, bool[] sampleCollection)
{
this.sampleInt = sampleInt;
this.sampleCollection = sampleCollection;
}
}
public class PrimaryUserClass
{
// Inherit ReadOnlyClassAsReturnValue so internal methods/properties/variables can be assigned
private class ReadOnlyObjectMaker : ReadOnlyClassAsReturnValue
{
public ReadOnlyObjectMaker(int sampleInt, bool[] sampleCollection)
: base(sampleInt, sampleCollection)
{ }
public string SampleString
{
set
{
this.sampleString = value;
}
}
}
//NO ONE CAN CHANGE THIS RETURN VALUE
public ReadOnlyClassAsReturnValue ReadOnlyClassReturner()
{
ReadOnlyObjectMaker returnValue = new ReadOnlyObjectMaker(10, new bool[] { true, false });
returnValue.SampleString = "I can assign this";
return returnValue;
}
}
class Program
{
static void Main(string[] args)
{
var returnValue = new PrimaryUserClass().ReadOnlyClassReturner();
//returnValue cannot be modified. Why? Just for fun. Someone has to hack it to change anythingin returnValue.
}
}
</pre>Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com0tag:blogger.com,1999:blog-11160305.post-51599876601011086852014-02-18T00:05:00.000+05:302014-09-19T14:51:25.401+05:30Counting Number of REAL lines in Your C# Code<div dir="ltr" style="text-align: left;" trbidi="on">
If you are here, it means one (or more) of the three things: 1. You are the boss, 2. Your boss told you to count number of lines 3. You are a serious programmer. <br />
Anyways, let's come to the point. Each programer is different. Problem with just literally counting the line has many issues which this piece of code attempts to resolve as mentioned below:<br />
0. Comments of // and /* kind are ignored.<br />
1. A statement written in multiple line is considered single line.<br />
2. brackets are (i.e. '{') not considered lines.<br />
3. 'using namespace' line are ignored.<br />
<br />
<br />
<pre class="brush: c#">
private int CountNumberOfLinesInCSFilesOfDirectory(string dirPath)
{
FileInfo[] csFiles = new DirectoryInfo(txtPath.Text.Trim())
.GetFiles("*.cs", SearchOption.AllDirectories);
int totalNumberOfLines = 0;
Parallel.ForEach(csFiles, fo =>
{
Interlocked.Add(ref totalNumberOfLines, CountNumberOfLine(fo));
});
return totalNumberOfLines;
}
private int CountNumberOfLine(Object tc)
{
FileInfo fo = (FileInfo)tc;
int count = 0;
int inComment = 0;
using (StreamReader sr = fo.OpenText())
{
string line;
while ((line = sr.ReadLine()) != null)
{
if (IsRealCode(line.Trim(), ref inComment))
count++;
}
}
return count;
}
private bool IsRealCode(string trimmed, ref int inComment)
{
if (trimmed.StartsWith("/*") && trimmed.EndsWith("*/"))
return false;
else if (trimmed.StartsWith("/*"))
{
inComment++;
return false;
}
else if (trimmed.EndsWith("*/"))
{
inComment--;
return false;
}
return
inComment == 0
&& !trimmed.StartsWith("//")
&& (trimmed.StartsWith("if")
|| trimmed.StartsWith("else if")
|| trimmed.StartsWith("using (")
|| trimmed.StartsWith("else if")
|| trimmed.Contains(";")
|| trimmed.StartsWith("public") //method signature
|| trimmed.StartsWith("private") //method signature
|| trimmed.StartsWith("protected") //method signature
);
}
</pre>
<br />
<br />
There is (literally) no solution for below (un)kind of programers:<br />
1. Write multiple statements in single line.<br />
2. Who declare useless variables.<br />
3.Whose every other line is debug.write <br />
4. Inappropriate use of compiler directive (directive itself is not considered as line btw)<br />
5. Bulk copy programmers who suffer from schizophrenia and lives only in their set of classes. Don't trust or reuse anything else.<br />
6. Who still likes to reinvent the wheel.<br />
<br />
Apart from above six non-solvable issues, if you can improve my code, it will be helpful to everyone.</div>
Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com3tag:blogger.com,1999:blog-11160305.post-39491980429399511122013-04-04T01:02:00.000+05:302013-04-04T01:02:26.704+05:30Firefox 20 Feature - Click To Play<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
If you, my friend, are annoyed by zillions of flash advertisements running on your browser for which you haven't subscribed, have a look at the latest version of <a href="http://www.firefox.com/">Firefox </a>20. It has a hidden lovable feature called "Click To Play". If enabled, it will deactivate all Flash (and Java) plugins except the one which you select to activate in a page. I've a netbook ('cheap laptop') which cannot handle the army of flash advertisements so I chose to activate this hidden Click_To_Play feature on my recently updated Firefox.<br />
<h3 style="text-align: left;">
How to Enable Click_To_Play:</h3>
<ol style="text-align: left;">
<li>Open a new firefox tab and type "about:config" in address bar.</li>
<li>Click on button which says "I will be careful" etc.. </li>
<li>Now search for Click_To_Play in "Sea<u>r</u>ch" box.</li>
<li>Double click preference named "plugins.click_to_play". It will change value of the preference to 'true'.</li>
<li>You are done. Go to any web site and click only the plugin which you know you want to activate. </li>
</ol>
</div>
Happy Browsing and don't let the Flash ads bite!</div>
Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com2tag:blogger.com,1999:blog-11160305.post-47574047169197086992013-02-15T21:16:00.001+05:302013-02-15T21:19:15.187+05:30Auto Mouse Click and Drag Generator<div dir="ltr" style="text-align: left;" trbidi="on">
If you are looking for a simple but powerful fast mouse clicker application, you are not alone. I am growing old and the software written by kids are too difficult for me to use, so I wrote a simple one called Auto Mouse Click and Drag Generator by myself which suite my work style - use keyboard when you automate mouse.<br />
<br />
Here is from where you can <span style="font-size: small;">try yourself: </span><a href="https://sourceforge.net/projects/superclick/files/latest/download?source=directory">https://sourceforge.net/projects/superclick/files/latest/download?source=directory</a><br />
<br />
Source Code can be found at project <span style="font-size: small;">home:</span> <a href="https://sourceforge.net/projects/superclick/?source=directory">https://sourceforge.net/projects/superclick/?source=directory</a><br />
<br />
Dedicated blog location is: <a href="http://automouseclicker.blogspot.in/">http://automouseclicker.blogspot.in/</a><br />
Below are the screens of the software as of today. Latest version may have more features and better UI. I don't intend to post update on this blog as the software has it's own dedicated blog.<br />
<br />
Happy clicking and crashing others' software! <br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6lZQYtoMLnEj5-ush6jqYX6OVSd0zr8iwCZlTlgWPEO96i5G4bKKEViFXPIVbMZffJSGW68dZ7q2OOhAFh8DEXBV_vtU8m9PiJ5h0Jd39_CPApikDFtolzjzHkvKNfaA4uWt9/s1600/MouseClickGen-Click.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6lZQYtoMLnEj5-ush6jqYX6OVSd0zr8iwCZlTlgWPEO96i5G4bKKEViFXPIVbMZffJSGW68dZ7q2OOhAFh8DEXBV_vtU8m9PiJ5h0Jd39_CPApikDFtolzjzHkvKNfaA4uWt9/s1600/MouseClickGen-Click.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1nsvzfarNDqzWhIdnZ84GGKuVkWwWRFWFKiuKcqLdFek5S1-Ao3JA-iDmR_pH9NMQ6tEtgh0xTAo_XM-Ccx2ARwC4XljSF-1vMBukpMGIJz5pNIOqO3ZVlyK0TOHlOtUICovY/s1600/MouseClickGen-Fire.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1nsvzfarNDqzWhIdnZ84GGKuVkWwWRFWFKiuKcqLdFek5S1-Ao3JA-iDmR_pH9NMQ6tEtgh0xTAo_XM-Ccx2ARwC4XljSF-1vMBukpMGIJz5pNIOqO3ZVlyK0TOHlOtUICovY/s1600/MouseClickGen-Fire.png" /></a></div>
<br /></div>
Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com2tag:blogger.com,1999:blog-11160305.post-62335567860644765072013-02-15T21:04:00.000+05:302013-02-15T21:04:19.156+05:30Unity3D and Vector Graphics<div dir="ltr" style="text-align: left;" trbidi="on">
SVG is a popular vector graphics format. It has same limitation and advantages like any other vector graphics formats but SVG is very popular (and it's open format). Actually most modern browsers (and mobile devices) support it. Also, a graphics developer can create complex vector graphics using various tools available and need not to be programmed. They are not there to replace all raster format but in some specific cases, it may be more advantageous to use vector graphics. One of the major advantage of the vector graphics in general is that it looks crisp regardless of resolution, and they are less in size (well, not all the times). They may take same amount of memory and little more processing power but sometime they are worth it.<br /><br />After thinking about all these advantages, I went look for unity plugin that can support direct rendering of SVG file or converts it to texture in runtime and show it and I found this:<br /><br /><a href="http://wiki.unity3d.com/index.php?title=SVG">http://wiki.unity3d.com/index.php?title=SVG</a><br /><br />This one is still in its basic form and not yet practical to use. I hope something along the way come to make Unity use 2D vector rendering easier.<br />
<br />
The other one that I stuck during my search was:<br />
<a href="http://virtualplayground.d2.pl/?p=241">http://virtualplayground.d2.pl/?p=241</a><br />
This one works with basic shapes and creates triangles out of vector forms which is more Unity friendly. It's nice thing but the implementation as of now has very limited features and most probably will not satisfy your needs.<br />
<br />
Btw, as you may know, Flash already supports vector rendering
(proprietary format) and this is the main reason why Flash games are
very light in size and still looks crisp. <br />
</div>
Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com3tag:blogger.com,1999:blog-11160305.post-76063792010618954632012-09-11T15:54:00.000+05:302012-09-11T15:55:30.448+05:30Extract BINK to PNG Sequence (with transparency)<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
BINK movies are widely used in games because they provide transparency in the video from long back. Sometime you have to reverse engineer the BINK file and get the PNGs out of (not JPEG but PNG with
transparency) the movie. I've used FFMpeg to get PNGs out of BINK (.bik format) file as followed.<br />
<br />
1. Download latest ffmpeg static build from <a href="http://ffmpeg.zeranoe.com/builds/">http://ffmpeg.zeranoe.com/builds/</a><br />
2. Extract the .7z build to any folder.<br />
3. Give this command to convert “my.bik” to “output” folder and %d is sequence number in output image. %d will auto increment by one, you have to just give %d in the command.<br />
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">ffmpeg.exe -i D:\my.bik D:\output\my_%d.png</span></blockquote>
<div>
Note that this is a general command which applies to any type of movie format supported by ffmpeg. There are hell lot of more things you can with ffmpeg. For example, your popular VLC is built using ffmpeg library :) </div>
</div>
Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com4tag:blogger.com,1999:blog-11160305.post-17472087708862305742012-05-08T19:24:00.001+05:302012-05-08T19:24:43.302+05:30When your 'mktime' is slow as shit<div dir="ltr" style="text-align: left;" trbidi="on">
While working on Vanilla Forum, I realized that dashboard was taking around 3 seconds to load on LAN. When looked further using Xdebug and cachegrind log, I realized that a method called "UnixTimestamp" (in Framework.Functions.php) was calling a stupid method called "mktime". What it does is just return the timestamp value (elapsed int value from a stupid start date of C which will create problem 2030). Not sure why on the earth this should happen, but this method is utter slow. So slow that when I wrote got the UTC time from my MySQL server (of local machine), it was 3 time fast.<br />
<br />
Conclusion:<br />
If your mktime is slow, throw that shit out and use stupider but faster method.. i.e. tell MySQL to do it for you. Here is what I wrote:<br />
<br />
<pre class="brush: js;">
$query = sprintf("SELECT UNIX_TIMESTAMP('%s') as UTS",
mysql_real_escape_string($DateTime));
$result = mysql_query($query);
if($row = mysql_fetch_assoc($result)) {
return $row['UTS'];
}
</pre>
May PHP god have mercy on you! Happy Coding!
</div>Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com0tag:blogger.com,1999:blog-11160305.post-68643983148408161192012-03-16T20:17:00.000+05:302012-03-16T20:17:45.908+05:30SqlDateTime overflow Exception with NHibernate<div dir="ltr" style="text-align: left;" trbidi="on"><blockquote class="tr_bq"><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.<br />
Exception Stacktrace:<br />
at System.Data.SqlTypes.SqlDateTime.FromTimeSpan(TimeSpan value)<br />
at System.Data.SqlTypes.SqlDateTime.FromDateTime(DateTime value)<br />
at System.Data.SqlClient.MetaType.FromDateTime(DateTime dateTime, Byte cb)<br />
at System.Data.SqlClient.TdsParser.WriteValue(Object value, MetaType type, Byte scale, Int32 actualLength, Int32 encodingByteSize, Int32 offset, TdsParserStateObject stateObj)<br />
at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc)<br />
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)<br />
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)<br />
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)<br />
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()<br />
at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)<br />
at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation)<br />
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)<br />
at NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)</span></blockquote><div style="text-align: left;"><b>What is NOT a problem:</b></div><div style="text-align: left;">As always, I opned SQL Profiler and tried solve the issue but it misguided me by adding few extra zeros in millisecond part of datetime (I don't want to discuss it and it is not the problem).</div><div style="text-align: left;"><br />
</div><div style="text-align: left;"><b>What IS (or was in my case) problem:</b></div><div style="text-align: left;">I added an extra Datetime filed which was nullable in database. But I was mapping it to DateTime in my database. When NHibernate was converting my unset Datetime to SQLdatetime for mysterious reason, it was trying to set DateTime.Min in SQL datetime datatype which is not allowed (see exception).</div><div style="text-align: left;"><br />
</div><div style="text-align: left;"><b><span style="font-size: large;">Solution:</span></b></div><div style="text-align: left;"><b>Look for any Datetime in your mappings that should be nullabe (according to database). And then use</b></div><div style="text-align: left;"><b>type="System.Nullable`1[[System.DateTime, mscorlib]], mscorlib" in your mapping.</b></div><div style="text-align: left;"><br />
</div></div>Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com4tag:blogger.com,1999:blog-11160305.post-36250013716660863092011-12-01T21:36:00.001+05:302014-04-17T15:54:41.620+05:30Floating/Fixed Table Header in HTML Page or Inside DIV control<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
I’ve looked a lot for finding a solution were we can float a header of a table so that the header always appears on the top no matter how down do I scroll. <br />
All the ‘floating table header’ solution ‘mostly’ worked were full HTML body is getting the scroll <strong>but none of them worked which can work inside scrolling div</strong>. None! <br />
So I though I can create one. The concept was simple, get the ‘onScroll’ even of Div control and change CSS “top” property of table header to current scrolled position of Div. <br />
Unfortunately, there are many browser issues. Like mozilla doesn’t like when table cells change their position. Chrome rendering issues shows two headers rows when scrolled up.<br />
At last, after storming through the problems, I arrived on this complex but simplified solution which is mentioned below. Copy the content in a blank HTML file and see the fun.<br />
<br /></div>
<pre>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript" > </script>
<script type="text/javascript">
$(function() {
if($.browser.mozilla)
//table row doean't float in firefox, div floats
$(".floatingHeader" + " tr th div")
.addClass("floatingStyle");
else
//table row can float in IE and Chrome
$(".floatingHeader"+ " tr th")
.addClass("floatingStyle");
});
function changeFloatingHeaderPosition(container, headerId) {
if($.browser.webkit) //chrome rendering bug fix
$("#"+headerId + " tr th")
.css("visibility", "hidden");
if($.browser.mozilla)
$("#"+headerId + " tr th div")
.css("top", container.scrollTop);
else
$("#"+headerId + " tr th")
.css("top", container.scrollTop);
if($.browser.webkit) //chrome rendering bug fix
$("#"+headerId + " tr th")
.css("visibility", "visible");
}
// Remove this method if you are using Jqeury earlier than 1.9
(function() {
var matched, browser;
// Use of jQuery.browser is frowned upon.
// More details: http://api.jquery.com/jQuery.browser
// jQuery.uaMatch maintained for back-compat
jQuery.uaMatch = function( ua ) {
ua = ua.toLowerCase();
var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
[];
return {
browser: match[ 1 ] || "",
version: match[ 2 ] || "0"
};
};
matched = jQuery.uaMatch( navigator.userAgent );
browser = {};
if ( matched.browser ) {
browser[ matched.browser ] = true;
browser.version = matched.version;
}
// Chrome is Webkit, but Webkit is also Safari.
if ( browser.chrome ) {
browser.webkit = true;
} else if ( browser.webkit ) {
browser.safari = true;
}
jQuery.browser = browser;
})();
</script>
<style>
.floatingStyle
{
position:relative;
background-color:#829DC0;
top:0px;
}
</style>
</head>
<body>
<div class="floatingContainer" onscroll="changeFloatingHeaderPosition(this, 'idHeader' );" style="height:150px; width: 100px;overflow:auto;">
<table cellspacing=0 cellpadding=0>
<thead class="floatingHeader" id="idHeader">
<tr>
<th><div>Col1</div></th> <th ><div>Col2<div></th>
<th ><div>Col3<div></th>
</tr>
</thead>
<tbody>
<tr><td>first_row</td><td>first_row</td><td>first_row</td></tr>
<tr><td>data</td><td>data</td><td>data</td></tr>
<tr><td>data</td><td>data</td><td>data</td></tr>
<tr><td>data</td><td>data</td><td>data</td></tr>
<tr><td>data</td><td>data</td><td>data</td></tr>
<tr><td>data</td><td>data</td><td>data</td></tr>
<tr><td>data</td><td>data</td><td>data</td></tr>
<tr><td>data</td><td>data</td><td>data</td></tr> </tbody>
</table>
</div></body><html>
</pre>
Note: Dan/Kenji has written plugging for the same which might be useful to you. I've not verified if it works in all case but worth having a look. You can find it: <a href="http://www.redkitetechnologies.com/2013/03/floatingsticky-headers-for-visualforce-pageblocktable">here: http://www.redkitetechnologies.com/2013/03/floatingsticky-headers-for-visualforce-pageblocktable/</a>
</div>Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com17tag:blogger.com,1999:blog-11160305.post-24139183090548337282011-11-15T18:30:00.001+05:302011-11-15T18:33:18.500+05:30Find Missing Foreign Key References<div dir="ltr" style="text-align: left;" trbidi="on">If you database column naming convention says all foreign key columns must end with 'ID' then this is the query for you to find missing foreign key reference. E.g. PRIZE_ID means Foreign Key reference to PRIZE table. <br />
<pre class="brush:sql">SELECT
colT.TABLE_NAME ,
colT.COLUMN_NAME
FROM
INFORMATION_SCHEMA.COLUMNS AS colT
WHERE
COLUMN_NAME LIKE '%id'
AND
(colT.TABLE_NAME + colT.COLUMN_NAME) NOT IN
( SELECT
KOM.TABLE_NAME + KOM.COLUMN_NAME
FROM
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS KOM)
</pre></div>Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com0tag:blogger.com,1999:blog-11160305.post-83407413707067533312011-06-20T21:08:00.001+05:302011-06-20T21:09:28.986+05:30Amazon SimpleDB in Nutshell for those who know RDBMS Systems<p><font size="1">Note: Latest Available Amazon SimpleDB version as of today, i.e. when I am writing this, is in Beta status with API Version: “2009-04-15”</font></p> <p><strong><font size="3"><u>Overview of SimpleDB <br /></u></font></strong>Amazon SimpleDB is a highly available, flexible, and scalable non-relational data store that offloads the work of database administration. Developers simply store and query data items via web services requests.[1] </p> <p><strong>Representation of Data with SimpleDB:</strong></p> <p><strong>Domains</strong>— Domains are similar to tables that contain similar data. </p> <p>You can execute queries against a domain, but cannot execute queries across different domains. </p> <p><strong>Attributes</strong>— They are similar to columns in RDBMS, attributes represent categories of data that can be assigned to items. </p> <p><strong>Items</strong>— Represented by rows, items represent individual objects that contain one or more attribute name-value pairs. </p> <p><strong>Values</strong>—Similar to column value, values represent instances of attributes for items. An attribute can have multiple values. There is no data typing supported for attribute and all data is treated as text data during query execution. </p> <p>However, Amazon SimpleDB is not a relational database, and does not offer some features needed in certain applications, e.g. complex transactions or joins (i.e. execute queries across different domains).[1] You need to rely on duplicating the data to avoid such scenarios.[2] </p> <p><strong><font size="3"><u>Benefits of using SimpleDB <br /></u></font> <br />Highly Available <br /></strong>Amazon SimpleDB creates and manages multiple geographically distributed replicas of your data automatically to enable high availability and data durability. <br /><strong>Flexible <br /></strong>You can change your data model on the fly, and data is automatically indexed for you. <br /><strong>Scalability <br /></strong>You can access additional machine resources by spreading your data set and requests across multiple domains. </p> <p><strong><font size="3"><u>Support for Reporting</u></font></strong> <br />Sql Server Reporting Service (SSRS) is a popular platform to build and access reports. SSRS reports are build based on dataset that has set for a report. It is possible to build dataset from SimpleDB.[3]  </p> <p><strong><u><font size="3">Limitation with SimpleDB </font></u></strong></p> <p><strong>Domain</strong> (similar to table): <strong>250</strong> active domains per account. More can be requested by filling a form. Note that each attribute (similar to column) can hold multiple value.[4] </p> <p><strong>Attribute</strong> (similar to column) name-value pairs per item: <strong>256</strong>[4] </p> <p>Maximum <strong>response size for Select</strong>:<strong> 1 MB</strong> (large data like images can be stored separately into cloud as files and an Attribute can store URL for the resource).[4] </p> <p><strong>Maximum</strong> <strong>items per select</strong>: <strong>2500</strong>[4] </p> <p>Attribute<strong> value length</strong>: <strong>1024</strong> bytes[4] </p> <p><strong>No datatyping:</strong> <strong>text only</strong>. Integers and reals must be represented using leading zeros to ensure proper query comparisons.[5] </p> <p><strong><u><font size="3">References: </font></u></strong></p> <p>[1] Amazon SimpleDB (beta) <br /><a href="http://aws.amazon.com/simpledb/">http://aws.amazon.com/simpledb/</a></p> <p>[2] How And Why Glue Is Using Amazon SimpleDB Instead Of A Relational Database <br /><a href="http://blog.getglue.com/?p=1145">http://blog.getglue.com/?p=1145</a></p> <p>[3] Accessing SimpleDB from SSRS <br /><a href="http://www.chrisumbel.com/article/simpledb_ssrs.aspx">http://www.chrisumbel.com/article/simpledb_ssrs.aspx</a></p> <p>[4] Amazon SimpleDB Limits, Amazon SimpleDB Developer Guide (API Latest version) <br /><a href="http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/">http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/</a></p> <p>[5] M/DB - A Free Open Source "plug-compatible" alternative to Amazon's SimpleDB database <br /><a href="http://gradvs1.mgateway.com/main/index.html?path=mdb">http://gradvs1.mgateway.com/main/index.html?path=mdb</a></p> Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com2tag:blogger.com,1999:blog-11160305.post-32043820100186575632011-04-21T21:41:00.001+05:302011-04-21T21:45:11.879+05:30How Apple's Location Services Work<div dir="ltr" style="text-align: left;" trbidi="on"><br />
Even though I like apples (specially the one which fell on Newton's head), I am not found of Apple as a corporation. Mainly because it is too secretive in its technologies and methods of doing something amazing. Location Services are one of those secretive things which need to be so secret but you can figure-out how it works.<br />
<br />
Apple's Locations services uses (in order) A-GPS, Wi-Fi triangulation and Cell Triangulation (base on capability of your device).<br />
<br />
<span class="Apple-style-span" style="font-size: large;">Uses A-GPS</span><br />
<b>Pros</b><br />
When you are outdoors, works amazingly.<br />
<b>Cons</b><br />
<div style="text-align: left;">Works poorly in urban environment with tall buildings. Even your vehicle roof is a problem for A-GPS. Doesn't work without GPS chip in device (case for iPod).</div><br />
<span class="Apple-style-span" style="font-size: large;">Uses cellular tower triangulation</span><br />
<b>Pros</b><br />
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Even with it's worst accuracy, sometimes it is more accurate than GPS in urban environment. This is because performance doesn't decrease in urban environments due to many towers triangulating in cities nowadays. </div><b>Cons</b><br />
Cellular tower triangulation as it is way too in accurate for the accuracy need of the day. This is option only when when no other medium of deciding location available.<br />
<br />
<span class="Apple-style-span" style="font-size: large;">Uses Wi-Fi triangulations</span><br />
<b>Pros</b><br />
Works very accurate when one or more wi-fi is available in area. You need not to connect to a Wi-Fi, nether the Wi-Fi needs to know your requirement of locating your device. If the location of Wi-Fi is stored in Apple's giant database of all Wi-Fi and their co-ordinates, you are in luck. Your device contact Apple's service and based on Wi-Fi details, Apple will send you Wi-Fi coordinates. I am not sure if device triangulates the Wi-Fi once the coordinates are found or Apple's service will do it - but end result is accurate coordinates.<br />
<b>Cons</b><br />
You need to be in range of one or more Wi-Fi. If you are using iPod, you should be connected with internet.<br />
<br />
<b><span class="Apple-style-span" style="font-size: large;">How Does Apple Get all Wi-Fi Locations?</span></b><br />
Hmm... so the world need to have a database of all wi-fi and their locations. It is still guess for the people how apple has got this database? This is what I think based on recent controversies regarding Apple's privacy policy regarding sharing your iPhone location with Apple's Service:<br />
When your device has correct location decided, it also looks for wi-fi around your device. It stores those information on iPhone and iTunes on your computer sends it to Apple. And so, this list has grown 2 fold in day and 4 fold in night (it is just saying).<br />
Note that before to iOS 3.2, this was not the case so Apple used to use (and still using for older devices) Skyhook Wireless and Google's services for WiFi triangulations.<br />
<br />
Now you are ready for next level: Go to <a href="http://support.apple.com/kb/HT1975">Apple's Office Discloser of its Location Service</a> and know more about it.</div>Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com1tag:blogger.com,1999:blog-11160305.post-75278125543443098962011-03-18T19:01:00.001+05:302011-03-18T19:01:33.494+05:30Good User Experience<p>Good user experience cannot be achieved by jazzy animations. It is these simple things that everyone wants to have.</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2GIcwxxuxOxnabu2OBHe35MShMF1MkTUOA2DY04DKzlAEUzL5Pb-QCWtV0J_Vfh299XFMTZJ-khsYn9uJMkXvqr9EgAk4yiW3pA339U1bYC5k8ZLff7KGkczBcAx8s8jJiAmjLQ/s1600-h/google_attachment%5B5%5D.png"><img title="google_attachment" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="454" alt="google_attachment" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxEPs7AdA2eJPnqjchNCpulGIQXFNVoy7Hc1haUNkZaIN6eAw9iB2TxPX4SJ8QBgNtjyw-nqFuixgVM5qUU3sJA4l9-tuk-lbblGh7IS7l8nbNVtn0UjUtIKeaGjzye62D-dEK0g//?imgmax=800" width="625" border="0" /></a></p> <p>Some common tips for better user experience (most of us knows but we don’t follow):</p> <p>1. Use standard controls. In laymen language, text should look like text and button should look like a button.</p> <p>2. Optimize for speed. Everyone want to get the things done faster. Don’t put animations which hinders speed of doing something. Your UI (specially forms) should be accessible by ‘keyboard only’ as well. </p> <p>3. Think about the common mistake that user may be making while data entry. When you find something wrong, locate exact position and show understandable message to show the error.</p> <p>4. Try to optimize available space. You controls should be able to adjust to larger width to avoid scrollbars if possible. Don’t put big logos of the application on each screen top.</p> <p>5. Find the most used flows for your UI and optimize UI so user can complete the common tasks faster. If necessary, create different views of the same UI for different kind of user in organizational hierarchy.</p> Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com0tag:blogger.com,1999:blog-11160305.post-75203582877148624102011-02-04T03:29:00.003+05:302011-05-23T17:53:48.810+05:30Nested Transaction Handling with NHibernate<div dir="ltr" style="text-align: left;" trbidi="on">NHibernate doesn’t have inbuilt support for nested transaction (or I am not using latest version). But, with little compromises, you can create a class that enables almost everything what you really need. I am using NHibernateSessionManager which you can find here: <a href="http://www.codekeep.net/snippets/8b94e3e0-3ffd-4b59-b6ce-ed4d46158a7c.aspx">http://www.codekeep.net/snippets/8b94e3e0-3ffd-4b59-b6ce-ed4d46158a7c.aspx</a><br />
<pre class="brush: c-sharp;"> public class SmartTransaction
{
bool _transactionOwner =false;
bool _transactionActive = false;
public bool IsActive
{
get
{
return _transactionActive;
}
}
public void Begin()
{
if (_transactionActive) return; //return to bad programer's code
try
{
_transactionOwner = !NHibernateSessionManager.Instance.HasOpenTransaction();
if (_transactionOwner)
NHibernateSessionManager.Instance.BeginTransaction();
_transactionActive = true;
}
catch
{
_transactionOwner = false;
_transactionActive = false;
throw;
}
}
public void Commit()
{
if (!_transactionActive || !NHibernateSessionManager.Instance.HasOpenTransaction())
{
_transactionActive = false;
return;
}
try
{
if (_transactionOwner)
NHibernateSessionManager.Instance.CommitTransaction();
}
catch //when you don't know what you are committing to.
{
NHibernateSessionManager.Instance.RollbackTransaction();
throw;
}
finally
{
_transactionActive = false;
}
}
public void Rollback()
{
_transactionActive = false;
if (!NHibernateSessionManager.Instance.HasOpenTransaction())
return;
NHibernateSessionManager.Instance.RollbackTransaction();
}
}
</pre><br />
<br />
<strong>Benefits:</strong><br />
<br />
1. When writing a method, you need not to worry about context of calling method. You can just begin transaction of SmartTransaction class. If calling method has started transaction already, SmartTransaction doesn’t begin the transaction, but if something goes wrong, it will rollback entire transaction (of calling method). <br />
<br />
<br />
2. You need not to worry if method you are calling needs transaction wrapping. As with SmartTransaction class, if method you are calling needs transaction wrapping, it will have transaction wrapping using SmartTransaction class.<br />
<br />
<br />
</div>Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com2tag:blogger.com,1999:blog-11160305.post-71416093899167427502010-11-14T16:23:00.001+05:302010-11-14T16:24:40.617+05:30iPhone Button for Navigation Bar<p>If you are developing iPhone application and trying to use UIButton on ‘Navigation Bar’ instead of ' ‘difficult to use’ ‘Bar Button Item’, you need a button image that exactly looks like Bar Button.</p> <p>As I couldn’t find the button background on net, I created it myself using Paint.NET. Here it is for  you.</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmK_xSyCE-t2vG4pPE3R_AlmSv6VxXk2Y-e9lIxK7NnGscQZcdJSYJzA3BdeDKitODqRPPpFHX1hlpG2KTO721Q4Ky4gZez2oWy_HnxUtaQiQjJEdy-5jRPECm3IHGT1jP71NCEw/s1600-h/iphoneButtonBig%5B5%5D.png"><img title="iphoneButtonBig" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="151" alt="iphoneButtonBig" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjorMUlkCLdCTDvRzcfaZ9zjpFfmCo44DKjXTcCot3v1UdzrHocYqqKcd1fn0tG_ErAGE9iBmErUIXrI_Zs8R2T-btkTwgVOh1hR8dGeL0n-qhVWVhsS6zjkj6M4GRIHOmo723frQ//?imgmax=800" width="328" border="0" /></a></p> Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com0tag:blogger.com,1999:blog-11160305.post-58310604548204691242010-08-08T22:26:00.001+05:302010-08-08T22:26:20.628+05:30What are Characteristics of Successful Innovative Idea<p>I’ve been associate with an Innovation Lab from quite a some time and observing for life how a genuine ideas turn into a success. Though I’ve never been able to own a killer existing idea, I can still depict some characteristics of successful innovative idea (based on guts but without example or stories - bad bad to convince people).</p> <ul> <li>Idea that solve problem for many. </li> <li>Idea that have feasibility to be prototyped.  Idea that can be prototyped in short duration. </li> <li>Idea that reasons (in term of Math, Science AND Art) why the idea can be successful. Idea should reference similar success. </li> <li>Idea that is inline with what your associated firm is trying to do. </li> </ul> Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com0tag:blogger.com,1999:blog-11160305.post-81483027491414944512010-07-21T00:13:00.001+05:302010-07-21T00:13:42.537+05:30Concatenation of Styles in WPF<p>In order to avoid confusion and/or be inline with OOP concepts, WPF style will not allow you to concatenate multiple style in one control. Instead, you can use ‘BasedOn’ property (of Style element) to inherit from the other style. It is possible to create chain of inheritance but multiple inheritance is not supported by default. Initially I though it is not possible  until I came across this amazing link: <a title="http://swdeveloper.wordpress.com/2009/01/03/wpf-xaml-multiple-style-inheritance-and-markup-extensions/" href="http://swdeveloper.wordpress.com/2009/01/03/wpf-xaml-multiple-style-inheritance-and-markup-extensions/">http://swdeveloper.wordpress.com/2009/01/03/wpf-xaml-multiple-style-inheritance-and-markup-extensions/</a></p> <p>It shows use of MarkupExtension to enable inheritance from multiple styles (in actual, your triggers and setters will be merged. Duplicates will be overwritten by the second style that you define)</p> <p>Happy interfacing!</p> Yogeehttp://www.blogger.com/profile/09194279800230653446noreply@blogger.com0