The ‘Techie Code’ for Business Leaders

Simplified TechSpeak for the Technically Befuddled

Thanks for reading my book. I hope it brought real value to you – and helped you recognize opportunities / gaps where your business can evolve & grow. This page is a list of credits and references for the book.

Google’s research about the digital experience in shops
https://www.thinkwithgoogle.com/consumer-insights/how-digital-connects-shoppers-to-local-stores/

Why a website is needed
http://www.serviceonemarketing.com/why-do-i-need-a-website/

My research on ‘Technology utilization patterns and business growth in Small/Medium Enterprises’ at Cornell University’s arXiv
https://arxiv.org/abs/1808.03956

Chaitanya Dhareshwar, 2018 June – Technology utilization patterns and business growth in Small/Medium Enterprises

Identifying what’s crap in your BLOATED PHP site and what’s not

  1. Register a shutdown function ref: http://php.net/manual/en/function.register-shutdown-function.php
  2. Call “get_included_files”
    ref: http://php.net/manual/en/function.get-included-files.php
  3. Save the returned file list to a log somewhere on your server.

This shouldn’t affect the response times – but be warned, it WILL generate higher disk I/O (which might in turn bottleneck at peak usage times).

Don’t let the size of the log file go up too much. Ensure crons/schedulers or any background processes use this shutdown function.

 

<?php
function shutdown()
{
 $xyzzy="";
 $included_files = get_included_files();
 foreach ($included_files as $filename) {
 $xyzzy .= "$filename\n";
 }
 file_put_contents($_SERVER['DOCUMENT_ROOT']."/shutdownlogger/incfiles.txt", $xyzzy, FILE_APPEND );
}

register_shutdown_function('shutdown');
?>

Blocking countries that you wish to exclude

A long time back, we found that none of our products and services are applicable to the Chinese and Korean market. However my mail servers continued to get a lot of spam from these sources – which was weird!

At some point I came across Okean (www.okean.com)  and started using their list to prevent access from such sources. I find it works great; and here’s the NETSH command used to perform the block on a windows box:

netsh advfirewall firewall add rule name="IP Block" dir=in interface=any action=block remoteip=x.x.x.x/32

server-to-server-transfer-notes

Transferring servers

  • Compress all unused / extra-low-usage stuff and ship it out first
  • DNS

Bulk transfer is the best way to do this.

  1. Use DNSCMD to bulk list all zones
  2. Allow them to transfer to a secondary
    dnscmd . /ZoneResetSecondaries testing.com /NonSecure
  3. Add them to the new server as secondary
    dnscmd . /ZoneAdd testing.com /Secondary (old-server-IP) /file testing.com.dns
  4. Give them 48 hours to sync correctly, optionally expand each zone and confirm that it’s actually synced
  5. Convert to primary
    dnscmd . /zoneresettype testing.com /primary /file testing.com.dns
  6. use this VBS script to ensure all the records are converted
    1.1.1.1 = old IP, 2.2.2.2 = new IP

    ---
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & _
    "\root\MicrosoftDNS")
    
    Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_AType")
    
    For Each objItem in colItems
    If objItem.RecordData = "1.1.1.1" then
    dim zone
    zone = objItem.ContainerName
    dim rr 
    rr = Replace(objItem.OwnerName,"." & objItem.ContainerName,"")
    if rr=zone then
     rr=zone & "."
    end if 
    Wscript.Echo "dnscmd /recorddelete " & zone & " " & rr & " A /F "
    Wscript.Echo "dnscmd /recordadd " & zone & " " & rr & " A 2.2.2.2 "
    Wscript.Echo
    End If 
    Next
    -----
  • IIS

Use the IIS bulk transfer tool. This moves everything including SSLs and whatnot – but it does not move dependencies. You will need to ensure dependencies are installed using Web Platform installer else you won’t have a track record of what’s there & what’s not.

BUT it does not work for > 4GB sizes. Batch transfers get tricky as the new transfer may negatively impact the past imports…

  1. Use the Server > Management > Shared Configuration  option to export the config only
  2. Transfer the files by hand
  3. On the new box, use Server > Management > Shared Configuration to import the config.
  4. Note: Username/password relates to folder security and NOT the file encryption password.
  5. Install PHP as per your preference – I use 5.3.9 MSI installer for convenience. DO NOT select “ALL extensions” – keep it default and add more as you NEED to. Some of them malfunction causing whole PHP framework to crash.
  6. Be sure to install all the VC++ libraries needed by PHP. This is very confusing and I chose to install ALL varieties (x86 AND x64, VC9, VC11, VC15) and then it worked smoothly. Doesnt take long to install though.
  7. ASP.NET – is uber smooth. Grab it through Web Platform installer and its a zero effort setup.

Anonymous logins cause a lot more trouble than it’s worth. Use this script to fix the issue permanently:

Dim Siteobj
Dim Site
Dim SiteName
Dim SiteId

Set SiteObj = GetObject("IIS://localhost/W3SVC")

for each Site in Siteobj
 
 If Site.keytype="IIsWebServer" Then 
 if Site.AnonymousUserName<>"" then
 
 WScript.Echo Site.ServerComment
 WScript.Echo Site.AuthAnonymous

Site.AnonymousUserName="" 
Site.setInfo

end if 
 End if 
Next

Beware: If you do the bulk transfer without taking care of dependencies, you WILL corrupt your IIS install. It’s harder to fix after that…

  • Database

Be sure to install database and ODBC drivers – the new ACE oledb driver (ref: http://stackoverflow.com/questions/6649363/microsoft-ace-oledb-12-0-provider-is-not-registered-on-the-local-machine) won’t work unless you install these 4 links
http://www.microsoft.com/en-us/download/details.aspx?id=23734
http://www.microsoft.com/en-us/download/details.aspx?id=13255
http://www.microsoft.com/en-us/download/details.aspx?id=39358
http://www.microsoft.com/en-us/download/details.aspx?id=50040
(I chose the 32bit version, which means in IIS application pool you’ll need to enable 32-bit execution)

Make backups “BAK” of all SQL databases and immediately thereafter delete the database / stop the server. This way the transfer state will remain consistent.

Refer to http://solutioncenter.apexsql.com/transfer-sql-logins-for-users-with-a-large-number-of-sql-authenticated-logins/ to ensure you know how to get the users list across. This article is superb for ready-to-use code too: https://support.microsoft.com/en-gb/kb/918992

Finally use this script: https://msdn.microsoft.com/en-in/library/ms187858.aspx

For MySQL:

  • do a full script export and stop the server

    mysqldump –all-databases -u root -p > mysql.txt

  • do an import on the new server

    mysql -u root -p < mysql.txt

For MongoDB: its SUPER EASY! I so love this.

  • do a mongodump and stop the server
  • mongorestore on the new server – voila! Instant running.

 

New found love for Fantasy Cricket

I’ve always hated cricket. No seriously – I lost matches and had such a poor experience playing cricket that I genuinely hated cricket all through school and college. However I could never understand the passion when people watch a match, or play a match themselves… So I thought I should at least make an honest effort to figure this out. I mean cricket IS the most popular game in India after all 🙂

The game itself is no biggie – standard 11 players per team, little leagues, big leagues, ODIs and Tests and so much more… But that’s the usual stuff. What really grabbed me was the Fantasy Cricket thing. It sounded like betting, and it sounded like gambling – but as I dug deeper I found that, per a court directive, cricket betting requires such great skill in selection of players that it’s actually qualified as a game of skill!

The annual market for cricket betting is estimated as USD 11 billion across the globe. This is from relatively recent news mentions on this topic (and the fact remains that some part of this is not conducted legally so I’ll just leave that piece out). The clean income from fantasy cricket is expected to exceed USD 2 billion this year. I wanted to get into the game and make my own millions (maybe not billions; but 1/1000th of that is still pretty good right?) so I started researching this angle.

What I found is this:

  • A fantasy cricket user chooses their 11 players from the squad for a given match.
  • When the real live game commences, your game is on the move as well.
  • For each run scored, wicket taken, the players you’ve chosen will earn you points!
  • Now obviously you need a serious level of skill to recognize which player will do well; thus you’re not betting on the game; you’re counting on your own incredible cricket skill.
  • Finally when all the points are pulled together, you may win various prizes based on the outcome
  • People earn as much as 7000-13000 from a single game!!

BUT – the website that runs the fantasy cricket tournament earns even more. So I got to thinking, maybe I need to create a “fantasy cricket” website instead. Now my programming skill may not be enough; but I’ve learned a lot about the fantasy cricket api and data sources in the process:

  • Cricinfo and the other sites are quite useless – I can get some data from them but I never get accurate player-wise scoring data to use for my game.
  • There are API providers who can be very expensive when it comes to fantasy API
  • The best API I could get at a really cheap rate (and 1000 hits free on signup) was the one from www.cricapi.com – and I was instantly a fan of their really cool Fantasy API! Which is why I’m endorsing them here.
  • You need to be careful how often you want to get the API data; manage expectations upfront. Tell users they will get their score updates every 10 minutes or whatever – don’t overload your servers to give a second-to-second update.
  • Once your have your data, you want to calculate the outcome of each match and store it in a database
  • Then when the match is over, or preferably the day AFTER the match is over, compare the data in your database and announce the winners!

So this is a bit of simple math. If I take Rs 100 from each player for a reward of Rs 2000 to the winner, and I get 30 people to play the fantasy cricket (which is easy enough for me to get) – I get to keep a cool Rs 1000 per match. Now that’s good money specially during the major tournaments! Also based on the logic I make I can calculate winners for each Innings of the match, and maybe make even more moolah.

Naturally I’m looking for great people who can help me program this and share the profits; but mainly I’m putting this up because I feel it’s a great way to earn, and it’s totally non-competitive. You can run it in your local clubs etc which will never impact me negatively; I may run it in my friends circle which will never impact you negatively. It’s a win-win-win!!

If you’re a great coder who wants to work with me on this contact me on chaitanyabd@gmail.com – but if you’re trying to make your own fantasy site you can drop me a line as well and I’ll try to help you out where I can.

Bacchas today and how we fret about it

Was in the train today, when the kid standing at the door was ABOUT to fall. I managed to grab his bag and pulled him in. The kid of course was grateful etc.

So I asked him

Me: Are you trying to prove a point standing on the footboard?
Kid: No

Me: Fighting cancer or something?
Kid: No

Me: Making a case for the downtrodden or the poor or the drought struck?
Kid: No. I didn’t know there was a drought

Me: Do you have parents or siblings?
Kid: Yes mom & dad work at (some bank) and 2 brothers in college

On hearing this, I totally lost it.

Me: THEN WHAT THE FUCK ARE YOU STANDING AT THE DOOR FOR?
Kid: College ke liye late ho raha tha

Me: AND WHAT YOUR 5 MINUTES LATE OR 1 PERIOD LATE IN COLLEGE IS MORE IMPORTANT THAN YOUR LIFE??? STUPID KID!
Kid: 🙁 sorry sir

Some passers by mumbled about how today’s generation / millenials have no value for their own life – but anyways maybe 25-30 years later he’ll take the opportunity to screech at some other stupid kid… maybe make a difference that way.

I didn’t note the kid’s details. Didn’t even ask his name. This was 11th of April 2016 around 8:50 AM.

Call to a member function getIsGlobal() on a non-object

We came across this while using the Advanced Dataflow profiles in Magento

 

PHP Fatal error:  Call to a member function getIsGlobal() on a non-object in /var/www/html/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php on line 173

 

Finally narrowed it down to a missing column in the CSV sheet!! Hope this helps you if you’re having the same issue. Was 8-9 hours hard effort to figure out what broke and then it came down to a silly error 🙁

Magento API giving issues with Unicommerce integration

I found out I needed to add this in app/code/core/Mage/Api/etc/config.xml

under “adminhtml”

 <routers>
 <api>
 <use>standard</use>
 <args>
 <module>Mage_Api</module>
 <frontName>api</frontName>
 </args>
 </api>
 </routers>

 

Also need to turn off Auto-redirect to Base Url in System > Web > Url Options.

 

After this you can change the Admin URL to absolutely anything and it’ll work correctly in Unicommerce 🙂

Research about my Internet and e-Governance research!