6/15/18

Python: Picking random events for a game: developing the algrothm





This video walks though developing code to pick random events where the
events have different probabilities.



This could be used in games,
simulations, or picking random visual elements.



It will show two functional programming approaches and one Object
Oriented approach



6/11/18

Web Scrape YouTube channel for video info and a table of contents using Python 3.6 and Beautiful Soup (V1.1)


THIS TECHNIQUE NO LONGER WORKS!
I will post an update in the future with code that using the Goggle API.

I have a YouTube channel for my videos to teach programming and needed to create a nice table of contents for a web page.

YouTube always list the videos and playlists with a lot of graphics and thumbnail images which look nice, but it does not fit much on a page for reference.

I tried to use write a program using their API, but decided it was better to try 'screen scraping' or 'web scraping'. This is a technique that is used to get information out of web pages.

I ended up writing a python program. Since many sites do not like scrapping, I checked the User Terms Contract for YouTube, and it is OK as long as it is as slow as a human.

I walk through version 1.0 of the code at my YouTube video @ https://youtu.be/NvxAhUkVgHU

Also please subscribe to my YouTube channel

I wanted a program that would output a CSV file to import to a spreadsheet or DB and a HTML file providing a table of contents to all the videos on the channel that I could copy to my blog.

I decided to pull the following data for the CSV file:

  • channel name
  • section name 
  • playlist name 
  • video title
  • video link
  • video time length
  • number of views
  • publication date
  • number of likes
  • number of dislikes
  • video description


I have embedded a gist here that you can see and get the code from:








You need python 3.6 or greater and just need to change the channel name near the top of the program.
Then run it to create the CSV and HTML file in the current run directory.

If you only need the HTML, json, or CSV file, see the if __name__ == '__main__' section and write an driver py program with imports like run_json.py example.

3/15/18

One Link to find FREE images though Google Search


HOW TO FIND FREE PICTURES AND IMAGES

  Click on this image to search:

 Click on this image
              (you can bookmark it of course)


Just use this image to link to google search that already has the advanced settings for finding free images.

Once there:
  1. type in a search phrase for image
  2. click on image that you what
  3. you can then select to download one you see
  4. or click on visit to go to the original page which may have other sizes

The images you see in searh are under the following copyright license or equivalent:

    CC0 License

    ✓ Free for personal and commercial use
    ✓ No attribution required

So you are free to use it for anything including commercial use, without attribution to the original author, including modifying it.

3/13/18

Strava Global Heatmap lands Strava in Hot Water:

Strava Global Heatmap lands Strava in Hot Water:


Strava developed a online map of the world showing activity tracker of people's paths that wear the Strava devices.

It was released in November 2017.

(Strava Heatmap Site)

The map shows activity of billions of activities around the world. Unfortunately it also showed activity at sensitive locations like areas 51, the pentagon, and arms services bases overseas. This was pointed out by Nathan Ruser on Twitter (Twitter Reference)

File this one under 'Unintended Consequences of New Tech'

3/5/18

Python Class: ElapsedTime (works like a stopwatch)

 If you are learning python, short examples are always helpful. Here is one.

Class in Python: ElapsedTime:

Use:

e1 = ElapsedTime()  # starts time e1

x = e1()  # get elapsed time as float in seconds from timer

... do something more

x = e1()  # get elapsed time since start

The code shows a couple neat things in python:
  • using a object reference as a methods by defining the __call__ standard method
  • using a Unicode char in output (this is easier in python 3)

The Code:

 
"""Small elapsed time class"""
# YouTube subscribe link: https://goo.gl/ZgZrZ5
# Gerry Jenkins

import time

class ElapsedTime():
    """elapsed since creation objects"""

    def __init__(self):
                self.start = time.time()  # store only start time
        
    def __call__(self):  # used to use object name as call
        """return elapsed time in float seconds"""
        return time.time() - self.start
        
        
if __name__ == "__main__":
    # check it out, follow two elapsed timers
    
    e1 = ElapsedTime()
    for _ in range(5):  # use e1
        print(f'e1: {e1()*1000000:0.1f} µsecs') # unicode micro
        
    e2 = ElapsedTime()
    for _ in range(5):  # use both e1 and e2
        print(f'e1: {e1()*1000000:0.1f} | e2: {e2()*1000000:0.1f}')

        

OH, and please subscribe to my YouTube Channel at: youtube.com/gjenkinslbcc

And check out my Python, Data Structures and Algorithms video class

2/11/18

Great article on history of Olympic Icons from Graphic point of view

Great article for Graphic Design on the history of Olympic Games Icon design:

Drawing From The Past – Josh S. Rose – Medium A Deeper Look at PyeongChang’s Olympic Pictograms @ medium.com