{"id":7369,"date":"2004-03-23T02:15:40","date_gmt":"2004-03-23T00:15:40","guid":{"rendered":"https:\/\/mamchenkov.net\/wordpress\/2004\/03\/23\/calculator-at-hand\/"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T22:00:00","slug":"calculator-at-hand","status":"publish","type":"post","link":"https:\/\/mamchenkov.net\/wordpress\/2004\/03\/23\/calculator-at-hand\/","title":{"rendered":"Calculator at hand"},"content":{"rendered":"<!-- google_ad_section_start -->\n<p>\t<img decoding=\"async\" class=\"alignright\" src=\"\/wordpress\/wp-content\/20040420-calculator_small.jpg\" alt=\"\">UNIX shell is excellent. The toolbox at hand also never stop to amaze. But sometimes there is this feeling that something is missing. No matter how many tools are there, you&#8217;ll still want something special and personalized.<\/p>\n<p>I am pretty often missing the calculator. Of course, there are xcalc and kcalc for graphical interface, but that&#8217;s just too slow for something that I should actually do in my head. There is bc(1) for console, but I never liked it for quick stuff. expr(1) is pretty close, but it needs a rather complex syntax like &#8220;expr 1 &#8216;+&#8217; 2&#8221;.\n<\/p>\n<p><!--more-->\t<\/p>\n<p>So here I am with a need for simple console calculator. Here is what I do &#8211; write a small perl script:<\/p>\n<div class=\"asis\"><code><br \/>\n<br \/>\n#!\/usr\/bin\/perl -w<\/p>\n<p>use strict;<\/p>\n<p>my $expr = shift;<br \/>\n<br \/>\nmy $verbose = $expr eq '-v' ? 1 : 0;<\/p>\n<p>$expr = shift if ($verbose);<br \/>\n<br \/>\ndo {<br \/>\n<br \/>\n        my $result = eval($expr);<br \/>\n<br \/>\n        print $expr . ' = '  if ($verbose);<br \/>\n<br \/>\n        print eval($expr) . \"<br \/>\n\";<br \/>\n<br \/>\n} while ( $expr = shift);<br \/>\n<br \/>\n<\/code><\/p>\n<\/div>\n<p>This can be than placed into any directory in the path and used as following:<\/p>\n<div class=\"asis\"><code><br \/>\n<br \/>\n[leonid@home tmp]$ calc.pl \"2+3\"<br \/>\n<br \/>\n5<br \/>\n<br \/>\n<\/code><\/p>\n<\/div>\n<p>The beauty of it is that it can do several equations at once and not only equations:<\/p>\n<div class=\"asis\"><code><br \/>\n<br \/>\n[leonid@home tmp]$ KOEF=`calc.pl '10 + 5'`<br \/>\n<br \/>\n[leonid@home tmp]$ calc.pl -v \"$KOEF * 2\" \"sqrt(256)\" \"localtime(time)\"<br \/>\n<br \/>\n15 * 2 = 30<br \/>\n<br \/>\nsqrt(256) = 16<br \/>\n<br \/>\nlocaltime(time) = Thu Feb 26 04:28:25 2004<br \/>\n<br \/>\n<\/code><\/p>\n<\/div>\n<p>This &#8216;-v&#8217; option causes calc.pl to print out the equation as well. Now I can totally forget arithmetics. :)<\/p>\n<!-- google_ad_section_end -->\n","protected":false},"excerpt":{"rendered":"<!-- google_ad_section_start -->\n<p>UNIX shell is excellent. The toolbox at hand also never stop to amaze. But sometimes there is this feeling that something is missing. No matter how many tools are there, you&#8217;ll still want something special and personalized. I am pretty often missing the calculator. Of course, there are xcalc and kcalc for graphical interface, but &hellip; <a href=\"https:\/\/mamchenkov.net\/wordpress\/2004\/03\/23\/calculator-at-hand\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Calculator at hand<\/span><\/a><\/p>\n<!-- google_ad_section_end -->\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_links_to":"","_links_to_target":""},"categories":[1,62],"tags":[],"keyring_services":[],"class_list":["post-7369","post","type-post","status-publish","format-standard","hentry","category-general","category-technology"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":26722,"url":"https:\/\/mamchenkov.net\/wordpress\/2016\/10\/11\/the-curious-case-of-the-switch-statement\/","url_meta":{"origin":7369,"position":0},"title":"The curious case of the switch statement","author":"Leonid Mamchenkov","date":"October 11, 2016","format":false,"excerpt":"\"The curious case of the switch statement\"\u00a0is a nice historical perspective on the switch statement in most modern programming languages, where it come from, and how it transformed over the years. \u00a0It starts of with ALGOL 58 (yes, a programming language from 1958), and traces the history down to the\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10682,"url":"https:\/\/mamchenkov.net\/wordpress\/2007\/03\/23\/sms-alerts-for-new-email-via-twitter\/","url_meta":{"origin":7369,"position":1},"title":"SMS alerts for new email via Twitter","author":"Leonid Mamchenkov","date":"March 23, 2007","format":false,"excerpt":"As I have mentioned previously, Twitter has many uses. Today, I used it to implement a quick and simple solution for SMS alerts. A certain someone (a client of ours) wanted to receive an SMS message on his phone every time an email arrives to his mailbox. Sounds simple, right?\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":36277,"url":"https:\/\/mamchenkov.net\/wordpress\/2019\/02\/26\/cyprus-tax-calculator\/","url_meta":{"origin":7369,"position":2},"title":"Cyprus Tax Calculator","author":"Leonid Mamchenkov","date":"February 26, 2019","format":false,"excerpt":"Cyprus Tax Calculator is probably the best implementation of the tax calculator that I've seen around. It's dead simple to use, and allows all kinds of calculations - monthly or annually, with or without 13th salary, and reporting overalls, income tax, social insurance deductions, as well as providing tax breakdowns.\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2019\/02\/cyprus-tax-calculator.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2019\/02\/cyprus-tax-calculator.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2019\/02\/cyprus-tax-calculator.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2019\/02\/cyprus-tax-calculator.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2019\/02\/cyprus-tax-calculator.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":9491,"url":"https:\/\/mamchenkov.net\/wordpress\/2005\/09\/24\/new-color-scheme-for-vim\/","url_meta":{"origin":7369,"position":3},"title":"New color  scheme for Vim","author":"Leonid Mamchenkov","date":"September 24, 2005","format":false,"excerpt":"I've been using dante color scheme for Vim for as long as I can remember. It's a nice one and suits me perfectly. Sometime though I feel that need for a change and than I have to go through a rather painful process of getting something new. This time I\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27639,"url":"https:\/\/mamchenkov.net\/wordpress\/2017\/05\/29\/house-affordability-calculator\/","url_meta":{"origin":7369,"position":4},"title":"House Affordability Calculator","author":"Leonid Mamchenkov","date":"May 29, 2017","format":false,"excerpt":"Zyprus.com has this nice Affordability Calculator, which, given a few basic numbers, helps one estimate the price of the house that will comfortably fit into the budget (yeah, those are the words they use). \u00a0It's a nice tool for people who have been saving up to buy a property. \u00a0For\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2017\/05\/house-price-500x242.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":29013,"url":"https:\/\/mamchenkov.net\/wordpress\/2018\/11\/23\/archiving-web-sites\/","url_meta":{"origin":7369,"position":5},"title":"Archiving web sites","author":"Leonid Mamchenkov","date":"November 23, 2018","format":false,"excerpt":"LWN runs an interesting article, covering different ways of archiving a website.\u00a0 It sounds trivial, but it's not.\u00a0 Even the simplest of ways - wget - will probably take you a few dozen attempts to figure out the following: There a few other interesting tools (like pywb) mentioned.","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/7369","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/comments?post=7369"}],"version-history":[{"count":0,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/7369\/revisions"}],"wp:attachment":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/media?parent=7369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/categories?post=7369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/tags?post=7369"},{"taxonomy":"keyring_services","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/keyring_services?post=7369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}