Posts

Happy Numbers

Happy Numbers Problem Problem: We'll say that for a positive whole number n, the squareSum of n is the sum of the squares of the digits of n. So if n is 1406, then squareSum(n) is 1^(2) + 4^(2) + 0^(2) + 6^(2) = 1 + 16 + 0 + 36 = 53. We further say that the k^(th)-squareSum of n is squareSum(squareSum(...(squareSum(n)))), where squareSum is composed k-many times. For example, the 3rdsquareSum of 1406 is squareSum(squareSum(squareSum(1406))) = squareSum(squareSum(53)) (as we know from above) = squareSum(5^(2) + 3^(2)) = squareSum(25 + 9) = squareSum(34) = 3^(2) + 4^(2) = 9 + 16 = 25. Definition: A number n is happy if for some positive integer m, the m^(th)-squareSum of n is equal to 1. Problem: Find the first N happy numbers for any given positive integer N. Aspects that made this problem interesting: Let the squareSum be the sum of the squares of a numbers digits. Then squareSum(number1) = squareSum(number2) if number1 is a permutation of the digits of numb

Complete SQLite IMDb Database with Python

Create IMDb Database with Python Our goal now is to automate the process of downloading the IMDb data and creating an optimized SQLite database with it. Below are the SQLite statements to create the tables, additional columns, and indices: create_Title = ("CREATE TABLE IF NOT EXISTS Title (" "tconst TEXT PRIMARY KEY, " "title_type TEXT, " "primary_title TEXT, " "original_title TEXT, " "is_adult INTEGER, " "start_year INTEGER, " "end_year INTEGER, " "runtime_minutes INTEGER, " "genres TEXT);") create_Name = ("CREATE TABLE IF NOT EXISTS Name (" "nconst TEXT PRIMARY KEY, " "primary_name TEXT, " "birth_year INTEGER, " "death_year TEXT, " "primary_profession TEXT, " "known_for_titles TEXT);") create_Crew = ("CREATE TABLE IF NOT EXISTS Crew (" "tconst TEXT PRIMARY KEY, "

Create IMDb Database with Python

Create IMDb Database with Python Making an IMDb Database with Python We will use the sqlite3 library in Python to create a database which holds the available data from the IMDb datasets. The IMDb datasets are available here . The descriptions are available here . All of these files are TSVs (tab separated value) as opposed to CSVs. Also, I will omit the file "title.akas.tsv.gz" because I find that its contents are superfluous for this project. Its columns are in the table below. Note that titleId and ordering form a composite key. Name titleId ordering title region language types attributes isOriginalTitle Description IMDb identifier for each title. (tt#######) (TEXT) Distinguishes a different translation of the title. (TEXT) Title of the translation. (TEXT) Country code. (ISO 3166-1 alpha-2) (TEXT) TBD (TEXT) TBD (TEXT)

NULL vs None in sqlite3 for Python

Null vs None in sqlite3, Python The sqlite3 library in Python accepts Python data types for data insertion. This table in the docs shows the type conversion for data when transferred between SQLite and Python. NULL vs None SQLite automatically accepts NULL (and null ) since it is a reserved keyword in. It cannot, however, be accepted as input via parameter substitution. We build a database and explain the distinctions in the following gist: dbpath = "/.../test.db" >>> import sqlite3 >>> connection = sqlite3.connect(dbpath) >>> cursor = connection.cursor() >>> cursor.execute("CREATE TABLE Test (testcolumn TEXT);") >>> cursor.execute("INSERT INTO Test VALUES(NULL);") >>> #We now have exactly one entry in our table. Verify this with SELECT: >>> cursor.execute("SELECT * FROM Test WHERE testcolumn IS NULL;") >>> for item in cursor: print(item) (Non

How to Install MongoDB (Without Brew) for Mac

Image
How to Install MongoDB (without Brew) for Mac I had previously wished I could host a MySQL database on my computer without having to run it 24/7. The commands give you more flexibility than does Excel, and Store data in a MySQL. I will cover the steps to install MongoDB (Community Edition) so that you can host a local MongoDB database and use MongoDB shell to connect to other databases. I largely followed the instructions in this video . 1. Download the MongoDB Software 1. Go to the MongoDB Download Center and click the tab for "Community Server". 2. Make sure that you are looking at Community Server for Mac. 3. Download the tgz file for MongoDB Community Server. It is probably best to save it in your home directory (usually Users/You). 2. Install the Software 1. Go to your terminal shell, change directories to wherever the downloaded file is, and unpack the downloaded file by running tar xvf mongodb-osx-x86_64-3.6.0.tgz . Note that this tutorial is n

Guide: Local Notifications in Foreground in iOS

Image
Guide: Local Notifications in Foreground in iOS In iOS 11, scheduling a notification will always result in delivery (i.e. the user sees it) as long as the user is not using the app at delivery time (and the iPhone is on). This means that either the user has the iPhone locked, is using a different app, or is on a home screen. Below are the steps to present a local notification in the foreground (i.e. while the user is in your app).