tag:blogger.com,1999:blog-72137905643243569812018-11-19T14:01:37.147-08:00ToonTricksJust another way to solve your issuesLucky Rathorenoreply@blogger.comBlogger61528125tag:blogger.com,1999:blog-7213790564324356981.post-2700502282110808052018-11-19T14:00:00.000-08:002018-11-19T14:01:36.988-08:00Tutorial :Oracle IDE to visually create views?<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>Oracle IDE to visually = wizard (not writing sql) create views? any names? (eg like toad)</p> <p>SQL Server Management Studio = can create views visually for sql server what is same for oracle</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>Have you tried <a href="http://www.oracle.com/technology/software/products/sql/index.html" rel="nofollow noreferrer">SQL Developer</a>? </p> <p>Once installed and connected - try the following.</p> <p>1) Right click on Views icon</p> <p>2) New View </p> <p>3) Click Advanced check box</p> <p>4) Interface appears which allows you select tables, where clauses etc.</p> <p><strong>EDIT:</strong> Just thought I would point out that the above allows the use of a "wizard" type interface to create a view. Not sure if that meets your requirement of "Visual"</p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>Want a purley visual experience? Try <a href="http://datanamic.com/dezign/index.html" rel="nofollow noreferrer">DeZign for Databases</a> by Datanamic. I haven't purchased the tool, but after an initial evaluation I'm wanting it. It lets you drag and drop items onto a visual designer and then generates the DDL for you.</p> </div><h3> <br> Solution:3<br> </h3><div class="post-text" itemprop="text"> <p>A little late, by here's an online designer - <a href="http://ondras.zarovi.cz/sql/demo/" rel="nofollow noreferrer">WWW SQL Designer</a></p> <p>Its mainly for MySQL but nevertheless pretty useful</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-42304593342827773422018-11-19T13:59:00.000-08:002018-11-19T14:00:55.923-08:00Tutorial :Hudson job with Gallio tests reports âNo testsâ<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>I am using Hudson as a CI server to build a few different .Net 3.5 projects. The actual build stuff works great.</p> <p>However, I run MbUnit v2 tests using Gallio.Echo as part of the build, and while the tests seem to run fine, Hudson claims that there were no tests run.</p> <p>I have the following build step right after the "Build a Visual Studio project or solution using MSBuild" step:</p> <p>Type: Execute Windows batch command Command:</p> <p>"C:\Program Files\Gallio\bin\Gallio.Echo.exe" TestLibrary\bin\Release\TestLibrary.dll /rt:Xml /rnf:mbunit-result /rd:. exit 0</p> <p>When the build is run, this gives the following output in the console log:</p> <pre><code>Gallio Echo - Version 3.1 build 313 Get the latest version at http://www.gallio.org/ Start time: 09:06 Initializing the runtime and loading plugins. Verifying test files. Initializing the test runner. Running the tests. [ignored] Test TestLibrary/ConfigTests/LoadAndSaveTest Generating reports. Disposing the test runner. Stop time: 09:07 (Total execution time: 10,210 seconds) 64 run, 64 passed, 0 failed, 0 inconclusive, 1 skipped (1 ignored) </code></pre> <p>So in my mind there is little doubt that the tests actually run - and the mbunit-result.xml file is in the right place and looking good.</p> <p>I have also configured the project to "Publish Gallio test result report", just specifying the "Test report XMLs" value as "mbunit-result.xml".</p> <p>To try to figure this out, I configured the Gallio plugin (through the jobs' config.xml file) to leave the jUnit files (that the Gallio plugin creates from the MbUnit test results) in place, and I took a look at the junitResult.xml file - the weird thing is that each and every of the "cases" element of each suite is empty. I.e. a suite can look like this:</p> <pre><code>&lt;suite&gt; &lt;file&gt;C:\Documents and Settings\Administrator\.hudson\jobs\TestProject\workspace\temporary-junit-reports\TEST-TestLibrary.Encryption_Tests.xml&lt;/file&gt; &lt;name&gt;TestLibrary.Encryption_Tests&lt;/name&gt; &lt;duration&gt;0.0&lt;/duration&gt; &lt;cases/&gt; &lt;/suite&gt; </code></pre> <p>As far as I know, the section is where the individual unit tests should reside. Also, duration shouldn't be 0.0.</p> <p>As you can see above, my Gallio version is 3.1 build 313. Could this be caused by changes in the report format of this Gallio version (just a guess, I don't know of any such changes)?</p> <p>I am running on Hudson v1.323, with the Gallio plugin v0.52. Any insight on how to get Hudson to see the test results would be highly appreciated!</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>Yes, it's due to the xml format of gallio 3.1 which changed. Have a look here, where I propose a test file to resolve this problem....</p> <p><a href="http://code.google.com/p/mb-unit/issues/detail?id=399" rel="nofollow noreferrer">http://code.google.com/p/mb-unit/issues/detail?id=399</a></p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>Is <code>mbunit-result.xml</code> at the root of your workspace? You can check by using the workspace browser. If it is not at the root of the workspace, I would suggest specifying the path in the Gallio plugin config.</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-8811370804925417482018-11-19T13:39:00.000-08:002018-11-19T13:40:40.951-08:00Tutorial :Editing business objects in Winforms DataGridView<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>Is possible to edit properties of business object (one property, one column) binded as BindingList to Winforms DataGridView?</p> <p>Or do I have to use DataSet or DataTable?</p> <p>I'm not able to get a cell to edit mode.</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>Yes it is possible check out BindingList.</p> <p>Otherwise the book Data Binding in Windows Forms 2.0 by Brian Noyes is an excellent reference book CH9 deals specifically with Binding Custom Business Objects.</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-55395532469671343532018-11-19T13:19:00.000-08:002018-11-19T13:20:41.758-08:00Tutorial :MVC and JQuery: Best pratice for retrieving form data<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>I have some JQuery that uses Ajax to send information back to my controller to be processed</p> <p>I am doing it like this:</p> <pre><code>//Define my controls &lt;%=Html.TextBox("PName", Model.PName, new { id = "pName" })%&gt; ... .... .... //Get the values from my controls var param1= $("#pName").val(); .... .... //Define the return URL. Is this how to send info back? var url = '&lt;%= Url.Content("~/Port/SaveRowAjax") %&gt;/?ID=' + id + "&amp;param1=" + param1 + "&amp;param2=" + param2 + "&amp;param3=" + param3 + "&amp;param4=" + param4 + "&amp;param5=" + param5; $.ajax({ url: url, success: function(html) { alert("Success!"); }, }); //My c# code, that processes the request public void SaveRowAjax(string param1 ....) { ... } </code></pre> <p>Is this the best way of doing it with MVC?<br> It seems a bit messy when i am contructing the URL to post back to the server</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>Try using <a href="http://docs.jquery.com/Ajax/serializeArray" rel="nofollow noreferrer">SerializeArray</a> for submitting your form items. It'll box all their values into a JSON object.</p> <pre><code>var link = "/Port/SaveRowAjax"; var formData = $(":input").serializeArray(); $.post(link,formData); </code></pre> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>You can try to use such syntax with jQuery</p> <pre><code>$.post(link, {param1: param1, param2: param2 }); </code></pre> </div><h3> <br> Solution:3<br> </h3><div class="post-text" itemprop="text"> <p>The way that works for me is this:</p> <pre><code>jQuery.ajax({ url: '@Url.Action("SaveRowAjax", "Port")', type: 'POST', contentType: 'application/json', data: JSON.stringify({ param1: param1, param2: param2, param3: param3 }), success: function (result) { } }); </code></pre> </div><h3> <br> Solution:4<br> </h3><div class="post-text" itemprop="text"> <p>Theres a few ways to do this. I prefer the method outlined here: </p> <p><a href="http://weblogs.asp.net/mikebosch/archive/2008/02/15/asp-net-mvc-submitting-ajax-form-with-jquery.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/mikebosch/archive/2008/02/15/asp-net-mvc-submitting-ajax-form-with-jquery.aspx</a> </p> <p>Yes, it is based on an older version of MVC but the real beef of the technique is the use of jQuery (which hasnt changed).</p> <p>One limitation of the technique is that it wont work with file uploads, however, there is a jQuery plugin for doing ajax form posts that does support file uploads (I think through a hidden iframe).</p> <p>edit: I think the best reason to use this technique is that if the user has javascript disabled, the form will still work.</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-76675883945326727912018-11-19T13:02:00.000-08:002018-11-19T13:04:22.569-08:00Tutorial :Splitting of development team [closed]<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>I was organizing the team to do parallel development of next version of the product. I grouped the team by </p> <ol> <li>Client specific </li> <li>Feature specific</li> </ol> <p>Handling the cross-functional issues by assigning that task to specific individual.</p> <p>Would like to know what other ways project managers/ leads group teams?</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>It doesn't matter so much how you do your split but there are pitfalls when splitting a development team that you need to be aware of. </p> <p>The level of integration determines how much risk you have. Separate software products that happen to share some libraries have very little risk. Highly integrated runtime components pose significantly more risk.</p> <p>The worst possible situation that you can find yourself in is where there is a dependency between teams to deliver a feature but no clear ownership. For example, team A is waiting on team B for a "back end service" but team B argues that the service is complete. Team A says the service does not meet all the requirements. But team B has moved on to new features. And so on....</p> <p>I've seen this us vs. them attitude literally grinding development to a halt. To combat this behavior, encourage cross team pairing and shared code ownership. Rotate team members from time-to-time. Make sure there is a single responsible person who will make a feature happen end-to-end.</p> <p>A team dedicated to developing reusable modules usually doesn't work. It because a collection of modules of dubious value and a governance nightmare. The best reusable modules comes from teams who deliver similar features and identify overlap themselves.</p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>We group people by product specific in our organization. Each team writes code for a specific product. When features of a product intersects with another product, sometimes they collaborate on that feature. We do a lot of compartmentalizing, so its possible. </p> <p>Write plenty of reusable modules. Thats the key.</p> <p>My organization also does client specific work only for large clients.</p> </div><h3> <br> Solution:3<br> </h3><div class="post-text" itemprop="text"> <p>I am a firm believer of pair programming, I would team such that one pair would manage and write test cases (tdd) while other one would code it. I would build up a team based on the same theme. </p> </div><h3> <br> Solution:4<br> </h3><div class="post-text" itemprop="text"> <ol> <li>If your product involves more than one technology then, You can group teams techno wise</li> <li>skillsets</li> </ol> </div><h3> <br> Solution:5<br> </h3><div class="post-text" itemprop="text"> <p>The key is to allow each team to follow the same standards, but be able to work as independently (decoupled) as possible. </p> <p>If its the same code base across your clients you probably don't want to split the team by client specific needs since it could lead to more overlapping of changes. </p> <p>If features cross system functional (AR, security, reporting, etc.) areas you probably want to split by functional areas. </p> <p>Other ways to split teams:</p> <ol> <li>front end (design implementation) and business logic and database/datastorage</li> <li>new development and maintenance (newer/more jr people on maintenance)</li> <li>core functionality and addon modules (if component based)</li> </ol> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-10995622134610586642018-11-19T12:59:00.000-08:002018-11-19T13:00:57.857-08:00Tutorial :Autocommit false mode java<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>I am not very sure about the auto commit mode of java JDBC, I am making a connection whose auto commit mode is set to false. After that I fire a select query on database, which works fine, I am under impression that commit has to be called only for insert, update, delete statements.</p> <p>Now do I need to commit the connection for Select query? If not will that table be locked for other transactions?</p> <p>Thanks, Rohit.</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>It depends on your isolation level. If you use <code>READ COMMITTED</code>, the <code>SELECT</code> only creates locks if you specify <code>SELECT FOR UPDATE</code>. If you use <code>REPEATABLE READ</code> or higher, every <code>SELECT</code> could create a lock (depends on your database model).</p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <blockquote> <p>I am not very sure about the auto commit mode of java JDBC, I am making a connection whose auto commit mode is set to false. After that I fire a select query on database, which works fine, I am under impression that commit has to be called only for insert, update, delete statements.</p> </blockquote> <p>That's depends of your application. If there are simple updates, inserts, deletes you can leave <em>autocommit=on</em>. Generaly, it's recomended to off autocommit. That configuration gives you more flexibility and power in applicaiton. You can use complex transactions and you can decide when transaction begins and when ends.</p> <blockquote> <p>Now do I need to commit the connection for Select query? If not will that table be locked for other transactions?</p> </blockquote> <p>No, select statment doesn't begin transaction (insert, update, delete does) so there is no need to commit/rollback after select statment. There is one special case of select which lock selected rows and need transaction - <a href="http://www.praetoriate.com/oracle_tips_for_update.htm" rel="nofollow noreferrer">with <strong>for update</strong> clause</a></p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-22314847347541889962018-11-19T12:39:00.000-08:002018-11-19T12:40:45.359-08:00Tutorial :Rounded corners on images using PHP?<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>Does anyone know how to make a image have rounded corners using a PHP script?</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>It can be done using php-gd, but I ended up passing that task to the browser, using CSS:</p> <blockquote> <p>&lt;img src="photo.jpg" width="42" height="42" alt="My cool photo" style="border-radius: 15px; -moz-border-radius: 15px;" /&gt;</p> </blockquote> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>This script shows <a href="http://salman-w.blogspot.com/2009/05/generate-images-with-round-corners-on.html" rel="nofollow noreferrer">how to apply rounded corners to images using PHP and GD Library</a>. It is as simple as drawing four quadrants of a circle over the four corners of the image. The circle itself has to be transparent.</p> <p>This script, on the other hand, <a href="http://salman-w.blogspot.com/2009/10/rounded-corner-graphics-generator.html" rel="nofollow noreferrer">generates rounded corner graphics</a> for HTML or CSS based solutions. It generates the four corners that you can overlay over an image using CSS positioning or HTML tables.</p> </div><h3> <br> Solution:3<br> </h3><div class="post-text" itemprop="text"> <p>You will need the GD library for that. There must be a lot of examples on the web. Here is one :</p> <p><a href="http://www.assemblysys.com/dataServices/php_roundedCorners.php" rel="nofollow noreferrer">http://www.assemblysys.com/dataServices/php_roundedCorners.php</a></p> <pre><code>&lt;?php $image_file = $_GET['src']; $corner_radius = isset($_GET['radius']) ? $_GET['radius'] : 20; // The default corner radius is set to 20px $angle = isset($_GET['angle']) ? $_GET['angle'] : 0; // The default angle is set to 0Âº $topleft = (isset($_GET['topleft']) and $_GET['topleft'] == "no") ? false : true; // Top-left rounded corner is shown by default $bottomleft = (isset($_GET['bottomleft']) and $_GET['bottomleft'] == "no") ? false : true; // Bottom-left rounded corner is shown by default $bottomright = (isset($_GET['bottomright']) and $_GET['bottomright'] == "no") ? false : true; // Bottom-right rounded corner is shown by default $topright = (isset($_GET['topright']) and $_GET['topright'] == "no") ? false : true; // Top-right rounded corner is shown by default $images_dir = 'images/'; $corner_source = imagecreatefrompng('images/rounded_corner.png'); $corner_width = imagesx($corner_source); $corner_height = imagesy($corner_source); $corner_resized = imagecreatetruecolor($corner_radius, $corner_radius); imagecopyresampled($corner_resized, $corner_source, 0, 0, 0, 0, $corner_radius, $corner_radius, $corner_width, $corner_height); $corner_width = imagesx($corner_resized); $corner_height = imagesy($corner_resized); $image = imagecreatetruecolor($corner_width, $corner_height); $image = imagecreatefromjpeg($images_dir . $image_file); // replace filename with $_GET['src'] $size = getimagesize($images_dir . $image_file); // replace filename with $_GET['src'] $white = imagecolorallocate($image,255,255,255); $black = imagecolorallocate($image,0,0,0); // Top-left corner if ($topleft == true) { $dest_x = 0; $dest_y = 0; imagecolortransparent($corner_resized, $black); imagecopymerge($image, $corner_resized, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100); } // Bottom-left corner if ($bottomleft == true) { $dest_x = 0; $dest_y = $size[1] - $corner_height; $rotated = imagerotate($corner_resized, 90, 0); imagecolortransparent($rotated, $black); imagecopymerge($image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100); } // Bottom-right corner if ($bottomright == true) { $dest_x = $size[0] - $corner_width; $dest_y = $size[1] - $corner_height; $rotated = imagerotate($corner_resized, 180, 0); imagecolortransparent($rotated, $black); imagecopymerge($image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100); } // Top-right corner if ($topright == true) { $dest_x = $size[0] - $corner_width; $dest_y = 0; $rotated = imagerotate($corner_resized, 270, 0); imagecolortransparent($rotated, $black); imagecopymerge($image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100); } // Rotate image $image = imagerotate($image, $angle, $white); // Output final image imagejpeg($image); // Remove temp files imagedestroy($image); imagedestroy($corner_source); ?&gt; </code></pre> <p><strong>How to use it?</strong></p> <p>Needless to say, PHP and the GD library needs to be installed on your server. Youâll also need a png file of the corner. You can use one of these corner images if you want: [<a href="http://assemblysys.com/wp/wp-content/uploads/2013/03/rounded_corners.zip%5D" rel="nofollow noreferrer">http://assemblysys.com/wp/wp-content/uploads/2013/03/rounded_corners.zip]</a></p> <p>Just paste the code above and save it in a .php file. Make the necessary changes to the $images_dir and $corner_source variables (lines 10 and 11). Link the src attribute of your image to that file, using the following URL variables:</p> <pre><code>**src:** name of the image file **radius** (optional): value that represents the radius (in pixels) of the corners; use this to resize the corner image **angle** (optional): value that represents the rotation angle of the full image, in degrees **topleft**=no (optional): do not round the top-left corner **bottomleft**=no (optional): do not round the bottom-left corner **bottomright**=no (optional): do not round the bottom-right corner **topright**=no (optional): do not round the top-right corner </code></pre> <p>Examples</p> <pre><code>&lt;img src='roundedCorners.php?src=image.jpg&amp;radius=40' /&gt; &lt;img src='roundedCorners.php?src=image.jpg&amp;radius=40&amp;angle=15' /&gt; &lt;img src='roundedCorners.php?src=image.jpg&amp;radius=40&amp;topleft=no&amp;bottomright=no' /&gt; </code></pre> </div><h3> <br> Solution:4<br> </h3><div class="post-text" itemprop="text"> <p>There are a lot of options available, you can find them using Google. The easiest way though is using the <a href="http://freelogic.pl/thumbnailer/demo" rel="nofollow">Thumbnailer</a>. It's as simple as two lines of code:</p> <pre><code>// make an object $th=new Thumbnailer("your-photo.jpg"); // create a 120x90 thumb and round its corners $th-&gt;thumbFixed(120,90)-&gt;round()-&gt;save("your-thumb.jpg"); </code></pre> <p>Fun it is, isn't it? :) There are a lot of other options available. The corners will be antialiased.</p> </div><h3> <br> Solution:5<br> </h3><div class="post-text" itemprop="text"> <p>Download easyphpthumbnail.class.php from <a href="http://www.mywebmymail.com/?q=content/easyphpthumbnail-class" rel="nofollow">this link</a> </p> <p>from this you can resize and convert image into rounded image. </p> <p>in below example image is converted into transparent circle image.</p> <pre><code>include_once('easyphpthumbnail.class.php'); $source = 'demo.jpg'; $width = 100; $height = 100; $thumb = new easyphpthumbnail; $thumb -&gt; Thumbheight = $width; $thumb -&gt; Thumbwidth = $height; $thumb -&gt; Backgroundcolor = '#FFFFFF'; $thumb -&gt; Clipcorner = array(2,50,0,1,1,1,1); $thumb -&gt; Maketransparent = array(1,0,'#FFFFFF',10); $thumb -&gt; Createthumb($source); </code></pre> </div><h3> <br> Solution:6<br> </h3><div class="post-text" itemprop="text"> <p>You can look at <a href="https://www.phpcontext.com/thumbnailer/" rel="nofollow noreferrer">https://www.phpcontext.com/thumbnailer/</a> . There's a script for creating nice rounded corner thumbs with PHP. They are antialiased too.</p> </div><h3> <br> Solution:7<br> </h3><div class="post-text" itemprop="text"> <p>Instead of modifying the image, why not just wrap it in some HTML that has images at each corner that overlay the original to provide the appearance of rounded corners?</p> <p>By doing the image editing in your .php script, you're going to put undue load on your web server, and that means your application won't scale well. </p> </div><h3> <br> Solution:8<br> </h3><div class="post-text" itemprop="text"> <p>GD is great for image manipulation, but it would be much easier for you and much easier on your server if you used CSS.</p> <p>Here's a great tutorial for some cool image effects using CSS:</p> <p><a href="http://www.webdesignerwall.com/tutorials/css-decorative-gallery/" rel="nofollow noreferrer">http://www.webdesignerwall.com/tutorials/css-decorative-gallery/</a></p> <p>For modern browsers, you can do it in pure CSS:</p> <p><a href="http://www.css3.info/preview/rounded-border/" rel="nofollow noreferrer">http://www.css3.info/preview/rounded-border/</a></p> <p>A couple of other noteworthy ones:</p> <p><a href="http://www.spiffycorners.com/" rel="nofollow noreferrer">http://www.spiffycorners.com/</a></p> <p><a href="http://www.html.it/articoli/niftycube/index.html" rel="nofollow noreferrer">http://www.html.it/articoli/niftycube/index.html</a></p> </div><h3> <br> Solution:9<br> </h3><div class="post-text" itemprop="text"> <p>its easy to create some <a href="http://www.freelogic.pl/thumbnailer/" rel="nofollow noreferrer">rounded thumbs</a> using php, just use Thumbnailer :)</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-32054012240277936382018-11-19T12:00:00.000-08:002018-11-19T12:01:35.611-08:00Tutorial :Can we use Extension Methods for building business rule engines?<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>I am looking to do something like this</p> <pre><code>public class ProductBiz: BizBase&lt;Product&gt; { public List&lt;String&gt; BrokenRules {get;set;} // Some kind of data + biz operation implementation } public static class ProductBizExtensions{ public ProductBiz Rule1(this ProductBiz prodBiz) {} public ProductBiz Rule2(this ProductBiz prodBiz) {} public bool ApplyRules (this ProductBiz prodBiz, Func&lt;ProductBiz,bool&gt; ruleset){} } </code></pre> <p>Then in client code use it as</p> <pre><code>productBiz.Rule1().Rule2(); productBiz.Rule2().Rule1(); </code></pre> <p>OR</p> <pre><code>// create multicasted delegate of type Func&lt;ProductBiz,bool&gt; say rulesetDelegate productBiz.ApplyRules(rulesetDelegate); </code></pre> <p>Just wanted to ask before i dive deep and drown.</p> <p>What are the potential pitfalls with this approach???</p> <p>Thanks in advance</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>I'm not sure what you mean by possible. It's certainly possible to write a rules engine in this way and you've demo'd an outline of how to achieve this.</p> <p>Don't forget that extension methods are just syntactic sugar on top of static methods. Asking if you can do X type of programming with extension methods is no different than asking if you can do X type of programming with static methods. Static methods may not look as nice but they are just as powerful. </p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>If you're looking at changing the rules at run-time then you might want to consider something more like <a href="http://mef.codeplex.com/" rel="nofollow noreferrer">MEF</a> or similar. </p> <p>Your solution is fine up until you compile, then it's set and locked, from the sound of your comments you're looking for run-time flexibility.</p> </div><h3> <br> Solution:3<br> </h3><div class="post-text" itemprop="text"> <p>Look at the implementation of business rules in CSLA <a href="http://lhotka.net/" rel="nofollow noreferrer">http://lhotka.net/</a> . In that you define a rule w/ a particular signature, and add it into the object's rule store, either at a class level or instance level. The syntax of what you are attempting to do is off-putting, but the method (defining business rules via static methods which are executed at run time) is exactly what CSLA does.</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-77655298965665942562018-11-19T11:59:00.000-08:002018-11-19T12:00:57.589-08:00Tutorial :iPhone: Data structure choice<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>I need to keep track of a bunch of objects that can be identified by two keys (Latitude and longitude actually, but there are some other properties). I need to do things like search for a particular object by those two keys, updating it if it is there and inserting if not. I was thinking. I was looking at NSDictionary and NSSet but thought I would hear what the masses have to say.</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>I guess the simpler way is to use <code>NSDictionary</code>. You will be able to get your data by just doing <code>[dic objectForKey:key]</code>.</p> <p>Also, a good practice is to create some defines for the keys, so that it's easier to change a key name, and also avoids typo:</p> <pre><code>#define kObjectLatitude @"Latitude" #define kObjectLongitude @"Longitude" [object setObject:lat forKey:kObjectLatitude]; [object setObject:lon forKey:kObjectLongitude]; </code></pre> <p>Don't forget to write the defines in a smart place. If you use it only in one class, just write them at the top of the declaration. If, however, you need them through different part of your code, you might consider moving it to the header file of the main class, or a specific header file for defines :)</p> <p>NS(Mutable)Set will not be useful for you in this case. NSSets are mathematical sets, and you cannot access a specific data with a specific key (aka, you can't ask a set: "Hey, give me the longitude, where-ever you stored it!")</p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>This is not a direct answer, but a word of warning. Latitude and longitude are CLLocationDegrees, which is a double precision floating point value. Testing for equality on floats is a risky proposition since floating point math is inexact. You can easily have an equality test fail on two floats that should theoretically be equal. I don't know the requirements of your application, but you may want to test for proximity rather than equality.</p> </div><h3> <br> Solution:3<br> </h3><div class="post-text" itemprop="text"> <p>Use NSDictionary. That's what it meant for.</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-37928507940966742402018-11-19T11:39:00.000-08:002018-11-19T11:40:41.496-08:00Tutorial :Displaying live video from a raw uncompressed byte source in C#: WPF vs. Win forms<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>I have a live 16-bit gray-scale video stream that is pushed through a ring-buffer in memory as a raw, uncompressed byte stream (2 bytes per pixel, 2^18 pixels/frame, 32 frames/sec). (This is coming from a scientific grade camera, via a PCI frame-grabber). I would like to do some simple processing on the video (clip dynamic range, colorize, add overlays) and then show it in a window, using C#.</p> <p>I have this working using Windows Forms &amp; GDI (for each frame, build a Bitmap object, write raw 32-bit RGB pixel values based on my post-processing steps, and then draw the frame using the Graphics class). But this uses a significant chunk of CPU that I'd like to use for other things. So I'm interested in using WPF for its GPU-accelerated video display. (I'd also like to start using WPF for its data binding &amp; layout features.) </p> <p>But I've never used WPF before, so I'm unsure how to approach this. Most of what I find online about video &amp; WPF involves reading a compressed video file from disk (e.g. WMV), or getting a stream from a consumer-grade camera using a driver layer that Windows already understands. So it doesn't seem to apply here (but correct me if I'm wrong about this).</p> <p>So, my questions:</p> <ul> <li><p>Is there a straighforward, WPF-based way to play video from raw, uncompressed bytes in memory (even if just as 8-bit grayscale, or 24-bit RGB)?</p></li> <li><p>Will I need to build DirectShow filters (or other DirectShow/Media Foundation-ish things) to get the post-processing working on the GPU? </p></li> </ul> <p>Also, any general advice / suggestions for documentation, examples, blogs, etc that are appropriate to these tasks would be appreciated. Thanks!</p> <hr> <p><strong>Follow-up:</strong> After some experimentation, I found <code>WriteableBitmap</code> to be fast enough for my needs, and extremely easy to use correctly: Simply call <code>WritePixels()</code> and any <code>Image</code> controls bound to it will update themselves. <code>InteropBitmap</code> with memory-mapped sections is noticeably faster, but I had to write p/invokes to kernel32.dll to use it on .NET 3.5.</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>My VideoRendererElement, though very efficient, does use some hackery to make it work. You may also want to experiment with the WriteableBitmap in .NET 3.5 SP1.</p> <p>Also the InteropBitmap is very fast too. Much more efficient than the WB as it's not double buffered. Though it can be subject to video tearing.</p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>Some further Google-searching yielded this:</p> <p><a href="http://www.codeplex.com/VideoRendererElement" rel="nofollow noreferrer">http://www.codeplex.com/VideoRendererElement</a></p> <p>which I'm looking into now, but may be the right approach here. Of course further thoughts/suggestions are still very much welcome.</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-15059891743816723172018-11-19T11:19:00.000-08:002018-11-19T11:20:43.855-08:00Tutorial :How to implement tagging system similar to SO in php/mysql?<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>I'm coding a website in PHP/MySQL and I'd like to implement a similar to stackoverflow tagging engine. I have 3 relevant tables in DB: 1. Items 2. Tags 3. ItemTagMap (maps tags to items, n:n mapping)</p> <p>Now, on search page I'd like to show distinct list of all tags for entire search result (not just the current page), so that users can "refine" their search by adding/removing tags from that tag list.</p> <p>The question is that it's a pretty heavy query on the DB and there can be tons of search requests that result in different result sets and thus different tag sets.</p> <p>Does anyone know how to implement this effectively?</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>Before we go into <strong>premature optimization</strong> mode, it may be useful to look into the following query template. If nothing else this could be used as a baseline against which the effectiveness of possible optimizations can be measured.</p> <pre class="lang-sql prettyprint-override"><code>SELECT T.Tagid, TagInfo.TagName, COUNT(*) FROM Items I JOIN Tags TagInfo ON TagInfo.TagId = T.TagId JOIN ItemTagMap T ON I.ItemId = T.ItemId --JOIN ItemTagMap T1 ON I.ItemId = T1.ItemId WHERE I.ItemId IN ( SELECT ItemId FROM Items WHERE -- Some typical initial search criteria Title LIKE 'Bug Report%' -- Or some fulltext filter instead... AND ItemDate &gt; '02/22/2008' AND Status = 'C' ) --AND T1.TagId = 'MySql' GROUP BY T.TagId, TagInfo.TagName ORDER BY COUNT(*) DESC </code></pre> <p>The subquery is the "driving query", i.e. the one corresponding to the end-user's initial criteria. (see below for details on how this query, required multiple times may fit in an overall optimized flow) Commented is the JOIN on T1 (and possibly T2, T3, when several tags are selected), and, with the WHERE clause, the associated criteria. These are needed when the user selects a particular tag, whether as part of the initial search or by refinement. (It may be more efficient to place these joins and where clauses within the sub-query; more on these below)</p> <p><strong>Discussion...</strong> The "driving query", or a variation thereof is needed for two distinct purposes:</p> <ul> <li><h1>1 to provide the <em>complete</em> list of ItemId which is needed to enumerate all associated tags.</h1></li> <li><h1>2 to provide the first N ItemId values (N being the display page size), for the purpose of looking up Item detail info in the Item table.</h1></li> </ul> <p>Note that the complete list doesn't need to be sorted (or it may benefit from sorting in a different order), whereby the second list needs to be sorted based on the user's choice (say by Date, descending or by Title, alphabetically ascending). Also note that if there is any sort order required, the cost of the query will imply dealing with the complete list (shy of odd optimization by SQL itself, and/or some denormalization, SQL needs to "see" the last records on that list, in case they belong to the top, sort-wise).</p> <p>This latter fact, is in favor of having the very same query for both purposes, the corresponding list can be stored in a temporary table. The general flow would be to quickly lookup the top N Item records with their details and returns this to the application at once. The application can then obtain ajax-fashion the list of Tags for refinements. This list would be produce with a query akin the one above, where the subquery is replaced by a "select * from temporaryTable." The odds are good that the SQL optimizer will decide to sort this list (in some cases), let's let it do that, rather than second guessing it and sorting it explicitly. <br></p> <p>One other point to consider is to maybe bring the join(s) on ItemTagMap table inside the "driving query" rather that as shown above. It is probably best to do so, both for performance, and because it will produce the right list for the #2 purpose (display of a page of items).</p> <p>The query/flow described above will likely scale rather well, even on relatively modest hardware; tentatively into the 1/2 Million+ Items, with sustained user searches maybe up to 10 per second. One of the key factor would be the selectivity of the initial search criteria.</p> <p><strong>Optimization ideas</strong></p> <ul> <li>[Depending on the typical search cases and on the data stats] it may make sense to denormalize by bringing (indeed duplicating) some of Items' fields to the ItemTagMap table. Short fields in particular may be 'welcome' there.</li> <li>As the data grows in the million+ Items, we could exploit the typically strong correlation of some tags (ex: in SO, PHP often comes with MySql, btw often for no good reason...), with various tricks. For example the introduction of "multi-Tag" TagIds could render the input logic a bit more complicated, but could also reduce the Map size significantly. </li> </ul> <p><br> -- 'nough said! --<br> Appropriate architecture and optimizations should be selected in light of the actual requirements and of the effective data statistical profile...</p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>You'll want to try to minimize the number of DB calls, putting the heavy work into PHP.</p> <p>First, select all your Items from the DB:</p> <pre><code>select * from items where (conditions); </code></pre> <p>Then, create an array of all id's from the result set.</p> <pre><code>$ids = array(); foreach ($items as $item) { $ids[] = $item['id']; } $ids = implode(',' $ids); </code></pre> <p>Then select all ItemTagMaps and associated tag data for the Item ID's you previously retrieved.</p> <pre><code>select map.item_id, t.id, t.name from tags t, item_tag_maps map where t.id = map.tag_id and map.item_id in ($ids); </code></pre> <p>Now when you loop through your $items array, you can locate all matching tags from the 2nd SQL query you performed as long as it has a matching item_id value.</p> </div><h3> <br> Solution:3<br> </h3><div class="post-text" itemprop="text"> <p>Assuming:</p> <ul> <li>Item (id);</li> <li>Tag (id, name) with index on name;</li> <li>ItemTag (item_id, tag_id).</li> </ul> <p>then:</p> <pre class="lang-sql prettyprint-override"><code>SELECT t.name FROM Tag t WHERE EXISTS (SELECT 1 FROM ItemTag WHERE item_id = 1234) ORDER BY t.name </code></pre> <p>Nothing intensive about that. This is similar but my guess is it would be slower:</p> <pre class="lang-sql prettyprint-override"><code>SELECT t.name FROM Tag t WHERE t.id IN (SELECT tag_id FROM ItemTag WHERE item_id = 1234) ORDER BY t.name </code></pre> <p>This can be done as a join as well:</p> <pre class="lang-sql prettyprint-override"><code>SELECT DISTINCT t.name FROM Tag t JOIN ItemTag i WHERE i.tag_id = t.id WHERE i.item_id = 1234 ORDER BY t.name </code></pre> <p>I think the first one will be faster but as is always the case with SQL, it's worth testing (on a sufficiently sized data set).</p> <p>The above have been done to list the tags for a single item. You want a composite set of tags for search results. That's not difficult from the above but it depends on how you get your search results.</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-85703200050151234662018-11-19T11:00:00.000-08:002018-11-19T11:01:34.815-08:00Tutorial :Java Orkut Login [closed]<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>I want the pagesource of home page of ORKUT (<a href="http://www.ORKUT.com" rel="nofollow noreferrer">http://www.ORKUT.com</a>) in java.</p> <p>But it needs to be logged in to the ORKUT before accessing any page of it. How can I do it. It should not involve browser in between</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>You should have a look at the <a href="http://hc.apache.org/httpclient-3.x/" rel="nofollow noreferrer">Commons HTTP Client</a>. With it you can send a POST request with your login data and then use the session ID for further processing.</p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>If you don't mind to read C# code:</p> <pre><code> string orkutSite = "http://www.orkut.com/Login.aspx"; // enter correct address string formPage = ""; string afterLoginPage = ""; // Get postback data and cookies CookieContainer cookies = new CookieContainer(); HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(orkutSite); getRequest.CookieContainer = cookies; getRequest.Method = "GET"; HttpWebResponse form = (HttpWebResponse)getRequest.GetResponse(); using (StreamReader response = new StreamReader(form.GetResponseStream(), Encoding.UTF8)) { formPage = response.ReadToEnd(); } Dictionary&lt;string, string&gt; inputs = new Dictionary&lt;string,string&gt;(); inputs.Add("__EVENTTARGET", ""); inputs.Add("__EVENTARGUMENT", ""); foreach (Match input in Regex.Matches(formPage, @"&lt;input.*?name=""(?&lt;name&gt;.*?)"".*?(?:value=""(?&lt;value&gt;.*?)"".*?)? /&gt;", RegexOptions.IgnoreCase | RegexOptions.ECMAScript)) { inputs.Add(input.Groups["name"].Value, input.Groups["value"].Value); } inputs["username"] = "xxxxx"; // *please*, check for \\ inputs["password"] = "yyyyy"; // correct field names \\ byte[] buffer = Encoding.UTF8.GetBytes( String.Join("&amp;", Array.ConvertAll&lt;KeyValuePair&lt;string, string&gt;, string&gt;( inputs.ToArray(), delegate(KeyValuePair item) { return item.Key + "=" + HttpUtility.UrlEncode(item.Value); }))); HttpWebRequest postRequest = (HttpWebRequest)WebRequest.Create(orkutSite); postRequest.CookieContainer = cookies; postRequest.Method = "POST"; postRequest.ContentType = "application/x-www-form-urlencoded"; // send username/password using (Stream stream = postRequest.GetRequestStream()) { stream.Write(buffer, 0, buffer.Length); } // get response from login page using (StreamReader reader = new StreamReader( postRequest.GetResponse().GetResponseStream(), Encoding.UTF8)) { afterLoginPage = reader.ReadToEnd(); } </code></pre> </div><h3> <br> Solution:3<br> </h3><div class="post-text" itemprop="text"> <p>Two ways of doing that:</p> <p>1) Buy Octazen that will do that for you and keep the library updated every time Orkut changes something.</p> <p>2) Use watir to hijack the browser.</p> <p>Doing with HTTP Client is like fixing a watch with boxing gloves under the water. It does not support JS, you have to work your way through the cookies, parsing, etc.</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-32263482103472011092018-11-19T10:59:00.000-08:002018-11-19T11:00:58.175-08:00Tutorial :Garbage values when C++ Operator Overloading<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>Im just getting garbage values. And it is wierd the debugger shows the correct values. But its printing weird stuff insted...</p> <p>this frist part is fine. Essentially, It just takes me to my problem. I have what I need to print inside that h.hashtable[hashIndex] array.</p> <pre><code>ostream&amp; operator&lt;&lt;(ostream&amp; out, const hashmap&amp; h) { const char *getSymbol = NULL; for ( int hashIndex = 0; hashIndex &lt; maxSize; hashIndex++ ) { getSymbol = h.hashTable[hashIndex].getSymbol(); if ( getSymbol ) // Find the one I added. { h.hashTable-&gt;display(out); return out &lt;&lt; h.hashTable[hashIndex]; } } return out; } </code></pre> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>Make sure the stream is set to print in decimal</p> <pre><code>out &lt;&lt; dec &lt;&lt; s.m_sharePrice; </code></pre> <p>(<code>m_sharePrice</code> is a non-pointer type, right?)</p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>Is the values at line:</p> <pre><code>getSymbol = h.hashTable[hashIndex].getSymbol(); </code></pre> <p>fine, but crap afterwards?</p> <p>You could be having a case where you have a const char* to something inside an anonymous variable, which gets deleted when the line is done.</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-2310310427941259612018-11-19T10:39:00.000-08:002018-11-19T10:40:43.703-08:00Tutorial :Why is the .NET Colors class not static?<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>I was browsing the colors class's source in reflector and it's just a sealed class. But all members are static. So why would anyone create a copy of the Colors class?</p> <p>It lies inside:</p> <pre><code>System.Windows.Media.Colors </code></pre> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>A static class is just a sealed <strong>abstract</strong> class with <s>private constructor</s> no constructors (as in, no constructors at any accessibility level, not even ones generated by the compiler) [fixed per Eric's comment]. The C# keyword <code>static</code> is simply a shorthand for that, and also forces you to make all members static, but for API clients it's exact same thing.</p> <p>Given that work on WPF (then Avalon) began before .NET 2.0 was released, it could be that this particular class was written before <code>static class</code> appeared. Or perhaps the author was simply unaware of that language feature.</p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>For me, <code>Colors.AliceBlue</code> and <code>Colors.AntiqueWhite</code> (the first and the second static property of Colors class :)) should be difference instances of Color objects instead of different types. </p> <p><code>public static Color AliceBlue {get;}</code> </p> <p>Please note that a static class is a sealed class that contains only static members and <em>cannot be instantiated using the <strong>new</strong> keyword</em> as it can only have a private default constructor (at least in C#).</p> <p>Imagine you are creating an API that takes Color as an argument, what will it look like if the Color is a static class? </p> <p>One can argue that different colors should be different types (arguably static as well) instead of different instances of the Color class. Even with this case, Color should not be a static class because you want to have a base Color class for individual Color classes and making the base Color class static automatically makes it sealed. </p> <p>One may still want to argue that Color should be a namespace and individual colors should be static classes. I will simply ask them to imagine what the API will look like again :)</p> </div><h3> <br> Solution:3<br> </h3><div class="post-text" itemprop="text"> <p>Because a <code>sealed</code> class with all static members and private constructor constitutes certain performance enhancements because of the way the <code>IL</code> is formed for the use of the <code>static</code> class versus the <code>sealed</code> class, in-fact the static class gets the <code>abstract</code> modifier in IL to prevent new from being called where as the <code>sealed</code> class does not.</p> <p>See.. <a href="http://social.msdn.microsoft.com/Forums/br/csharplanguage/thread/7f0b56ca-fc61-4b64-ae31-3581398996e8" rel="nofollow">This post on msdn social</a> </p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-77435903405771049022018-11-19T10:19:00.000-08:002018-11-19T10:20:43.912-08:00Tutorial :Excel VBA âAutofill Method of Range Class Failedâ<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>The following VBA code (Excel 2007) is failing with Error 1004, "Autofill Method of Range Class Failed.". Can anyone tell me how to fix it?</p> <pre><code>Dim src As Range, out As Range, wks As Worksheet Set wks = Me Set out = wks.Range("B:U") Set src = wks.Range("A6") src.AutoFill Destination:=out </code></pre> <p>(note: I have Googled, etc. for this. It comes up fairly often, but all of the responses that I saw had to do with malformed range addresses, which AFAIK is not my problem.</p> <hr> <p>At someone's suggestion I tried replacing the autofill line with the following:</p> <pre><code>src.Copy out </code></pre> <p>This had the effect of throwing my Excel session into an apparent infinite loop consuming 100% CPU and then just hanging forever.</p> <hr> <p>OK, apparently the source has to be part of the destination range for autofill. So my code now looks like this:</p> <pre><code>Dim src As Range, out As Range, wks As Worksheet Set wks = Me Set out = wks.Range("B1") Set src = wks.Range("A6") src.Copy out Set out = wks.Range("B:U") Set src = wks.Range("B1") src.AutoFill Destination:=out, Type:=xlFillCopy </code></pre> <p>Same error on the last line.</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>From <a href="http://msdn.microsoft.com/en-us/library/bb209671.aspx" rel="noreferrer">MSDN</a>:</p> <blockquote> <p>The destination must include the source range.</p> </blockquote> <p><code>B:U</code> does not contain <code>A6</code> and thus there is an error. I believe that you probably want <code>out</code> to be set to <code>A6:U6</code>.</p> <p>Specifiying just the column name means that you want to fill every row in that column which is unlikely to be the desired behvaiour</p> <hr> <p><strong>Update</strong></p> <p>Further to the OP's comment below and update to the original answer, this might do the trick:</p> <pre><code>Dim src As Range, out As Range, wks As Worksheet Set wks = Me Set out = wks.Range("B1") Set src = wks.Range("A6") src.Copy out Set out = wks.Range("B1:U1") Set src = wks.Range("B1") src.AutoFill Destination:=out, Type:=xlFillCopy Set out = wks.Range("B:U") Set src = wks.Range("B1:U1") src.AutoFill Destination:=out, Type:=xlFillCopy </code></pre> <p><code>AutoFill</code> is constrained to a single direction (i.e. horizontal or vertical) at once. To fill a two-dimensional area from a single cell you first have to auto-fill a line along one edge of that area and then stretch that line across the area</p> <p>For the specific case of copying the formatting and clearing the contents (by virtue of the source cell being empty), this is better:</p> <pre><code>Dim src As Range, out As Range, wks As Worksheet Set wks = Sheet1 Set out = wks.Range("B:U") Set src = wks.Range("A6") src.Copy out </code></pre> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>To make <code>AutoFill</code> work, you need to make the range of <code>AutoFill</code> more than the <em>source range</em>. If the AutoFill range is same as of Source range then there is nothing to AutoFill in that range and hence you would get an error </p> <blockquote> <p>1004: AutoFill method of Range class failed.</p> </blockquote> <p>So make AutoFill range more than the source range and error will gone. </p> </div><h3> <br> Solution:3<br> </h3><div class="post-text" itemprop="text"> <p>If you want to autofill you just do something like...</p> <pre><code>Private Sub Autofill() 'Select the cell which has the value you want to autofill Range("Q2").Select 'Do an autofill down to the amount of values returned by the update Selection.AutoFill Destination:=Range("Q2:Q10") End Sub </code></pre> <p>This would autofill down to the specified range.</p> <p>Does ths help?</p> </div><h3> <br> Solution:4<br> </h3><div class="post-text" itemprop="text"> <p>Not sure if this helps anyone, but I needed something similar. Selecting the cells as destination works;</p> <pre><code>dim rowcount as integer Sheets("IssueTemplate").Select ' Whatever your sheet is rowcount = 0 rowcount = Application.CountA(Range("A:A"))'get end range Cells(4, 3).Select 'select the start cell 'autofill to rowcount Selection.AutoFill Destination:=Range("C4:C" &amp; rowcount), Type:=xlFillDefault </code></pre> <p>in my example I had to auto-generate a list of folder names from OA100 to OA###?, and this worked fine. </p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-21815130122512592202018-11-19T09:59:00.000-08:002018-11-19T10:00:57.793-08:00Tutorial :Django Vote Up/Down method [closed]<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>I am making a small app that lets users vote items either up or down. I'm using Django (and new to it!).</p> <p>I am just wondering, what is the best way to present the upvote link to the user. As a link, button or something else?</p> <p>I have already done something like this in php with a different framework but I'm not sure if I can do it the same way. Should I have a method for up/down vote and then display a link to the user to click. When they click it, it performs the method and refreshes the page?</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>Just plug and play: </p> <blockquote> <p>RedditStyleVoting<br> Implementing reddit style voting for any Model with django-voting<br><a href="http://code.google.com/p/django-voting/wiki/RedditStyleVoting" rel="noreferrer">http://code.google.com/p/django-voting/wiki/RedditStyleVoting</a></p> </blockquote> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>Here's the gist of my solution. I use images with jQuery/AJAX to handle clicks. Strongly influenced by this site. There's some stuff that could use some work (error handling in the client, for example -- and much of it could probably be refactored) but hopefully the code is useful to you.</p> <p>The HTML:</p> <pre><code> &lt;div class="vote-buttons"&gt; {% ifequal thisUserUpVote 0 %} &lt;img class="vote-up" src = "images/vote-up-off.png" title="Vote this thread UP. (click again to undo)" /&gt; {% else %} &lt;img class="vote-up selected" src = "images/vote-up-on.png" title="Vote this thread UP. (click again to undo)" /&gt; {% endifequal %} {% ifequal thisUserDownVote 0 %} &lt;img class="vote-down" src = "images/vote-down-off.png" title="Vote this thread DOWN if it is innapropriate or incorrect. (click again to undo)" /&gt; {% else %} &lt;img class="vote-down selected" src = "images/vote-down-on.png" title="Vote this thread DOWN if it is innapropriate or incorrect. (click again to undo)" /&gt; {% endifequal %} &lt;/div&gt; &lt;!-- .votebuttons --&gt; </code></pre> <p>The jQuery:</p> <pre><code>$(document).ready(function() { $('div.vote-buttons img.vote-up').click(function() { var id = {{ thread.id }}; var vote_type = 'up'; if ($(this).hasClass('selected')) { var vote_action = 'recall-vote' $.post('/ajax/thread/vote', {id:id, type:vote_type, action:vote_action}, function(response) { if (isInt(response)) { $('img.vote-up').removeAttr('src') .attr('src', 'images/vote-up-off.png') .removeClass('selected'); $('div.vote-tally span.num').html(response); } }); } else { var vote_action = 'vote' $.post('/ajax/thread/vote', {id:id, type:vote_type, action:vote_action}, function(response) { if (isInt(response)) { $('img.vote-up').removeAttr('src') .attr('src', 'images/vote-up-on.png') .addClass('selected'); $('div.vote-tally span.num').html(response); } }); } }); </code></pre> <p>The Django view that handles the AJAX request:</p> <pre><code>def vote(request): thread_id = int(request.POST.get('id')) vote_type = request.POST.get('type') vote_action = request.POST.get('action') thread = get_object_or_404(Thread, pk=thread_id) thisUserUpVote = thread.userUpVotes.filter(id = request.user.id).count() thisUserDownVote = thread.userDownVotes.filter(id = request.user.id).count() if (vote_action == 'vote'): if (thisUserUpVote == 0) and (thisUserDownVote == 0): if (vote_type == 'up'): thread.userUpVotes.add(request.user) elif (vote_type == 'down'): thread.userDownVotes.add(request.user) else: return HttpResponse('error-unknown vote type') else: return HttpResponse('error - already voted', thisUserUpVote, thisUserDownVote) elif (vote_action == 'recall-vote'): if (vote_type == 'up') and (thisUserUpVote == 1): thread.userUpVotes.remove(request.user) elif (vote_type == 'down') and (thisUserDownVote ==1): thread.userDownVotes.remove(request.user) else: return HttpResponse('error - unknown vote type or no vote to recall') else: return HttpResponse('error - bad action') num_votes = thread.userUpVotes.count() - thread.userDownVotes.count() return HttpResponse(num_votes) </code></pre> <p>And the relevant parts of the Thread model:</p> <pre><code>class Thread(models.Model): # ... userUpVotes = models.ManyToManyField(User, blank=True, related_name='threadUpVotes') userDownVotes = models.ManyToManyField(User, blank=True, related_name='threadDownVotes') </code></pre> </div><h3> <br> Solution:3<br> </h3><div class="post-text" itemprop="text"> <p>Whatever you do, make sure that it's submitted by POST and not GET; GET requests should <em>never</em> alter database information.</p> </div><h3> <br> Solution:4<br> </h3><div class="post-text" itemprop="text"> <blockquote> <p><em>As a link, button or something else?</em></p> </blockquote> <p>Something else, what about an image?</p> <blockquote> <p><em>When they click it, it performs the method and refreshes the page?</em></p> </blockquote> <p>Perhaps you could better use ajax to invoke a method to save the vote, and not refresh anything at all.</p> <p>This is what comes to my mind.</p> <p><a href="https://i.stack.imgur.com/b4IiR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b4IiR.png" alt="enter image description here"></a></p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-67165826462558805152018-11-19T09:39:00.000-08:002018-11-19T09:40:41.921-08:00Tutorial :Make a window topmost using a window handle<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>After launching an application using the Process class I'd like to make that window topmost. Currently, my app is the topmost window so when i launch the other app it doesn't display. One thing that came to mind is that I could set topmost = false for my application before launching the process, the problem with this is I want to give the process ample time to load up before displaying it to the user, so I'd like more control over when I switch the other application to the topmost.</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>You need to use <a href="http://www.pinvoke.net/default.aspx/user32.SetWindowPos" rel="noreferrer">P/Invoke with SetWindowPos</a> to accopmlish this:</p> <pre><code>[DllImport("user32.dll")] static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); const UInt32 SWP_NOSIZE = 0x0001; const UInt32 SWP_NOMOVE = 0x0002; const UInt32 SWP_SHOWWINDOW = 0x0040; // Call this way: SetWindowPos(theWindowHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); </code></pre> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-25096950800042401662018-11-19T09:19:00.000-08:002018-11-19T09:20:43.353-08:00Tutorial :What is âOrthogonalityâ?<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>What does "orthogonality" mean when talking about programming languages? </p> <p>What are some examples of Orthogonality?</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p><a href="http://en.wikipedia.org/wiki/Orthogonal" rel="noreferrer">Orthogonality</a> is the property that means "Changing A does not change B". An example of an orthogonal system would be a radio, where changing the station does not change the volume and vice-versa. </p> <p>A non-orthogonal system would be like a helicopter where changing the speed can change the direction.</p> <p>In programming languages this means that when you execute an instruction, nothing but that instruction happens (very important for debugging).</p> <p>There is also a specific meaning when referring to <a href="http://en.wikipedia.org/wiki/Orthogonal_instruction_set" rel="noreferrer">instruction sets</a>.</p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>From Eric S. Raymond's <a href="http://www.faqs.org/docs/artu/" rel="noreferrer">"Art of UNIX programming"</a></p> <blockquote> <p>Orthogonality is one of the most important properties that can help make even complex designs compact. In a purely orthogonal design, operations do not have side effects; each action (whether it's an API call, a macro invocation, or a language operation) changes just one thing without affecting others. There is one and only one way to change each property of whatever system you are controlling.</p> </blockquote> </div><h3> <br> Solution:3<br> </h3><div class="post-text" itemprop="text"> <p>Think of it has being able to change one thing without having an unseen affect on another part.</p> </div><h3> <br> Solution:4<br> </h3><div class="post-text" itemprop="text"> <p>Broadly, orthogonality is a relationship between two things such that they have minimal effect on each other.</p> <p>The term comes from mathematics, where two vectors are orthogonal if they intersect at right angles.</p> <p>Think about a typical 2 dimensional cartesian space (you typical grid with X/Y axes). Plot two lines: x=1 and y=1. The two lines are orthogonal. You can change x=1 by changing x, and this will have no effect on the other line, and vice versa.</p> <p>In software, the term can be appropriately used in situations where you're talking about two parts of a system which behave independently of each other.</p> </div><h3> <br> Solution:5<br> </h3><div class="post-text" itemprop="text"> <p>If you have a set of constructs. A langauge is said to be <em>orthogonal</em> if it allows the programmer to mix these constructs freely. For example, in C you can't return an array(static array), C is said to be unorthognal in this case:</p> <pre><code>int[] fun(); // you can't return a static array. // Of course you can return a pointer, but the langauge allows passing arrays. // So, it is unorthognal in case. </code></pre> </div><h3> <br> Solution:6<br> </h3><div class="post-text" itemprop="text"> <p>Most of the answers are very long-winded, and even obscure. The point is: if a tool is orthogonal, it can be added, replaced, or removed, in favor of better tools, without screwing everything else up.</p> <p>It's the difference between a carpenter having a hammer and a saw, which can be used for hammering or sawing, or having some new-fangled hammer/saw combo, which is designed to saw wood, then hammer it together. Either will work for sawing and then hammering together, but if you get some task that requires sawing, but not hammering, then only the orthogonal tools will work. Likewise, if you need to screw instead of hammering, you won't need to throw away your saw, if it's orthogonal (not mixed up with) your hammer.</p> <p>The classic example is unix command line tools: you have one tool for getting the contents of a disk (dd), another for filtering lines from the file (grep), another for writing those lines to a file (cat), etc. These can all be mixed and matched at will.</p> </div><h3> <br> Solution:7<br> </h3><div class="post-text" itemprop="text"> <p>from <a href="http://en.wikipedia.org/wiki/Orthogonal" rel="nofollow noreferrer">wikipedia</a>:</p> <p>Computer science</p> <p>Orthogonality is a system design property facilitating feasibility and compactness of complex designs. Orthogonality guarantees that modifying the technical effect produced by a component of a system neither creates nor propagates side effects to other components of the system. The emergent behavior of a system consisting of components should be controlled strictly by formal definitions of its logic and not by side effects resulting from poor integration, i.e. non-orthogonal design of modules and interfaces. Orthogonality reduces testing and development time because it is easier to verify designs that neither cause side effects nor depend on them.</p> <p>For example, a car has orthogonal components and controls (e.g. accelerating the vehicle does not influence anything else but the components involved exclusively with the acceleration function). On the other hand, a non-orthogonal design might have its steering influence its braking (e.g. electronic stability control), or its speed tweak its suspension.<a href="http://en.wikipedia.org/wiki/Orthogonal" rel="nofollow noreferrer">1</a> Consequently, this usage is seen to be derived from the use of orthogonal in mathematics: One may project a vector onto a subspace by projecting it onto each member of a set of basis vectors separately and adding the projections if and only if the basis vectors are mutually orthogonal.</p> <p>An instruction set is said to be orthogonal if any instruction can use any register in any addressing mode. This terminology results from considering an instruction as a vector whose components are the instruction fields. One field identifies the registers to be operated upon, and another specifies the addressing mode. An orthogonal instruction set uniquely encodes all combinations of registers and addressing modes.</p> </div><h3> <br> Solution:8<br> </h3><div class="post-text" itemprop="text"> <p>From <a href="http://en.wikipedia.org/wiki/Orthogonality#Computer_science" rel="nofollow noreferrer">Wikipedia</a>:</p> <blockquote> <p>Orthogonality is a system design property facilitating feasibility and compactness of complex designs. Orthogonality guarantees that modifying the technical effect produced by a component of a system neither creates nor propagates side effects to other components of the system. The emergent behavior of a system consisting of components should be controlled strictly by formal definitions of its logic and not by side effects resulting from poor integration, i.e. non-orthogonal design of modules and interfaces. Orthogonality reduces testing and development time because it is easier to verify designs that neither cause side effects nor depend on them.</p> <p>For example, a car has orthogonal components and controls (e.g. accelerating the vehicle does not influence anything else but the components involved exclusively with the acceleration function). On the other hand, a non-orthogonal design might have its steering influence its braking (e.g. electronic stability control), or its speed tweak its suspension.[1] Consequently, this usage is seen to be derived from the use of orthogonal in mathematics: One may project a vector onto a subspace by projecting it onto each member of a set of basis vectors separately and adding the projections if and only if the basis vectors are mutually orthogonal.</p> <p>An instruction set is said to be orthogonal if any instruction can use any register in any addressing mode. This terminology results from considering an instruction as a vector whose components are the instruction fields. One field identifies the registers to be operated upon, and another specifies the addressing mode. An orthogonal instruction set uniquely encodes all combinations of registers and addressing modes.</p> </blockquote> <p>To put it in the simplest terms possible, two things are orthogonal if changing one has no effect upon the other.</p> </div><h3> <br> Solution:9<br> </h3><div class="post-text" itemprop="text"> <p>While talking about project decisions on programming languages, orthogonality may be seen as how easy is for you to predict other things about that language for what you've seen in the past.</p> <p>For instance, in one language you can have:</p> <blockquote> <p>str.split</p> </blockquote> <p>for splitting a string and</p> <blockquote> <p>len(str)</p> </blockquote> <p>for getting the lenght.</p> <p>On a language more orthogonal, you would always use str.x or x(str).</p> <p>When you would clone an object or do anything else, you would know whether to use</p> <blockquote> <p>clone(obj)</p> </blockquote> <p>or</p> <blockquote> <p>obj.clone</p> </blockquote> <p>That's one of the main points on programming languages being orthogonal. That avoids you to consult the manual or ask someone.</p> <p>The wikipedia article talks more about orthogonality on complex designs or low level languages. As someone suggested above on a comment, the Sebesta book talks cleanly about orthogonality.</p> <p>If I would use only one sentence, I would say that a programming language is orthogonal when its unknown parts act as expected based on what you've seen. Or... no surprises.</p> <p>;)</p> </div><h3> <br> Solution:10<br> </h3><div class="post-text" itemprop="text"> <p><strong>Orthogonality in Programming:</strong></p> <blockquote> <p>Orthogonality is an important concept, addressing how a relatively small number of components can be combined in a relatively small number of ways to get the desired results. It is associated with simplicity; the more orthogonal the design, the fewer exceptions. This makes it easier to learn, read and write programs in a programming language. The meaning of an orthogonal feature is independent of context; the key parameters are symmetry and consistency (for example, a pointer is an orthogonal concept).</p> </blockquote> <p>from <a href="http://en.wikipedia.org/wiki/Orthogonality_%28programming%29" rel="nofollow">Wikipedia</a></p> </div><h3> <br> Solution:11<br> </h3><div class="post-text" itemprop="text"> <p>In programming languages a programming language feature is said to be orthogonal if it is bounded with no restrictions (or exceptions). For example, in Pascal functions can't return structured types. This is a restriction on returning values from a function. Therefore we it is considered as a non-orthogonal feature. ;)</p> </div><h3> <br> Solution:12<br> </h3><div class="post-text" itemprop="text"> <p>As examples of the lack of orthogonality in a high-level language, consider the following rules and exceptions in C. Although C has two kinds of structured data types, arrays and records (structs), records can be returned from functions but arrays cannot. A member of a structure can be any data type except void or a structure of the same type. An array element can be any data type except void or a function. Parameters are passed by value, unless they are arrays, in which case they are, in effect, passed by reference (because the appearance of an array name without a subscript in a C program is interpreted to be the address of the arrayâs first element)</p> </div><h3> <br> Solution:13<br> </h3><div class="post-text" itemprop="text"> <p>Orthogonality means the degree to which language consists of a set of independent primitive constructs that can be combined as necessary to express a program. Features are orthogonal if there are no restrictions on how they may be combined</p> <pre><code>Example : non-orthogonality </code></pre> <p>PASCAL: functions can't return structured types. Functional Languages are highly orthogonal.</p> </div><h3> <br> Solution:14<br> </h3><div class="post-text" itemprop="text"> <p>The basic idea of orthogonality is that things that are not related conceptually should not be related in the system. Parts of the architecture that really have nothing to do with the other, such as the database and the UI, should not need to be changed together. A change to one should not cause a change to the other. </p> </div><h3> <br> Solution:15<br> </h3><div class="post-text" itemprop="text"> <p>Orthogonality in a programming language means that a relatively small set of primitive constructs can be combined in a relatively small number of ways to build the control and data structures of the language. Furthermore, every pos- sible combination of primitives is legal and meaningful. For example, consider data types. Suppose a language has four primitive data types (integer, float, double, and character) and two type operators (array and pointer). If the two type operators can be applied to themselves and the four primitive data types, a large number of data structures can be defined. The meaning of an orthogonal language feature is independent of the context of its appearance in a program. (the word orthogonal comes from the mathematical concept of orthogonal vectors, which are independent of each other.) Orthogonality follows from a symmetry of relationships among primi- tives. A lack of orthogonality leads to exceptions to the rules of the language. For example, in a programming language that supports pointers, it should be possible to define a pointer to point to any specific type defined in the language. However, if pointers are not allowed to point to arrays, many potentially useful user-defined data structures cannot be defined. We can illustrate the use of orthogonality as a design concept by compar- ing one aspect of the assembly languages of the IBM mainframe computers and the VAX series of minicomputers. We consider a single simple situation: adding two 32-bit integer values that reside in either memory or registers and replacing one of the two values with the sum. The IBM mainframes have two instructions for this purpose, which have the forms </p> <pre><code>A Reg1, memory_cell AR Reg1, Reg2 </code></pre> <p>where Reg1 and Reg2 represent registers. The semantics of these are</p> <pre><code>Reg1 â contents(Reg1) + contents(memory_cell) Reg1 â contents(Reg1) + contents(Reg2) </code></pre> <p>The VAX addition instruction for 32-bit integer values is</p> <pre><code>ADDL operand_1, operand_2 </code></pre> <p>whose semantics is</p> <pre><code>operand_2 â contents(operand_1) + contents(operand_2) </code></pre> <p>In this case, either operand can be a register or a memory cell. The VAX instruction design is orthogonal in that a single instruction can use either registers or memory cells as the operands. There are two ways to specify operands, which can be combined in all possible ways. The IBM design is not orthogonal. Only two out of four operand combinations possibilities are legal, and the two require different instructions, A and AR . The IBM design is more restricted and therefore less writable. For example, you cannot add two values and store the sum in a memory location. Furthermore, the IBM design is more difficult to learn because of the restrictions and the additional instruction. Orthogonality is closely related to simplicity: The more orthogonal the design of a language, the fewer exceptions the language rules require. Fewer exceptions mean a higher degree of regularity in the design, which makes the language easier to learn, read, and understand. Anyone who has learned a sig- nificant part of the English language can testify to the difficulty of learning its many rule exceptions (for example, i before e except after c).</p> </div><h3> <br> Solution:16<br> </h3><div class="post-text" itemprop="text"> <p>Check orthogonality of matrices:</p> <p>Orthogonality can also be with respect to matrices, </p> <pre><code>Matrix *(transpose of matrix)= identity matrix. </code></pre> <p>Click the below link to view a YouTube video on Orthogonality.<br><a href="https://youtu.be/tNekLaxnfW8" rel="nofollow noreferrer">https://youtu.be/tNekLaxnfW8</a></p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-12178623623758884862018-11-19T09:02:00.000-08:002018-11-19T09:04:28.881-08:00Tutorial :List of valid resolutions for a given Screen?<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>Is there a way to get ALL valid resolutions for a given screen?</p> <p>I currently have a dropdown that is populated with all valid screens (using <strong><em>Screen.AllScreens</em></strong>). When the user selects a screen, I'd like to present them with a second dropdown listing <em>all</em> valid resolutions for that display (<em>not</em> just the current resolution).</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>I think it should be possible to get the information using <a href="http://en.wikipedia.org/wiki/Windows_Management_Instrumentation" rel="nofollow noreferrer">Windows Management Instrumentation (WMI)</a>. WMI is accessible from .NET using the classes from them <a href="http://msdn.microsoft.com/en-us/library/system.management.aspx" rel="nofollow noreferrer">System.Management</a> namespace.</p> <p>A solution will look similar to the following. I don't know WMI well and could not immediately find the information you are looking for, but I found the WMI class for the resolutions supported by the video card. The code requires referencing System.Management.dll and importing the System.Management namespace.</p> <pre><code>var scope = new ManagementScope(); var query = new ObjectQuery("SELECT * FROM CIM_VideoControllerResolution"); using (var searcher = new ManagementObjectSearcher(scope, query)) { var results = searcher.Get(); foreach (var result in results) { Console.WriteLine( "caption={0}, description={1} resolution={2}x{3} " + "colors={4} refresh rate={5}|{6}|{7} scan mode={8}", result["Caption"], result["Description"], result["HorizontalResolution"], result["VerticalResolution"], result["NumberOfColors"], result["MinRefreshRate"], result["RefreshRate"], result["MaxRefreshRate"], result["ScanMode"]); } } </code></pre> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>The following link contains detailed code examples for this:</p> <p><strong>Task 2: Changing the Display Resolution</strong> <br><a href="http://msdn.microsoft.com/en-us/library/aa719104(VS.71).aspx#docum_topic2" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa719104(VS.71).aspx#docum_topic2</a></p> </div><h3> <br> Solution:3<br> </h3><div class="post-text" itemprop="text"> <p>The accepted answer doesn't seem to work on Windows 8.1, at least on my machine. The query runs fine but there are 0 entries in the results. And considering Bijoy K Jose's comment I suppose that I am not the only one.</p> <p>However the validated answer for the following question worked out just fine : <a href="https://stackoverflow.com/questions/744541/how-to-list-available-video-modes-using-c">How to list available video modes using C#?</a></p> <p>Thanks to Vimvq1987</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-6653753453959960292018-11-19T08:59:00.000-08:002018-11-19T09:01:03.063-08:00Tutorial :RESTful API response status code disambiguation<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>I'm developing a RESTful API and have a question about the most appropriate response status codes for certain scenarios.</p> <p>Consider the case where the client makes a GET request for a resource. How can I disambiguate a "not found" response for the case where the resource legitimately does not exist, vs. the case where there may be a minor service interruption (during deployment, etc).</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>The W3C defines <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html" rel="noreferrer">very specific status codes</a> for nearly all cases you can think of. For your specific needs:</p> <ul> <li>Not Found: 404</li> <li>Service Unavailable: 503</li> </ul> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>Send a 404 status code for "Not found"</p> <p>Send some <a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_Error" rel="nofollow noreferrer">500-series error</a> for error conditions on the server-side.</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-57306209276486522082018-11-19T08:39:00.000-08:002018-11-19T08:40:43.501-08:00Tutorial :If I have some massive process running in response to a users click will it keep running if they close the page?<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>If they close the browser page out after a process has started via a button on the page, will the process keep running until completion or will it die? How will I allow it to die safely if so?</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>The page will keep processing. If you want to terminate the processing you can check the <a href="http://msdn.microsoft.com/en-us/library/system.web.httpresponse.isclientconnected.aspx" rel="nofollow noreferrer">HttpResponse.IsClientConnected</a> property and end processing if the client is no longer connected. </p> <p>The example from MSDN:</p> <pre><code>private void Page_Load(object sender, EventArgs e) { // Check whether the browser remains // connected to the server. if (Response.IsClientConnected) { // If still connected, redirect // to another page. Response.Redirect("Page2CS.aspx", false); } else { // If the browser is not connected // stop all response processing. Response.End(); } } </code></pre> <p><br> However that assumes that are able to check the property. If you make a long running synchronous call then you wouldn't be able to check the property. If that is the case you can either execute it asynchronously or break the long running call into separate smaller calls where you can check the status before processing further.</p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>I would say, off hand, that that depends entirely on the process and how you've coded your solution.</p> <p>In my experience, however, there's no direct connection between the browser and the server. It's simulated through the use of session state. So once that process starts, I'd say yes, it will keep going until it sends the response back to the client. Whether or not the client is there to receive it is another matter altogether.</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-36463296261011883702018-11-19T08:19:00.000-08:002018-11-19T08:20:42.676-08:00Tutorial :C# - Windows ACL - Applying Inherited Permissions<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>I've been having problems programatically assigning permissions to Folders / Registry entries. I have managed to assign inheriting permissions using the following code:</p> <pre><code>FileSystemAccessRule rule = new FileSystemAccessRule(LOGON_USER_NAME, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow); DirectorySecurity security = new DirectorySecurity(); security.SetAccessRule(rule); Directory.CreateDirectory(dir); Directory.SetAccessControl(dir, security); </code></pre> <p>This correctly sets my file permissions on all the child folders i create as an administrator. However, it does not set the permissions on the <code>dir</code> folder itself. I've played around with a fair few permutations for inheritance and propogation, but not had any joy.</p> <p>For example, I have:</p> <pre><code>dir = %programfiles%\Test </code></pre> <p>If i have created a folder in test (<code>%programfiles%\Test\SubFolder</code>), I have full permissions assigned to it for my user, but I do not have full permissions on <code>%programfiles%\Test</code>. This is really annoying, as I would like to give my user full permissions to do whatever with the Test directory as well.</p> <p>I am having similar problems with registry permissions, but I believe that if i can solve one, i can solve both of the outstanding issues.</p> <p>Does anyone know how this can be resolved?</p> <p>Regards<br> Tris</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>For the folder:</p> <pre><code>FileSystemAccessRule rule = new FileSystemAccessRule(LOGON_USER_NAME, FileSystemRights.FullControl, AccessControlType.Allow); </code></pre> <p>For subfolders and files:</p> <pre><code>FileSystemAccessRule rule = new FileSystemAccessRule(LOGON_USER_NAME, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow); </code></pre> <p>both lines need to be in your project. then you get acls that apply to this folder, subfolders and files</p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>I'm hardly an expert here, but after having to figure this out for my own purposes, I believe that Dave's answer, although functional, is overly complicated. You should be able to achieve this with just one rule:</p> <pre><code>FileSystemAccessRule rule = new FileSystemAccessRule(LOGON_USER_NAME, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow); </code></pre> <p>The <code>PropagationFlags.InheritOnly</code> parameter used by the OP in their original code is what prevents the access rule from applying to the object itself.</p> <p>Also, you might as well set the directory's security as you're creating it, since .NET provides an overload for just that purpose:</p> <pre><code>Directory.CreateDirectory(dir, security); </code></pre> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-50042210494540282572018-11-19T08:00:00.000-08:002018-11-19T08:01:48.294-08:00Tutorial :Hosting images on separate sub domains<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>My company hosts about 30 web sites all sharing the same code base and reusing many of the same images. Right now, the images for all of the sites are hosted on the one domain, and then every other site has to link to those images.</p> <p>i.e., www.example.com/images/hello.jpg</p> <p>and on www.example2.com we have something like: <code>&lt;img src="http://www.example.com/images/hello.jpg" /&gt;</code></p> <p>Recently someone told me that I should be putting all of these shared/static images on a subdomain, but I don't see the advantages to this. I have heard that there might be a slight speed increase, but I've also heard that it can complicate things. Can someone elaborate?</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>A couple advantages to it:</p> <ul> <li>A separate domain prevents your domain's cookies from being sent for every image request, where they're not needed. Reduces the bandwidth overhead for each request.</li> <li>Most browsers will only make a certain number of HTTP requests at one time to a particular domain, so serving images and other static content off a second domain potentially doubles the number of HTTP requests at one time.</li> <li>You can conceivably use a different, lighter weight webserver like nginx/lighttpd to serve the static content.</li> </ul> <p>Downsides:</p> <ul> <li>Managing it.</li> <li>Two DNS lookups instead of one.</li> </ul> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>When a browser is requesting static files like CSS and Javascript, it often limits the number of connections to a given server/sub-domain. Putting static files under a different domain allows more simultaneous downloads.</p> <p>If set up correctly, the different sub-domain may just be a directory on your webserver. Depends on your config-file-fu.</p> </div><h3> <br> Solution:3<br> </h3><div class="post-text" itemprop="text"> <p>This is covered in a couple of the Stackoverflow podcasts.</p> <p>One concern - if you are serving an https page the user may get a warning about a mix of secure and insecure items.</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-56526267260380458422018-11-19T07:59:00.000-08:002018-11-19T08:00:56.602-08:00Tutorial :Skipping css file mentioned under asp.net App_themes folder<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>I've an asp.net web application which uses App_themes feature. Application has aspx pages which refer to master pages. Master pages apply css file (for eg. A.css) present in App_themes folder to all the aspx pages.</p> <p>For some of the aspx pages, I want to skip this A.css file and apply a new one called B.css instead.How do i achieve this?</p> <p>Note: A.css and B.css both have hundreds of classes.Ids for each class are same in both of them but have different attributes.</p> <p>Thanks for reading.</p> <hr> <p>Thanks a ton Martin and o.k.w. all for ur valuable inputs...can i use the approach mentioned at: <a href="http://www.joeaudette.com/overriding-the-location-for-app_themes.aspx" rel="nofollow noreferrer">http://www.joeaudette.com/overriding-the-location-for-app_themes.aspx</a> </p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>Maybe you can create two themes (one containing A.css, the other containing B.css) and switch the currently used theme in your master page (depending on the currently requested page).</p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>Once you assigned the theme, the ASPX pages automatically link to all the CSS files found within the assigned theme folder. If there's a need to totally skip one CSS for another, I realy think you should relook at your theming strategy.</p> <p>I can't provide a good answer unless I fully understand you needs/requirements. From what I can assume, you might need to 'normalise' your A.css and place it in the theme folder.</p> <p>Assuming B.css is used less frequently than A.css, have the css selectors and styles coded within B.css overwrite those of A.css that suit your needs. Assign B.css manually in your ASPX/masterpage markup AFTER that of the automatically assigned A's, for the cascading effect.</p> <p>In B.css, only code in those that needs to overwrite A's and those that A does not have.</p> <p>If both CSS files are used more or less as frequent and you are using masterpages, Martin's solution would be good too.</p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0tag:blogger.com,1999:blog-7213790564324356981.post-3464505152719632232018-11-19T07:39:00.000-08:002018-11-19T07:40:40.891-08:00Tutorial :sin, cos, tan and rounding error<br><img src='https://4.bp.blogspot.com/-te3nq62xJRQ/WIzbeIW_hiI/AAAAAAAAAaU/T9jgUxascMELRPlYee11mkSEA3KFhImRQCLcB/s1600/lucky%2Brathore%2B%2Buser%2Basked%2BQuestion_logo.jpg'/><h3> <br>Question:<br> </h3><div class="post-text" itemprop="text"> <p>I'm doing some trigonometry calculations in C/C++ and am running into problems with rounding errors. For example, on my Linux system:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;math.h&gt; int main(int argc, char *argv[]) { printf("%e\n", sin(M_PI)); return 0; } </code></pre> <p>This program gives the following output:</p> <pre><code>1.224647e-16 </code></pre> <p>when the correct answer is of course 0.</p> <p>How much rounding error can I expect when using trig functions? How can I best handle that error? I'm familiar with the Units in Last Place technique for comparing floating point numbers, from Bruce Dawson's <a href="http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm" rel="nofollow noreferrer">Comparing Floating Point Numbers</a>, but that doesn't seem to work here, since 0 and 1.22e-16 are quite a few ULPs apart.</p> </div><h3> <br> Solution:1<br> </h3><div class="post-text" itemprop="text"> <p>An IEEE double stores 52 bits of mantissa, with the "implicit leading one" forming a 53 bit number. An error in the bottom bit of a result therefore makes up about 1/2^53 of the scale of the numbers. Your output is of the same order as 1.0, so that comes out to just about exactly one part in 10^16 (because 53*log(2)/log(10) == 15.9).</p> <p>So yes. This is about the limit of the precision you can expect. I'm not sure what the ULP technique you're using is, but I suspect you're applying it wrong.</p> </div><h3> <br> Solution:2<br> </h3><div class="post-text" itemprop="text"> <p>The answer is only 0 for sin(pi) - did you include all the digits of Pi ?</p> <p>-Has anyone else noticed a distinct lack of, irony/sense of humour around here?</p> </div><h3> <br> Solution:3<br> </h3><div class="post-text" itemprop="text"> <p>@Josh Kelley - ok serious answer.<br> In general you should never compare the results of any operation involving floats or doubles with each other. </p> <p>The only exceptions is assignment.<br> float a=10.0;<br> float b=10.0;<br> then a==b</p> <p>Otherwise you always have to write some function like bool IsClose(float a,float b, float error) to allow you to check if two numbers are within 'error' of each other.<br> Remember to also check signs/use fabs - you could have -1.224647e-16 </p> </div><h3> <br> Solution:4<br> </h3><div class="post-text" itemprop="text"> <p>Sine of Ï is 0.0.<br> Sine of <code>M_PI</code> is about 1.224647e-16. </p> <p><strong><code>M_PI</code> is not Ï.</strong></p> <blockquote> <p>program gives ... 1.224647e-16 when the correct answer is of course 0.</p> </blockquote> <p>Code gave a correct answer to 7 places.</p> <hr> <p>The following does not print the sine of <a href="https://en.wikipedia.org/wiki/Pi" rel="nofollow noreferrer">Ï</a>. It prints the sine of a number close to Ï. See below pic.</p> <pre><code>Ï // 3.1415926535897932384626433832795... printf("%.21\n", M_PI); // 3.141592653589793115998 printf("%.21f\n", sin(M_PI));// 0.000000000000000122465 </code></pre> <p>Note: With the math function <em>sine(x)</em>, the slope of the curve is -1.0 at <em>x = Ï</em>. The difference of Ï and <code>M_PI</code> is about the <code>sin(M_PI)</code> - <em>as expected</em>.</p> <hr> <blockquote> <p>am running into problems with rounding errors</p> </blockquote> <p>The rounding problem occurs when using <code>M_PI</code> to present Ï. <code>M_PI</code> is the <code>double</code> closest to Ï, yet since Ï is irrational and all finite <code>double</code> are rational, they must differ - even by a small amount. So not a direct rounding issue with <code>sin(), cos(), tan()</code>. <code>sin(M_PI)</code> simple exposed the issue started with using an inexact Ï.</p> <hr> <p>This problem, with different non-zero results of <code>sin(M_PI)</code>, occurs if code used a different FP type like <code>float</code>, <code>long double</code> or <code>double</code> with something other than 53 binary bits of precision. This is not a precision issue so much as a irrational/rational one.</p> <p><a href="https://i.stack.imgur.com/IcWSd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IcWSd.png" alt="Sine(x) near Ï"></a></p> </div><h3> <br> Solution:5<br> </h3><div class="post-text" itemprop="text"> <p>There are two sources of error. The sin() function and the approximated value of M_PI. Even if the sin() function were 'perfect', it would not return zero unless the value of M_PI were also perfect - which it is not.</p> </div><h3> <br> Solution:6<br> </h3><div class="post-text" itemprop="text"> <p>I rather think that will be system-dependent. I don't think the Standard has anything to say on how accurate the transcendental functions will be. Unfortunately, I don't remember seeing any discussion of function precision, so you'll probably have to figure it out yourself.</p> </div><h3> <br> Solution:7<br> </h3><div class="post-text" itemprop="text"> <p>I get the exact same result on my system - I'd say it is close enough</p> <p>I would solve the problem by changing the format string to "%f\n" :)</p> <p>However, this gives you a "better" result, or at least on my system it does give -3.661369e-245</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;math.h&gt; int main(int argc, char *argv[]) { printf("%e\n", (long double)sin(M_PI)); return 0; } </code></pre> </div><h3> <br> Solution:8<br> </h3><div class="post-text" itemprop="text"> <p>Unless your program requires significant digits out to the 16th decimal place or more, you probably can do the rounding manually. From my experience programming games we always rounded our decimals to a tolerable significant digit. For example:</p> <pre><code>#include &lt;math.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #define HALF 0.5 #define GREATER_EQUAL_HALF(X) (X) &gt;= HALF double const M_PI = 2 * acos(0.0); double round(double val, unsigned places = 1) { val = val * pow(10.0f, (float)places); long longval = (long)val; if ( GREATER_EQUAL_HALF(val - longval) ) { return ceil(val) / pow(10.0f, (float)places); } else { return floor(val) / pow(10.0f, (float)places); } } int main() { printf("\nValue %lf", round(sin(M_PI), 10)); return 0; } </code></pre> </div><h3> <br> Solution:9<br> </h3><div class="post-text" itemprop="text"> <p>Maybe too low accuracy of implementation</p> <pre><code>M_PI = 3.14159265358979323846 (20 digits) </code></pre> <p><a href="http://fresh2refresh.com/c/c-function/c-math-h-library-functions/" rel="nofollow noreferrer">http://fresh2refresh.com/c/c-function/c-math-h-library-functions/</a></p> </div><br><b>Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com</b> Lucky Rathorehttps://plus.google.com/104241817701863380935noreply@blogger.com0