Saturday, February 29, 2020

The Magic of Jupyter - via Cygwin!

And you wouldn't even know - such a breeze to install. And, when you launch, you can use the regular browser - like Chrome..

But, why are terminals unavailable?

Wednesday, February 26, 2020

Shame on Google - Can't Even Get Factorial Right..

It just gets worse..

And worser.. WT*? What are they trying to prove? A one liner has been made a freaking paragraph!

Problem : The pretty_address function separates out parts of the address string into new strings: house_number and street_name, and returns: "house number X on street named Y". The format of the input string is: numeric house number, followed by the street name which may contain numbers, but never by themselves, and could be several words long. For example, "123 Philly Ave", "1001 3rd St", or "55 North Ferst Blvd". Fill in the gaps to complete this function.

def pretty_address(address):
  # Declare variables

  # Separate the address string into parts
  words = address.split()

  # Traverse through the address parts
#  for __:
    # Determine if the address part is the
    # house number or part of the street name

  # Does anything else need to be done
  # before returning the result?
 
  # Return the formatted string 
  return "house number {} on street named {}".format(" ".join(<censored>) , words[duh!] )

print(pretty_address("456 Castler Street"))
# Should print: "house number 456 on street named Castler Street"


asdf. Another one that got my temperature up. Problem? A failure to address or play to the student's curiosity. Think about how ridiculous this is - you have two classes of clothing - shirts and pants and they're both inheriting from Clothing - so far so good. Clothing keeps track of the entire population - hence assigning to CNAME.varName rather than self.varName. Good.

But then, when you want information about the entire population - in this case, the total stock of Cotton, you go through a particular class of clothing - how ridiculous is that? Or sick?

For the current_stock = , you can use either polo or sweatpants - which shows up another QA fail - why is one singular and the other plural?

class Clothing:
  stock={ 'name': [],'material' :[], 'amount':[]}
  def __init__(self,name):
    material = ""
    self.name = name
  def add_item(self, name, material, amount):
    Clothing.stock['name'].append(self.name)
    Clothing.stock['material'].append(self.material)
    Clothing.stock['amount'].append(amount)
  def Stock_by_Material(self, material):
    count=0
    n=0
    for item in Clothing.stock['material']:
      if item == material:
        count += Clothing.stock['amount'][n]
        n+=1
    return count

class shirt(Clothing):
  material="Cotton"
class pants(Clothing):
  material="Cotton"
 
polo = shirt("Polo")
sweatpants = pants("Sweatpants")
polo.add_item(polo.name, polo.material, 4)
sweatpants.add_item(sweatpants.name, sweatpants.material, 6)
current_stock = sweatpants.Stock_by_Material("Cotton")
print(current_stock)


That's not enough.. More evidence that either Google's or Coursera's QA dept is asleep (highlighted) :

class Zoo:
    def __init__(self):
        self.current_animals = {}
   
    def add_animal(self, animal):
        self.current_animals[animal.name] = animal.category
   
    def total_of_category(self, category):
        result = 0
        for animal in self.___.values():
            if self.____ == category:
                result += 1
        return result
zoo = Zoo()
 

Tuesday, February 25, 2020

Did You K? PDF is an Open Standard! Manipulate PDFs with python - tutorial

https://realpython.com/courses/pdf-python/

pyPDF2 - that's hot stuff!
  1. Introduction
  2. pyPDF2 History, an Alternative and Installation
  3. Metadata Extraction and Rotating Pages
  4. Merging and Splitting PDFs
  5. Adding Watermarks and Encrypting PDFs
  6. Conclusion and Further Reading
Alternatives to pyPDF2 (Phasit) - pdfrw by Patrick Maupin (good with ReportLab, but no encryption).

Actually, this tutorial is members only :(

How would you add links in a PDF : https://stackoverflow.com/questions/28796832/add-links-in-pdf

But, Al Sweigart, on the advice of Alan Dershowitz, has made his Udemy companion (to the book) is free in March - just log out of Udemy, go to his website and then click on the link, and you'll see it's free.. click on buy and checkout, it's $0.

Wednesday, February 19, 2020

Python Resources - Online Interpreters and More

Who else but GOOG would know about this?

Additional Python resources

While this course will give you information about how Python works and how to write scripts in Python, you’ll likely want to find out more about specific parts of the language. Here are some great ways to help you find additional info: 
Strings :

String operations


  • len(string) Returns the length of the string
  • for character in string Iterates over each character in the string
  • if substring in string Checks whether the substring is part of the string
  • string[i] Accesses the character at index i of the string, starting at zero
  • string[i:j] Accesses the substring starting at index i, ending at index j-1. If i is omitted, it's 0 by default. If j is omitted, it's len(string) by default.

String methods

  • string.lower() / string.upper() Returns a copy of the string with all lower / upper case characters
  • string.lstrip() / string.rstrip() / string.strip() Returns a copy of the string without left / right / left or right whitespace
  • string.count(substring) Returns the number of times substring is present in the string
  • string.isnumeric() Returns True if there are only numeric characters in the string. If not, returns False.
  • string.isalpha() Returns True if there are only alphabetic characters in the string. If not, returns False.
  • string.split() / string.split(delimiter) Returns a list of substrings that were separated by whitespace / delimiter
  • string.replace(old, new) Returns a new string where all occurrences of old have been replaced by new.
  • delimiter.join(list of strings) Returns a new string with all the strings joined by the delimiter
Check out the official documentation for all available String methods.

Formatting expressions

ExprMeaningExample
{:d}integer value'{:d}'.format(10.5) → '10'
{:.2f}floating point with that many decimals'{:.2f}'.format(0.5) → '0.50'
{:.2s}string with that many characters'{:.2s}'.format('Python') → 'Py'
{:<6s}string aligned to the left that many spaces'{:<6s}'.format('Py') → 'Py    '
{:>6s}string aligned to the right that many spaces'{:<6s}'.format('Py') → '    Py'
{:^6s}string centered in that many spaces'{:<6s}'.format('Py') → '  Py '
Check out the official documentation for all available expressions.

Sunday, February 02, 2020

Cubicle in ON Semi Bangalore

Makes you wonder why anyone would ever want to work there.. Wonder what a *real* sweatshop like Broadcom has..


Saturday, February 01, 2020

Pushing Your Stuff to Github

You have files on your computer you want to send to GitHub. 

If you said you have files in your directory you want to send to GitHub, I'd say... not so fast. If you don't know what you're doing, you might lose *all* of them!

What *should* you do?

Start with an empty directory.
Then

git init
git remote add origin https://github.com/username/repoName (yes, I assume you created it on GH :)
git pull origin master  // this is the magic that now tells your local system that you're hooked up
cp /from/path/file1 .    // may be overcautious..
git add file1
git commit -m "initial"
git push origin master

If you try the git remote add origin thing without the git init..

fatal: not a git repository (or any parent up to mount point /cygdrive)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

If you do the git init and the git remote add origin and then try pushing..

To https://github....
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/...
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

CowPhImB : Avoid Death by Powerpoint

C : Use contrast to draw attention to the important parts of the slide
O : One message per slide!
W : White does not delight! Use the appropriate background for the setting - if you're outdoors, maybe white is okay :)
PhIm : Have an Image and Phrases. Don't have full sentences because people will lose cognitive bandwidth processing them - and you won't get your verbal message across.
B : The most important part of the slide should be the biggest - not necessarily the title!

https://youtu.be/Iwpi1Lm6dFo

Oh Really? How, If Drones are Supposed to Be Illegal in India?

https://yourstory.com/socialstory/2019/12/drone-scientist-karnataka-mandya-600-drones

Nitakal Marimadiah Pratap started tinkering with drones when he was only 14 years old, and two years later at 16, he had managed to develop a fully functioning drone. Even though it could fly and capture only a few images, it was no less than an achievement for the young boy, who was inspired by the might of the eagle soaring in the sky and Dr APJ Abdul Kalam, India’s top scientist and former president.

Over the course of the next few years, Pratap built 600 drones all by himself. He has so far completed six major projects that includes Telegraphy in Border Security, Drones in Traffic Management, UAVs in rescuing humans and Auto piloted drones and Cryptography in Drone Networking. Pratap’s drones are saving the lives of tribals in Africa by helping deliver medical support in a short period of time.

Invited to 87 countries.. wow.. and just a B.Sc. from JSS College of Arts, Science and Commerce, Mysore.