Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

Tuesday, February 05, 2019

Exercises for Programmers: 57 Challenges to Develop Your Coding Skills - Chapter 1 Part b

I don't know why this was so difficult.  I'm pretty sure that /100, *100, /100 is probably wrong anyway, it just works because the math works.  Anyway, rounding UP the pennies in the % because I'm a greedy corporate f*cker.


import math

print("Enter a tip:")
x =input()
print("Tip is: " + str(x))
print("Enter a bill/total: ")
y = input()
print("Bill is: " + str(y))

#this won't work because I need a precision factor (cents) in my ceil()
#so use full ints?
print("Tip is: " + str((y * x/100)*100)) #cents
print("Tip rounded up is: " + str(math.ceil((y * x/100)*100)))  #what do I expect?
print("Total is: " + str(y + (y * x/100)))

#with 3% and 1.85 should be 1.91
print("Total rounded up is: " + str(y + math.ceil((y * x/100)*100)/100))


Output for a good use case:
Enter a tip:
3
Tip is: 3
Enter a bill/total: 
1.85
Bill is: 1.85
Tip is: 5.55
Tip rounded up is: 6.0
Total is: 1.9055
Total rounded up is: 1.91

Monday, February 04, 2019

Exercises for Programmers: 57 Challenges to Develop Your Coding Skills - Chapter 1

Chapter 1, the most basic option for a tip calculator using Python.  No type checking and no error handling.

print("Enter a tip:")
x =input()
print("Tip is: " + str(x))
print("Enter a bill/total: ")
y = input()
print("Bill is: " + str(y))

print("Tip is: " + str(y * x/100))
print("Total is: " + str(y + (y * x/100)))


  • Step 2: round up the tip to the cent and the total to the cent.
  • Step 3: restrict the user to numbers for the bill and tip %.
  • Step 4: if the input isn't a number/%, ask them to try again or bail.
  • Step 5: no negatives
  • Step 6: use functions
  • Step 7: make it a gui (well, that's not going to happen in Python....maybe use Javascript) - use a slider, not a prompt.  Could use Visual Studio/C# as well, although that's got overhead.

Saturday, February 10, 2018

Kodu

I spent this morning at Pacer in Bloomington teaching girls how to "code" in Kodu.  It's not exactly coding; more assigning action to objects w/in the framework.  But it gets the idea across and, if you get complicated, aspects of it are pre-Unity.  The girls were great.  They all seemed to be having a great time.  We did a few other activities as well including drawing favorite video game characters and yoga.  Yes.  Yoga.  There's now a picture of me in a yoga pose (Warrior II) with the rest of my coworkers who volunteered.

Two of the girls were excited I knew about Five Nights at Freddy's and Foxy and Bonnie.  One of them drew Foxy as her character and let me take a picture.


Afterwards I went to Poor Richard's Commonhouse for breakfast/lunch.  It was not an optimal breakfast.  No choice of toast type.  Hashbrowns were patties.  Eggs over medium were a little too cooked.  Bacon was good.  I threw a Summit oatmeal stout on top of it and made it a "Guinness" breakfast.  That fixed it.  It was interesting because there were a lot of people there running some sort of Valentine's Day sexy clothing marketplace.  A woman in a red lame' dress - short - was sporting red wings  like an evil angel (fallen angel?) and wandering between the back room and front area encouraging sales.  She had to have  been at least...at least...20 years younger than the average customer.

Later the whole family went to the Uptown to see the Oscar Nominated Short Films 2018 (animated).  Garden Party with the frogs was morbid, but great.  And obviously an attempt to show off computer animation.  Amazing.  I loved Revolting Rhymes, a Roald Dahl story, about Sleeping Beauty and Little Red Riding Hood and the wolf trying to get vengeance.  We agreed that Lou, about a living Lost and Found, will probably win as a Pixar entry.  Damn cute and to the point.

And then...to make it a full day, we topped it off with the copy of Heavy Metal that arrived via Amazon.  Eryn said it was not what she expected, but she enjoyed it.  And she really enjoyed the music.  That's really all you can get/expect out of Heavy Metal if you're not in an altered state.

Friday, February 02, 2018

Twitter Bot Analysis

I was playing around with this on my free time: https://rinzewind.org/blog-en/2018/replicating-the-new-york-times-bot-twitter-analysis-with-r-and-python.html

It was a good opportunity to mess around with Twitter's API, mess around with python (including pickling and caching), and mess around with R, which I've never touched before.  I made minor changes to the code so I could include user names and poked at the other properties on the Twitter user object.

Despite it being all spelled out for me, there were some tricky bits.  pip-ing the right Twitter api instance.  I had to use twitter-python, not just twitter, so there was some installing and uninstalling to get it right.  I could have used the OAuth/REST interfaces, but I wanted to mimic the article.  In the Python, trying to add the username was a little tricky for me mapping what he dumped to the cache (dd) back against the file.  The cache made it tricky because I had to remember to go kill it if I made model changes.  R...I thought I had it all wrong because I couldn't see the ggplot graph AT ALL at first.  But it was a sample size issue.  I was using small accounts, not million-user accounts, so the alpha wasn't layering up enough to show any depth of color.  A few minor changes to shape, alpha, size, and fill and it was easily visible, although it's less useful for real bot analysis.  R was fun to play with, but does most of the heavy lifting with the tidyverse module.  It was more about knowing the general syntax of the chart than doing any coding.

plt1 <- dd="" font="" ggplot="">
geom_point(aes(x = order, y = created_at),
color = "blue", fill="green", shape=21, alpha = 1, size = 2) +
xlab(sprintf("@%s's followers", username)) + 
ylab("Join date") + 
scale_y_datetime(date_breaks = "1 year", date_labels = "%Y")

To top it off, I think I maxed out my api rate limit, although I haven't checked.  I hope I wasn't blacklisted.  The number of calls is minimal, so if you're doing even as few as 1000 users, it can get maxed out quickly.
But, it worked for a while.  Here's Klund with a pretty typical chart.  A stable line since he started with a variety of users under the line and a little bit of clumping likely related to popular tweets.



And me.  One of the devs I work with told me it looks like a dinosaur.  The clumping in the circle, though minimal, is interesting because they're new people all at once. In my case, it's not bots, but some gaming and horror movie related companies that like some of my tweets.


Sunday, February 26, 2017

Cat Doodles via Machine Learning

This is a cool idea.  It maps, in the browser, what you draw against some machine learning algorithms.  I played aroudn with the cat one to create my own letters out of cats.  Almost looks like someone skinned a cat to make the alphabet.  Yuck.  I tried my own cat below....he's sort of creepy.








Friday, February 03, 2017

Big O

A post I left elsewhere tonight.  I'm playing around with the first bits of The Python Companion to Data Science.

Hmm...my notes tell me a Python set should be approximately 15-30 times faster than a list, and Big O notation tells me I should see a more significant difference at the scale I'm using, but on lookup, it's about only twice as fast. I can't find anywhere that blames my copy of Windows for the problem, although I suspect it has something to do with that. Wait...no no. PEBKAC. I was doing the list to set conversion inside my elapsed timer. Took it outside the elapsed timer code and I'm 60x faster on the actual lookup, which is the magnitude of difference I expected to see based on O(n) and O(1). I think I just invented my next question for an intern candidate. Go back to what you're doing. I'm O(1)k now.

The code in question...

Monday, November 28, 2016

Women in Coding Article

"For girls, you cannot be what you cannot see," says Reshma Saujani...

I think this is tough, because it has to be hard to measure in less than a 10 year cycle. I wouldn't think you'd see results, or even a trend, until a new cycle of students makes it to college and the career pool. There are some sharp...extremely sharp...developers, who happen to be women, on my team, and I talk to more of them in the new grad and intern college screenings every year. Anecdotal of course. I don't keep analytics. And there is usually a strong showing both in the Python classes I teach - although coworkers might send their female offspring more often given it's a safe environment and we're predominantly tech oriented - and the Hour of Code I mentor (and there, it might be that it's semi-mandatory participation, so everyone attends).   I'm hoping by the time my daughter makes it to the career pool STEM has corrected itself (with a lot of effort from proponents and mentors) in terms of women in tech.

http://www.inc.com/jeremy-goldman/why-its-getting-harder-not-easier-to-find-women-with-computer-science-degrees.html

Tuesday, February 23, 2016

Unity Bug #2 - That was Fast (and funny)

Thought I'd be smart and fix the increasing difficulty Vector3 issue by just making the velocity of the asteroids faster and faster based on the wave count.  So I exposed the wave count on the Game Controller and accessed it via the move script where asteroids keep set their velocity based on a public property.

I forgot to account for my wave array being 0 based.  I failed to account for the fact that my shots and asteroids were tied to the same velocity/move script, meaning my bolts go faster as the asteroids go faster.  Perhaps not a bad thing, although strange.  And my ship's movement isn't tied to the same movement script, so it doesn't get faster as the rocks start to shoot down the screen at breakneck speed.


My first bug

I've got music and waves going and scoring and restart in my Unity3d game.  And then I tried to get fancy and add a value that slowly moved the waves closer and closer.  I thought I should add:

1.) waves move closer and closer or faster and faster.
2.) objects that aren't shot, but pass the player and destroyed against the boundary are negative points.
3.) each shot is potentially a negative point (because I'm a dick)
4.) a shot counter and objects destroyed to track a few stats to show at the end
5.) a ship destruction value (because I'm a dick)
6.) potentially a few lives with the ability to get more with a higher score.  I hope that rolls over and gives infinite lives because it would be old school.

So I started on #1 and moved the asteroids 5 units closer after the first wave.  Result...unshootable asteroids that, after the first wave, became ghost asteroids.  It seemed to be a float value and I was adding an int, so I modified it and tried again.  Same behavior.  So I use the range for the y value like the x value and added the number directly as an int and then a float.  Same behavior.  It's exciting to have a coding challenge, even if it's minor.

I feel like I'm coding VB COM again.  A lot of setting .Text against text objects and just sort of attaching things to each other to use them.  It would be nice if some of the students I interviewed played around with the Unity tutorials just long enough to talk through the object structure and why you have to locate the game controller rather than instantiate try to access it from every instance of a tumbling rock.  Good lessons there.

Friday, February 19, 2016

Minnedemo 22

I went to Minnedemo 22 last night at the Depot in downtown Minneapolis.  I tried to have dinner at Zen Box beforehand, but I was looking for food prior to 5:00 p.m., so it was a no go.  I ended up over at the Crooked Pint eating a peanut butter juicy lucy.  Good.  But not as good as the Blue Door (Longfellow) which, I have to say, is my favorite (and Eryn likes their wings; and it's close to guitar lessons) after Chetek, WI.  But that just might be sentiment speaking.

I will admit, I didn't stay for the whole thing.  I got downtown too early, so I was getting squirrely after a few presentations.  I watched Who's Driving, an app for coordinating car pools if you have kids in extracurricular events.  My sentiment was I'm really happy I never have to carpool and even consider using that app. I see the happy people on the app website and think, "They're so happy they're f***ing over their friends."

I watched Twistjam, which involved an Asian guitar player (does his race matter?) sitting on stage not really playing guitar for 7 minutes.  The app is cool, but Mike and Eryn told me you have to enter your own cords which is a pain in the ***.  They're playing with it to see what the limitations are.  It's a Rock Band style guitar-learning app.

Litejot.com, notable for being presented by a U of MN student.  Dude.  Come work for me.

Homi, which I shared with Charlotte because it was created by a Carleton econ alum.  She helped me interview an intern last week and right afterwards I talked to a Carleton intern candidate.  Most of the Carleton folks I've talked to are above average.  Which is strange for a college known for liberal arts skills.  But I've found a good prof or two with real world experience makes all the difference in the world.

And YouAreHear.org.  Well.  I played with that all the way to Izzy's where I had a bourbon izzy on a scoop of Zin chocolate ice cream.  The presenter was particularly funny and joked that he was the only person not to use the word monetized.  More of an art project than anything else.  But fun if you're wandering around downtown and paying enough attention that you're pretty sure you won't get mugged.

Vidcomet and Aurelius.  You're on your own.  Although Aurelius sounds particularly interesting to me as a manager, so I'll be checking it out.


Destroy the Object

I'm tempted to use Unity3d as an interview tool for intern/new grad candidates as a great example of the dangers of not getting rid of your objects.  It was cool to see it hang on to shot objects forever because they never ran into a border which would de-instantiate them. Why are interview candidates not infinitely smart compared to me when I was looking for a job?  Seriously - with tools like this, you should be able to talk for hours.  And hours.


Tuesday, February 16, 2016

Ship

I've got my ship flying around in the second Unity tutorial.  I think 20 minutes a night (really about 30+ of work) is about as much as I can manage. I'm going to declare it good progress, despite the fact that I can fly off the bottom of the screen. I fixed that - I just have to remember if I edit values while I'm in play mode, they revert.

That error message isn't for me - that's leftover Unity 4 stuff from their finalized scripts in case I get lazy.

IT Management Career Guidance

Last Friday, before the long weekend, I went over to career day at Inver Grove Hills to present to eighth graders.  I still can't tell whether they were forced to sign up, could volunteer to avoid other classes, or what the deal was.  They didn't seem particularly excited to be there.  I joked with one of the girls as one of the three rounds was getting underway that perhaps I should have used "Highly Salaried IT Manager" as my career title just to get more people to listen to me.  She gave me the obligatory he's-old-I-should-laugh-to-humor-him-so-he-doesn't-do-something-crazier laugh.



It was three twenty minute sessions and I ad hoced it rather than coming with something prepared.  I think I suffered in comparison to uniformed police, dog handlers, and EMTs.  I'm not sure how I fared compared to the therapist.  And I dressed down in jeans, a corporate t-shirt, and corporate hoodie, so hopefully I looked more relaxed than the guy in the suit and tie and dress shoes.

I talked about not starting in tech, but ending up there.  How career decisions can change but you can leverage what you'd already been learning if you're careful.  What a typical day on an agile team looks like (oh yeah...dream on).  How self-direction and continuous learning play a big part (sounding better and better, isn't it eighth graders?).  And then I talked about how my job has changed several times without much in the way of additional interviewing (more interesting).  That I've been abroad as part of my job (even more interesting).  And then my salary.  Which perked a few of them right up.  I babbled about tech a lot and talked about programming speakers (the mechanical kind) and the internet of things, content, code security and SOC 2 certifications (it always sounds more glamorous in my head than coming off the tongue), and working with different roles locally and internationally.  And, of course, people management.  The sub gave me some helpful advice after the first round and said, "They might not even know what CompSci means."  It was a good point given how much it annoys me when people assume I know their compressed words and acronyms.

My daughter's friends were in the library when I started and were jealous of my free donut and coffee.  Those might be the two people most inspired by my visit because it came with free food.  I think next time I need a fancier presentation with interactive web apps and code visualizations.  Think shinier.  Because obviously every day as an IT manager is shiny and I should trick them into an appropriate career choice.

Monday, February 15, 2016

Science ##

I was working on a new Unity tutorial today that involved multiple light sources.  I find it amazing that I can use a piece of software to just create different levels and hues of light and the physics within the application takes care of smoothing it across the object/s.  That's an amazing amount of power to wield with almost no programmatic effort (on my part).

Here's a main light, rim light, and fill light, all bouncing off my main object with varying intensities, hues, and positions.  It mostly came down to copy and paste.

It reminded me of this cover from the Science magazines my parents ordered for me when I was younger.  There was one cover where they showed several pool balls rendered by a computer.  In 1984, this was freaking magic to me.  The fact that it was difficult to even find the covers tells you how early in popular computing 1984 was.  I couldn't find the correct magazine searching on line, but Kyle tracked it down.  It's the one in the upper right corner.  But searching around for the right cover let me see all the issues that I remember.  There isn't a single issue of this magazine I didn't cherish and read and reread and there wasn't a single cover that I didn't immediately remember.  Between those and Gaming magazine, that was a huge part of my teenage reading (well, and Mack Bolin books at $0.10 each from the flea market, but that was altogether different).  That 20 discoveries that changed our lives issue I carried around with me for weeks; maybe even months.

There was one on sharks (I believe that was early on, Science 81) that had me obsessed with the critters.  As well as this one about undersea exploration from the same year that was so cool.


And this one, a larger version of one of those in the montage above, which is a beautiful cover.  There's a wikipedia article on the magazine, but it's short and no associated covers.  Probably worth fixing were I so inclined.  The article includes this sad bit, that I remember well because I hated the format of Discover compared to Science ##, "Science was purchased in 1986 by Time Inc. and folded into Discover, the last issue being July 1986. A few issues of Discover after the merger feature a stamp noting "Now including Science 86", but this quickly disappeared. This claim was somewhat suspect, however, as all of the Science staff was immediately laid off after the takeover."




Sunday, February 14, 2016

Unity 3d - First Attempt

I am exceedingly proud of being able to follow instructions. I have a board game I'd like to make...actually two or three or four or five. And between Unity and Snap SVG, maybe I can create online and paper copies. I'm not sure they'll ever be for anyone but me, but still, fun to see something I can qualify as a product instead of only in my head.

 

Friday, March 09, 2012

Poke Poke

What's that?  Ming seems to be wearing out while poking me in Facebook?  He just doesn't have the same gumption he once had?  Is it like I'm the terminator?  Merciless in my ability to poke back?  It's like I'm just sitting there waiting for him to poke me?  I wonder if that turing test/stopwatch joke makes sense now.


Saturday, August 06, 2011

Well...it's not cutting edge...

But I did manage to make the circle colors vary both with an if/else with a modulo, and in a second version using a (mutable) array of UIColor objects.  I feel a bit like I'm back in high school coding class with the Apple II and a sheet of graph paper...if you tacked on iOS memory management issues.  And I learned how to use the cmd-shift-3, cmd-shift-4, and cmd-shift-4 then space then click commands on a Mac to capture what I want.  And I learned Mac users are just as a-holish in many instances as PC developers with their "that's in the documentation, so I'm not going to answer that" and "It's Mac, not MAC. If you can't even do that right, I'm not going to answer your perfectly valid coding question."  These things were not said to me.  I just got to appreciate them in the general postings on the web.

Tuesday, March 15, 2011

Kat Hack

Boing Boing has a link to an amusing javascript game where you can dump the javascript in your url and you're playing Katamari Damacy.  Kyle couldn't get it to work, but it worked just fine in Chrome for me (although I didn't try it in IE9).

javascript:var i,s,ss=['http://kathack.com/js/kh.js','http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js'];for(i=0;i!=ss.length;i++){s=document.createElement('script');s.src=ss[i];document.body.appendChild(s);}void(0);

Sunday, March 21, 2010

Competency

My lead developer on a project couldn't attend a meeting on Friday. My lead (a project manager) couldn't attend in her stead. I said I'd be there. At which point one of the PMs on the project sent a message to me and the project team that said, and I barely paraphrase, "Are you sure you understand all the details involved in the project and can speak to our concerns?" I responded with a four point treatise that basically said, "I wouldn't have done it the way you did it in the first place, so I don't understand what you're doing or why you're doing it, but I understand the project." My lead/PM was highly amused and sent me a one word email that said, "Solid!"

The follow up meeting involved two of the PMs on the project (from the same team) voicing differences in direction in the meeting, arguing with automated testing about whether they'd take the testing tool development we'd been trying to give them all along, talking over the automated testing rep when he was trying to explain that he'd take it (instead of just saying f*ing thank you), questioning how the automated testing team wanted to implement the tool (at which point I spoke up and said, he/she who owns the tool owns the implementation. If it doesn't do what you want, then you go back to the table, but they'll understand it enough to remedy the problem at that point. Until then, tell them what you want in concrete terms and leave the details to the people with the developers), and sounding very confused when they discovered I can pull document ids at will with only 60 minutes of programming (no one ever thinks a manager knows how to use a product api). Possibly the most aggravating meeting I've been in since I started managing, and I've been in a LOT of meetings.

I miss just coding to make myself happy.