Author - Web Developer - Educator
Found 5 results for tag "python"
RSS Feed

Transistion, Business Shutdown, and Overall Updates

xkcd

Here's, the deal: the past few months have really been chaotic for me.

The first thing: As of March 4th, Shadow Dev is no more. On March 4th, I cut the 800 number, ended the insurance, and pretty much cut all ties. There's even a "goodbye" message at shadowdev.com that goes into a little more detail and the why of why it happened. Honestly, it was a good 8 years, but it was time to change directions.

Since I didn't want to say that I have been "unemployed" for the past few months (because self-employment doesn't supply unemployment insurance), I have created a sole-proprietorship freelance web development company called Q5 Industries. Don't ask about the name; Q5 was an available domain and good for a short domain (q5i.co), which really helps with short links.

So anyway, I've also finished Day of Reckoning - well, writing it, of course. It is currently going through the Editing process, which is taking a bit longer than expected, but hey - it's free. After that is finished, I will move on to Book 3: Dusk of Demise and almost be done with the series. My mother, although I'm sure it's 50% support and 50% real, likes my books, so finding how the series ends will be a surprise to us all.

I've also move some more personal "blog items" to a personal blog - kind of a "personal log". I gave it a LCARS look with more of a quick bootstrap view, and only available behind some security (I'm sure my reasons don't have to be explained).

Also, due to some role-playing gaming research, I would like to do a few things:
1) With a raspberry pi, I would like to do some hardware tinkering. I feel like I can do some testing and developing with basic LED research with a few helpful resources that I found on the internet using Python GPIO.

2) I would also like to tinker with raspberry pi and Jasper - a voice-command based system with a "dead-simple API". I thought I 'd give it a shot.

3) I've also been experimenting with some UI Framework, including UIKit, Bootstrap, Foundation (my favorite, thus far), Pure, HTML5 Boilerplate, and Skeleton. In reference, this may help with my job search with Frontend UI Design experience. (Speaking of which, I've updated my blog design to a slimmer, more responsive design, which looks pretty good)

I'm also going to be writing (and releasing) some tutorials on some HTML5, CSS3, and PHP on this blog - maybe to increase more traffic, maybe to show off some of the new techniques that I had learned (such as CSS3's vw property, which I thought was pretty cool)

Meanwhile, Java has taken a bit of a backseat while I get the rest of this chaos under control.


Tags:#nightblade #python #ui #raspberrypi #frameworks

RSS Feed

HTML5 Canvas - Bouncing Ball Example

At this point, I'm trying to stay up with HTML5 programming, and I feel like I'm a little behind the times.

So, because I'm in a Python class (via Coursera by Rice University) learning about interactive programming (more specifically, "Pong" was this week's project) and seeing Google's anniversary edition of Breakout, I felt inspired to learn how innovative HTML5 could be, so I looked up some HTML5 references and thought I'd try my hand at it.

Well, I combined by Python experiences and some HTML5 canvas examples and created some ball-bouncing joy. Want a demo? Here's a demo!

Here's a screenshot of it:
Bouncing Ball
I've taken out the clear() function to show it in motion


Even though this is very simple (as compared to some more advanced HTML5 stuff), I thought I'd go ahead and put this here for others to view/use/learn from.

Here's the HTML:
 
<!DOCTYPE html>
 
<html>
 
	<head>
 
		<meta charset='utf-8'/>
 
		<title>Ball Canvas Test</title>
 
		<link href='main.css' rel='stylesheet'/>
 
		<!--[if lt IE 9]>
 
			<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
 
		<![endif]-->
 
		<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js'></script>
 
		<script src='main.js'></script>
 
	</head>
 

 
	<body>
 
		<div id='debug'></div>
 
		<div id='container'>
 
			<canvas id='scene'></canvas>
 
		</div>
 

 
		<footer>
 
			© 2013 - Kyle Perkins
 
		</footer>
 
	</body>
 
</html>
 


Here's the CSS: (this uses a standard Reset CSS, started by Eric Meyers)
 
@import url("//dev.shadowdev.com/reset.css");
 
html, body{
 
	display: block;
 
	text-align: center;
 
}
 
#debug{
 
	position: absolute;
 
	top: 50px;
 
	right: 50px;
 
}
 
canvas{
 
	margin: auto;
 
	display: block;
 
	border: 5px #000 solid;
 
	background-color: #efefef;
 
}
 


And here's the fancy-smancy Javascript:
var canvas, ctx;
 
var circles = [];
 
var circleCount = 4; 
 
var velocity_set = 2;
 

 
function oneorzero(num){
 
	// simple function to randomly get 0 or 1
 
	if (Math.round(Math.random())==1) num *= -1;
 
	return num;}
 

 
function Circle(x,y,radius, color){
 
	// get the information stored for eac ball
 
	this.x = x;
 
	this.y = y;
 
	this.radius = radius;
 
	this.color = color;
 
	var V1 = oneorzero(velocity_set);
 
	var V2 = oneorzero(velocity_set);
 
	// velocity is set as an array so we can have the [x,y] values
 
	// [5,5] means ^,>
 
	// [-5, -5] means V,<
 
	this.velocity = new Array(V1, V2);
 
}
 

 
function clear(){
 
	// clear the screen (prevent "dirty canvas")
 
	ctx.clearRect(0,0, ctx.canvas.width, ctx.canvas.height);
 
}
 

 
function getrand(){
 
	// function to randomly get a value between 0-255 (one value for R, G, and B each)
 
	return Math.floor((Math.random()*255)+1);
 
}
 

 
function drawCircle(ctx, x, y, radius, color) { // draw circle function
 
//	$('#debug').html("X:"+x+" Y:"+y);
 
//    ctx.fillStyle = 'rgba('+r+', '+g+', '+b+', 1.0)';
 
	ctx.beginPath();
 
	ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
 
	ctx.fillStyle = "rgb("+color+")";
 
	ctx.fill();
 
	ctx.stroke();
 
//    ctx.closePath();
 
}
 

 
function drawScene(){ //main draw function
 
	clear(); //clear the canvas
 
	// this is only for additional draw functionality (testing only)
 
/*	ctx.beginPath();
 
      ctx.arc(canvas.width/2, canvas.height/2, 70, 0, 2 * Math.PI, false);
 
      ctx.fillStyle = 'blue';
 
      ctx.fill();
 
      ctx.lineWidth = 5;
 
      ctx.strokeStyle = '#fc0';
 
      ctx.stroke();
 
*/
 
	
 
	var ball_info ="";
 
	for (var i=0; i 0)
 
		$('#debug').html(ball_info);
 
}
 

 
////////////////////////////////////////
 

 
$(function(){
 
	// call these setup properties upon load
 
	canvas = document.getElementById("scene");
 
	ctx = canvas.getContext('2d');
 

 
	// this is to make sure the canvas spreads across the screen
 
	ctx.canvas.width = window.innerWidth-10; // the canvas has a 5px border
 
	ctx.canvas.height = window.innerHeight-50; // 50 is only for the footer info
 

 
	var circleRadius = 25;
 
	var width = canvas.width;
 
	var height = canvas.height;
 

 
	for (var i = 0; i < circleCount; i++){
 
		// start at random position
 
		var x = Math.random()*(width*.9);
 
		var y = Math.random()*(height*.9);
 
		var r = getrand();
 
		var g = getrand();
 
		var b = getrand();
 
		ballColor = r+","+g+","+b;
 
		// add circle to array
 
		circles.push(new Circle(x,y,circleRadius, ballColor));
 
	}
 
	setInterval(drawScene, 1); // loop drawScene - aka: "draw handler"
 
});
 

 
function animate(ball, canvas, context) {
 
	// this is for adding (aka: "move") the ball based on the velocity increase/decrease
 
	// velocity is an array
 
        ball.x += ball.velocity[0];
 
	ball.y += ball.velocity[1];
 
	
 
        if( (ball.x > (canvas.width - ball.radius)) || (ball.x < (0 + ball.radius))) {
 
		// bounce off left or right wall
 
		ball.velocity[0] *= -1;
 
        }
 
	if ( (ball.y > (canvas.height - ball.radius)) || (ball.y < (0 + ball.radius))){
 
		// bounce off top or bottom wall
 
		ball.velocity[1] *= -1;
 
	}
 

 
	// draw the circles with on the (canvas, x position, y position, radius, color)
 
        drawCircle(ctx, ball.x, ball.y, ball.radius, ball.color);
 
      }


I hope this works for some people learning how to use HTML5 and the "velocity effect"


Tags:#html5 #css #javascript #python #tutorials

RSS Feed

Python Progress: Coin Flip

Based on a conversation I had earlier today with Keat's brother, I took another whack at Python. I've been working on learning Python for a while, but never really got the hang of it since I'm mainly a PHP guy.

Anyway, based on some tutorials I learned today, I wrote a pretty nice Python script for calculating coin flips and reporting the outcome. Some of my Python-skilled friends may laugh, but I enjoyed writing this and testing my (limited) skills.

 
#!/usr/bin/python
 
import time, random, os
 

 
#clear the screen
 
os.system('clear')
 

 
#define H and T, making them floats
 
H=T=0.0
 

 
#begin input
 

 
max_num = raw_input("How many times do you want to flip a coin? ")
 

 
if len(max_num)==0:
 
	#if no input, make 10 the default
 
	max_num = 10 
 
	print "No number specificed. Defalting to 10"
 

 
max_num = int(max_num) #convert to integer to make the calcualtions work 
 

 
#little helpful tip
 
if max_num >= 300:
 
	unit = str(round((max_num*.2)/60,2))+" minutes"
 
else:
 
	unit = str(round(max_num*.2,2))+" seconds"
 

 
print "It will take "+unit+" to complete"
 

 
#flip the "coin" max_num times
 
for x in range(0,max_num):
 
	coin = random.randrange(2)
 
	if coin == 0:
 
		print "Heads" #report
 
		H+=1 #record
 
	else:
 
		print "Tails" #report
 
		T+=1 #record
 
	time.sleep(.15) #take a small break
 

 
#simple function to calcualte the percentage and report it, 
 
# instead of having to write this out more than once
 
def report(text,side):
 
	perc = round((side/max_num)*100, 2)
 
	print text+": "+str(perc)+"%"
 

 
#debugging
 
#print "Heads: "+str(H)+" | Tails: "+str(T)
 

 
#finalize the reports
 
report("Heads", H)
 
report("Tails", T)
 

 

 
#Print the winning side
 
#print "\n"
 
if H>T:
 
	print '\033[1m'+"Heads Win!"+'\033[0m'
 
elif T>H:
 
	print '\033[1m'+"Tails Win!"+'\033[0m'
 
elif T==H:
 
	print "It's a tie!"
 


I've been trying to work on getting Python to work on the web, but my server doesn't really like WSGI or mod_python. I also tried TurboGears, but that didn't quite work as expected. I may be able to work on that better and get it incoroprated to to some Dynamic programming and offer that to clients.

Also, things may be changing at Shadow Development - could be for the worse or better. Personally, I think it will be for the better because I really enjoyed pushing my skillset and coding practices, so we'll see where it goes.


Tags:#python #php #coins #heads #tails #percent #tutorials

RSS Feed

July Progress + Christmas (List)!

It certainly seems like my posting frequency has been reduced to 1x/mth. Well, we'll see how it progresses.
Zits

Between my last post and now, here's a summary of the last month's operations:
Personal:

  • I started re-watching Voyager again (since July 1). I'm already on Season 3 Ep. 16. At this pace, I should be done with the whole series (again) by the end of the month.

  • Keat got me a new bow! It's a 45lb'er, so it takes a little more strength then the ones I've used before. My previous one was a 29#, and Keat's a 35#. I've developed some blisters and had some string-bite welts, but nothing permanent. With a little more strength training and practice, I should be able to hit the bullseye 9/10 times!

  • I went to Games and Gluttony in Canton in June. It was really fun - I learned to play some medieval games and had more than enough feast. Next event: SAAD in September!

  • Star Fleet! I'm already starting my Christmas list for this year. Here's my first item: Starfleet Uniform (pre 2370)

  • Next item: Tickets (and hotel, and airfare, and transport, and spending money) to ComiCon! I'm seeing all of the photos, videos, cosplays, merchandise, comics, etc, and it's just making me want to go even more!

  • I can't believe the last episode of Eureka airs next week. It will be missed!

  • Futurama's next season started on Wednesday at 10pm. This season has been....interesting.

  • I've taken up Python....again. Hopefully, I can stick with it this time. If Python sticks, I may try Ruby as well, if the server will support it.

  • I installed Debian on my work computer. Now it dual-boots into Win7 and Debian, although I'm using Debian more. There are only 2 differences between Win7 and Debian:
    1) I can't run Netflix. Without going into too-technical detail, Netflix uses SilverLight to play their titles. SilverLight is a MSFT product. Netflix/Microsoft has declared that SilverLight will NEVER be available for Linux (I can run it by creating a VirtualBox, but I have to install Windows on that Virtual partition in order to run anything. Apparently, I can't have the VirtualBox load the existing Windows partition because it doesn't like to work that way, and without the original installiation discs (the computer only came with a recovery partition), I can't install a 2nd copy of Windows on the VirtualBox, which means I can't run SilverLight, which means no Netflix)
    2) Windows-programs (and the Windows half of the hard drive) run SUPER SLOW whenever they are accessed. Quicken has to be run for financial records, and it runs like it is on a 256MB system instead of a 4GB. Everything else is super-fast.



Business:

  • A few tools have been created for public use: Phrase Encrypter, tinyJpg, FontTest, and GTS Homepage Tool (the last one we've had for a while, but we finally decided to release it for public use)

    And I created a Japanese Name/Word Generator. While working on Omega Noir, I needed a tool to help me create some Japanese names and words. Most of the japanese words in Omega Noir were created with this tool.

  • I've created an automated "Weekly Facebook Resource Mailer" that I call our "Web Utility" Newsletter. In short: this gathers all of the posts made on the Shadow Dev Facebook page (via RSS), puts them in a database, pulls out all of the ones from the past week (based on date comparison), makes those nice and pretty, then sends them out to everyone who wants a copy of it.

    I had a few issues with the initial concept of it, but after studying the structure of how the RSS feed was presented, but after looking at it with fresh eyes (after 24 hours), I figured out a good de-structuring method and configured the system to parse the RSS into the database. In short: it's working!

  • Today, I was invited to a grand opening of a new data center in Asheville. I invited Keat because I thought it would be a unique experience. Apparently, the experience was nowhere what we expected. Let me explain:

    Based on the original member invite that I received, my assumption was this:
    Arrive on site, see 20-30 people gathered in a small security room with some crackers and sodas, mingling for about 20 minutes, taking an extended tour of rows and rows of servers in a chilled room, seeing the backup generators, seeing the security room of a data center, following up for questions, leaving in about 1.5-2 hours

    Here's what actually happened:
    We arrived at 5:20 (10 minutes before the event "begins"), about 50 people were already there. We walked into a fairly large "lobby" (about 700 sq. ft.). I found my nametag and Keat had to write hers. Tours began at 6 and ran every 15 minutes, and we wrote our names at the top of the list.
    We found the "refreshments", which consisted of wine, beer, and water. More people gathered. After about 20 minutes, there wasn't any wiggle room in the lobby because of everyone cramming in (my assumption, 120ish). We were introduced to the "Board room" which had a large table of finger foods. We gathered some, ate, then tried to "wiggle" out. 5:45 - about 180 people, and more were pouring in. Keat and I were starting to get dizzy and a little claustrophobic.
    We gathered around the "tour table" hoping it would begin at 6 as expected. More people were coming in.
    6:05 - no tour, more people coming in. My guess - 200+. This arrangement made a sardine can look comfortable.
    6:10 - tour was about to begin. The guides looked at the list, looked around, looked at the list, looked around, said "We will only take 6 people on the tour." (I'm thinking: "6 people! That's only 1% of the people here! Come on!") The first 6 people around the table rushed to the hallway behind the guide. "1, 2, 3,4, 5, 6! Okay - that's it!" (I'm thinking: "WHAT!?! We were the first names on that list! We've been waiting ever since we got here! Why can't we.....aw, nevermind")
    Keat and I wiggled our way to the front door, threw our cups away, and drove off. So much for a tour.....

  • We had a some-what "Part 2" of the Shareholders meeting with Lockwood. Let's just say that the meeting was....more personal than business. It was good to catch up with Lockwood and Donna.

  • We had a meeting with the owner of Chimsesa (?). His product was definitely interesting, and I wish I could have helped him out, but he is looking for a Technical partner with a python background. That is one thing that I/we do not have.




That'll do it for now. My days have been merging with nights, and I'm lucky if I can recall what day it is. I'm trying to wake up at 9:30am. Let's just say that my 9:30am days are starting at about 12-1pm. So, my day consists of the following:
1pm-ish: Get up, get dressed, get to the office
1-7pm: Work on everything: programming, accounting, legal, project management, sales, secretary, janitorial, etc
7-10pm: Go home, do home-based chores (cut grass, laundry, dishwasher, clean up, cook, etc)
10ish: Dinner
11pm: more home-based chores (dishwasher, laundry, gather files, feed the cats, etc), go for a daily walk
11-1am: Get ready for the night (help with pills, tuck Keat in bed, etc)
1am - 4:30ish: work/program (while either listening to music or watching Netflix)
4:30ish - 9:30am: sleep
9:30am - 1pm: attempt to get up, sleep more
Repeat


Tags:#startrek #voyager #zits #archery #comicon #saad #sca #python #win7 #debian #netflix #silverlight #virtualbox #tools #datacenter #

RSS Feed

A Brief History of Programming

Saw this via @GeeksAreSexy - it's amazing how the Java vs PHP and Ruby duels have progress

History of Programming


Tags:#programming #java #php #ruby #javascript #fortran #cobol #basic #c #pascal #c++ #python #perl #ruby #rails