How to turn your Python Script into a Windows Executable (.exe)

Quick little tutorial on how to turn your python script into a real program:

  1. Install PyInstaller using pip
  2. Navigate to the directory containing your python script.
  3. Run PyInstaller
  4. Double click your newly created .exe file located in the dist subdirectory and enjoy!
$ pip install pyinstaller
# make cool python program
$ cd Desktop/PythonPlayground
$ pyinstaller --onefile cool_python_program.py
# double click cool_python_program.py in Desktop/PythonPlayground/dist directory
 

Simple Leaderboard Tutorial in PHP & JS

This blog post is brought to you by the developer of BitBudget. BitBudget is an automated budgeting app for Android and iOS which syncs with your bank account and helps you avoid overspending. If you’d like to quit living paycheck-to-paycheck and get a better handle on your finances, download it today! https://bitbudget.io

Quick little tutorial on creating a leaderboard for a PhaserJS game with PHP and a little JS =>

// Guys, we need to write a little javascript here
// to add the user's score to our database
var playerName = "nUb";
var score = points;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// document.getElementById("demo").innerHTML = this.responseText;
alert(this.responseText);
}
};
xhttp.open("POST", "add_score_to_leaderboard.php", true);
var myFormData = new FormData();
myFormData.append("playerName", playerName);
myFormData.append("score", score);
xhttp.send(myFormData);
<?php
$playerName = $_POST['playerName'];
$score = $_POST["score"];
$servername = "localhost";
$username = "shranos_admin";
$password = "letsgo";
$dbname = "shranos_db";
// Create connection
$conn = new mysqli($servername,$username,$password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: ".$conn->connect_error);
}
// $sql = "INSERT INTO leaderboard_table (username_column, highscore_column) VALUES ('aNub', 0)";
$sql = "INSERT INTO leaderboard_table (username_column, highscore_column) VALUES ('" . $playerName . "', " . $score . ")";
if ($conn->query($sql)===TRUE) {
// echo "New record created successfully";
echo "your moms score added to leaderboard, thx noob";
} else {
// echo "Error: ".$sql."<br>".$conn_error;
echo "ERROR: PC LOAD LETTER";
}
$conn->close();
?>
 

Introduction to Game Development Lesson 0: Pong

Simple Pong by Peter Kwak (Edited by Topher Pedersen)

On my way back to Dallas from Austin on Labor Day I happened to hear about this really awesome course on game development from Harvard University taught by David Malan (of CS50) and Colton Ogden. I immediately enrolled in the course via edX.org on my phone, and jumped right into lesson 0 after I arrived back in Dallas.

One of the things that I really liked about the course is that they kick things off with one of the original video games, Pong. When I first started teaching at theCoderSchool this was one of the first games I built myself to make sure I knew what I was doing when it game to programming simple 2D games in Python with my students. That first summer of teaching we actually used an extremely slimmed down ~100 line version of the game one of my coworkers Peter Kwak wrote for our summer camp.

Fast forward a few hours though, and I’ve quickly fallen out of love with Malan & Ogden’s course. While the Lua programming language and Love2D game engine seem really promising, their code examples haven’t been updated in two years, and include bugs that prevent them from running. While I was able to find a bug fix that someone posted in the YouTube comments for the course lecture, I realized that the 100 line program that Peter wrote is actually a lot better for teaching purposes than the one used in the Harvard CS50 Game Development Course on edX. So…

I busted out Peter Kwak’s old code, and modified it a little bit so I can run it using real Python instead of the trinket.io web based stuff we were using at camp. I imagine I will probably need to make a lot of tweaks to this code, however, I’m tossing two of my 10 year old students into the deep end of the pool tomorrow with Lesson 0: Pong =>

# Copyright (c) 2018 Peter Kwak (Edited by Chris Pedersen)
# This is free and unencumbered software released into the public domain.
# For more information, please refer to <http://unlicense.org/>
import turtle
# Create Game Window
screen = turtle.Screen()
# screen.setup(500, 400)
screen.screensize(500, 500, "black")
screen.bgcolor("black")
# screen.addshape("Paddle.jpg")
# Create Ping Pong Ball
ball = turtle.Turtle()
ball.penup()
ball.speed(0)
ball.shape("circle")
ball.color("white")
# Create Left Ping Pong Paddle
paddle1 = turtle.Turtle()
paddle1.penup()
paddle1.speed(0)
paddle1.setx(-200)
paddle1.shape("square")
paddle1.shapesize(4.5, 1, 0)
paddle1.fillcolor("white")
# Create Right Ping Pong Paddle
paddle2 = turtle.Turtle()
paddle2.penup()
paddle2.speed(0)
paddle2.setx(200)
paddle2.shape("square")
paddle2.shapesize(4.5, 1, 0)
paddle2.fillcolor("white")
# Create Scoreboard
scoreWriter = turtle.Turtle()
scoreWriter.penup()
scoreWriter.speed(0)
scoreWriter.hideturtle()
scoreWriter.color("white")
# Set Ball Trajectory
rise = 3
run = 3
# Set Score
score1 = 0
score2 = 0
# Create Function Which Will Move Player 1's Paddle Up
def up1():
paddle1.sety(paddle1.ycor() + 50)
# Create Function Which Will Move Player 1's Paddle Down
def down1():
paddle1.sety(paddle1.ycor() - 50)
# Create Function Which Will Move Player 2's Paddle Up
def up2():
paddle2.sety(paddle2.ycor() + 50)
# Create Function Which Will Move Player 2's Paddle Down
def down2():
paddle2.sety(paddle2.ycor() - 50)
# Create Function To Update Scoreboard
def updateScoreboard():
global scoreWriter
global score1
global score2
global ball
scoreWriter.clear()
myFont = ("Arial", 40, "bold")
scoreWriter.goto(-100, 150)
scoreWriter.write(score1, font=myFont)
scoreWriter.goto(100, 150)
scoreWriter.write(score2, font=myFont)
ball.goto(0, 0)
# Set Event Listeners
# These event listeners will listen for button presses (up, down, etc.)
screen.onkey(up1, "w")
screen.onkey(down1, "s")
screen.onkey(up2, "Up")
screen.onkey(down2, "Down")
screen.listen()
# Create Main Game Loop (Simulates Time, Keeps Game Running)
while True:
# Move Ball
ball.goto(ball.xcor() + run, ball.ycor() + rise)
# Detect Top or Bottom Boundary Strike
# (Reverses the Ball's Direction of Travel)
if ball.ycor() > 200 or ball.ycor() < -200:
rise = -rise
# Detect Paddle Strike (Player 1)
# (Also Reverses the Ball's Direction of Travel)
if abs(paddle1.xcor() - ball.xcor()) < 15:
if abs(paddle1.ycor() - ball.ycor()) < 50:
run = -run
# Detect Paddle Strike (Player 2)
# (Also Reverses the Ball's Direction of Travel)
if abs(paddle2.xcor() - ball.xcor()) < 15:
if abs(paddle2.ycor() - ball.ycor()) < 50:
run = -run
# Detect When A Player Scores a Point
if ball.xcor() > 250:
# Increment player1's score by 1 point when his ball
# travels past the paddle of his opponent, player 2.
score1 = score1 + 1
updateScoreboard()
ball.goto(0, 0)
elif ball.xcor() < -250:
# Increment player2's score by 1 point when his ball
# travels past the paddle of his opponent, player 1.
score2 = score2 + 1
updateScoreboard()
ball.goto(0, 0)
# Christine, My Super Sweet AI Goes HERE...
if ball.ycor() > paddle2.ycor() + 25:
paddle2.sety(paddle2.ycor() + 15)
elif ball.ycor() < paddle2.ycor() - 25:
paddle2.sety(paddle2.ycor() - 15)
view raw pong.py hosted with ❤ by GitHub
 

MoneyPhone, the First Official Sponsor of BudgetMealPlanner.com

This blog post is brought to you by the developer of BitBudget. BitBudget is an automated budgeting app for Android and iOS which syncs with your bank account and helps you avoid overspending. If you’d like to quit living paycheck-to-paycheck and get a better handle on your finances, download it today! https://bitbudget.io

A few weeks ago I decided to give Gabriel Weinberg’s book, Traction, a second read. Long story short: Weinberg suggests trying many many different marketing channels when launching a startup. Shortly after picking the book back up I heard about a blog that I was particularly interested in sponsoring on the Indie Hackers Podcast called BudgetMealPlanner.com.

If you haven’t heard of it, BudgetMealPlanner.com is a blog with recipes or meal plans for eating on $5 a day! Pretty neat right? Personally I try to stay under $6 per meal, but BudgetMealPlanner is all about $5 for the whole day, which I think is really incredible and definitely falls into the same sort of category as my app, Frugal Living, Minimalism, Etc.

So without further ado, my first email marketing campaign =>

 

Smart Dumbbells

This blog post is brought to you by the developer of BitBudget. BitBudget is an automated budgeting app for Android and iOS which syncs with your bank account and helps you avoid overspending. If you’d like to quit living paycheck-to-paycheck and get a better handle on your finances, download it today! https://bitbudget.io

A friend of mine and I have been bouncing this idea around about trying to see if we can build a pair of smart dumbbells. The idea is: Strava for Weight Lifting. Anyway, I happened to stumble upon this cool blog post about such a dumbbell built a hackathon in 24 hours, and wanted to bookmark it here for future reference => Arduino Integrated Dumbbell — The dumbbell that’s not dumb! Rep counting has never been easier!

 

RIP Peter Fonda

” I never wanted to be anybody else.” ⁠— Captain America

 

/* TODO: Learn How to Create Multiplayer Online Games with Phaser, Node, Express, & Socket.IO */

This blog post is brought to you by the developer of BitBudget. BitBudget is an automated budgeting app for Android and iOS which syncs with your bank account and helps you avoid overspending. If you’d like to quit living paycheck-to-paycheck and get a better handle on your finances, download it today! https://bitbudget.io

This Saturday at work I happen to be taking on a new student at the school where I teach. He’s really advanced so I wasn’t sure exactly what to plan ahead of time for our lesson. But now I think I have a good idea. This Saturday we’re going to learn how to create online multiplayer games:

UPDATE (8/17/2019): A few notes on Unet Deprecation. My new student has told me a little bit about Unet in the past, but it looks like it’s being completely overhauled, so maybe it’s okay if we play around with some other options for the day.

UPDATE (8/17/2019): And a few more notes on the client-server model from the Unreal Engine documentation.

UPDATE (8/17/2019): // TODO NEXT WEEK:

  1. How To Install Express, a Node.js Framework, and Set Up Socket.io on a VPS
  2. DEVELOPER’S GUIDE TO UNITY3D MMO WITH NODE.JS USING SOCKET.IO

UPDATE (8/23/2019): Do not attempt to complete the above tutorials using repl.it. While repl.it does have a pretty nice Express/Node.js setup, I have had trouble trying to install socket.io using the package.json file. For tomorrow’s lesson, make sure to use a real server where we will be able to easily install socket.io using npm on the command line.

UNFORTUNATE DEVELOPMENT (8/23/2019): It looks like setting up an ExpressJS app to run on a live production server is painful. Most of the time I usually just roll with PHP which is extremely easy to get up and running in a production environment as the infrastructure-as-a-service providers such as DigitalOcean have pre-configured server images that you can use. But with other languages and web frameworks I’ve noticed you usually have to set everything up yourself. So my game plan for tomorrow’s lesson is going to be simply following along with the standard ExpressJS tutorials to get a development server setup on a local machine, in our case, a Mac Mini. Then we can use something like NGROK to expose our development server to the rest of the world wide web. However, I’m going to want to make sure I let my student know that we can get a live production server setup as well, but that it is going to take a bit more time as getting NGINX and all that stuff setup correctly will probably take a bit more research on my part.

 

Make Bold Claims

Stumbled upon this really great promoted Tweet today that I liked enough to click on (and bookmark), and wanted to make sure I wrote a little blurb about here on the blog for future reference:

The thing that stood out to me the most about this tweet was the claim of being “the world’s largest icon libary.” At first I think I sort of just took the author of the tweet’s word for it, but being a “promoted” tweet I then sort of realized that the advertiser was likely just making this claim up regardless of how accurate it may or may not be. However, Vincent appears to operate a fine icon library, which I may go ahead and use in my app here in the near future. But most importantly, I’m definitely going to steal Vince’s marketing strategy of making bold unverified claims about my product. Thanks for the hot tip Vinny!

 

Search Everywhere

A while back I created my own “search engine” called BuckBuckMoose. It was a one night project that simply redirects search queries to both Google and DuckDuckGo so that users can “search DuckDuckGo without fear of missing out on Google.” I built this tool to scratch my own itch. As an IndieHacker I like to support the little guy, DuckDuckGo, but I’ve found that I don’t search as often as I’d like because of my “fear of missing out on Google.”

The tool worked really great for awhile, but it’s pretty janky as the search results are launched in two new browser windows which I’ve come to find quite annoying. I programmed the tool at the time to work this way because well… it was the only way I could get it to work. However, I think I’ve found a better way: Googlespider

Tonight I’ve been playing around with scraping Google using Python and BeautifulSoup along with a couple of other libraries. However, Luke Maxwell at Hyperion Gray has released a neat Python library called Googlespider which apparently makes all of this a lot easier, so I think I want to give it a try.

A really good friend of mine once checked out BuckBuckMoose and thought it was pretty cool if I remember correctly. She exclaimed something along the lines of, “search everywhere!” So I think that’s what I’m going to call this thing going forward, SearchEverywhere.

 

Hi my name is Topher…

and I’m addicted to registering domain names on GoDaddy.