#100DaysofCode Day 9

a friend posted a sentence in Morse code, and rather than looking up a translation directly, I decided to write a script to translate it. I’m going to clean this up and post it over in my code samples when it’s prettier and has more functions, and I’m hesitant to post a rough draft of something so basic, but in the interest of accountability to myself, here’s a (functional) early version anyway, followed by the tests to ensure it works:

# morse code tranlsator

# dict of Morse code
morseCode = { "a" : ".-", "b" : "-...", "c" : "-.-.", "d" : "-..", "e" : ".",
            "f" : "..-.", "g" : "--.", "h" : "....", "i": "..", "j" : ".---",
            "k" : "-.-", "l" : ".-..", "m" : "--", "n" : "-.", "o" : "---",
            "p" : ".--.", "q" : "--.-", "r" : ".-.", "s" : "..." , "t" : "-",
            "u" : "..-", "v" : "...-", "w" : ".--", "x" : "-..-", "y" : "-.--",
            "z" : "--..", "one" : ".----", "two" : "..---", "three" : "...--",
            "four" : "....-", "five" : ".....", "six" : "-....", "seven" : "--...",
            "eight" : "---..", "nine" : "----.", "zero" : "-----", " " : " " }

# alphanum-to-morse conversion
def alphaInput(secretMsg):
    translatedWords = []
    words = secretMsg.lower().split(' ')
    for word in words:
        tempChars = []
        for c in word:
            m = morseCode.get(c)
            tempChars.append(m)
        tempWord = ' '.join(tempChars)
        translatedWords.append(tempWord)
    return '  '.join(translatedWords)

# TODO: morse-to-alphanum
# TODO: swap "dot" and "dash"
def morseInput(secretMsg):
    translatedWords = []
    morseWordList = secretMsg.split('\n')
    # Look up Morse-word line by line; one row = one word
    for word in morseWordList:
        chars = []
        chars = word.split(' ') # splits each Morse-word-row into Morse-characters
        translatedChars=[]
        for c in chars:
            chardict = { k:v for k,v in morseCode.items() if v == c }
            char = list(chardict.keys())[0]
            translatedChars.append(char)
        word = ''.join(translatedChars)
        translatedWords.append(word)
    return ' '.join(translatedWords)

# TODO: input / output (can django do this?)
# should this be in another file?
secretMsg = "... --- -- . --- -. .\n-.- -. --- .--\n-- --- .-. ... .\n-.-. --- -.. ."
# TODO: FIX THIS so it knows when to translate inputs written out as dot/dash
# the comparators with 'dot' and 'dash' don't work
if ((secretMsg[0] in '.-') or (secretMsg[0:3] == 'dot') or (secretMsg[0:4] == 'dash')):
    translated = morseInput(secretMsg)
else:
    translated = alphaInput(secretMsg)
print(translated)

and the tests:

import unittest, morse

class MorseTest(unittest.TestCase):
    def test_alpha_to_morse(self):
        self.assertEqual(morse.alphaInput('A'), '.-')
        self.assertEqual(morse.alphaInput('SOS'), '... --- ...')
        self.assertEqual(morse.alphaInput('This is a test'), '- .... .. ...  .. ...  .-  - . ... -')
        self.assertEqual(morse.alphaInput('Cats are awesome'), '-.-. .- - ...  .- .-. .  .- .-- . ... --- -- .')

    def test_morse_to_alpha(self):
        self.assertEqual(morse.morseInput('... --- ...'), 'sos')
        self.assertEqual(morse.morseInput('- .... .. ...\n.. ...\n.-\n- . ... -'), 'this is a test')
        self.assertEqual(morse.morseInput('-.-. .- - ...\n.- .-. .\n.- .-- . ... --- -- .'), 'cats are awesome')

#100 Days of Code Days 7 & 8

I finished the Django tutorial!! and read the docs.

Does it count as 100 days of code if there was more reading than coding? In MY 100 Days of Code, I say yes. It’s my 100 days to do with as I wish.

I really love Python.

#100DaysofCode Days 5 & 6

Continuing with the Django tutorial… and discovered Django Girls, too, a UK-based nonprofit.

I hadn’t yet seen SQL in classes, and it’s just so… eloquent. I like it.

class Choice(models.Model):
    question = models.ForeignKey(Question, on_delete = models.CASCADE)
    choice_text = models.CharField(max_length = 200)
    votes = models.IntegerField(default = 0)
    def __str__(self):
        return self.choice_text

#100DaysofCode Day 2

More cats… this time with pictures! I played around a little with responsive design, and a teeny bit of JavaScript.

I present to you [drumroll, please] my cats.

#100DaysofCode Day 1

Happy new year, friends. I spent most of the holiday season working on the wd4e specialization, and finished intro to CSS3, interactivity with JavaScript, and advanced styling with responsive design. My capstone begins in March.

When I first read about 100 Days of Code, I realized I needed this kind of motivation, and I’ve been focusing on developing a code-something-everyday habit… and opted not to blog about it. I want to track my progress more linearly, so I’m going to change that today, and restart the clock to Day 1.

Day 1: Finished drafting contributing.md and editing code of conduct for the Aardwolf project (PR link). I’ve been tracking my job search in using mySQL and a CRUD UI I designed myself, and I spent some time tweaking the UI for that. For privacy reasons, I’ll just share my CSS using a representative table of cats.

This exercise is a reminder that I prefer back-end to front-end work. I am colorblind and the things I find attractive, you might find hideous. My personal style leans in a simpler direction: black, white, shades of gray, which also tend to be much more accessible to a broader audience. But there’s something relaxing about playing with color pallets– kind of like coloring with a fresh box of crayons! So for this exercise, don’t judge– I don’t feel bad about it. 🙂

web design

I confess that graphic design is not my strong suit, by any stretch of the imagination. I’m much more useful behind the scenes. But web accessibility is so important to me that I needed to learn more about the front end. I’m in the middle of this Web Design for Everybody specialization. It’s been fantastic, and it’s another University of Michigan series on Coursera– I’m so impressed with the University of Michigan! So far, I have completed the HTML course (a sample of some HTML scribbles), and nearly-completed the CSS course (a sample of some CSS scribbles), and I am halfway through the JavaScript course. I have a much healthier appreciation for how much work goes into a fully functional website– and I’ve recommitted myself to making my code the most accessible as possible. Whether it’s a blog post or a full-blown app. The internet is awesome. It should be accessible to everyone who wants to access it, with no exceptions.

I am excited to say I’ll be helping out with the Aardwolf project, a decentralized and open-source alternative to Facebook that was inspired by Mastodon, an open-source microblogging platform. I drafted Aardwolf’s Code of Conduct, and will be helping with accessibility features, as well.

winding down and ramping up

I’ve finished the Web Applications for Everyone Coursera specialization! (proof!) I have really come to like Coursera’s format for learning, but I think what really made me love it (first with Python for Everybody, and now with WA4E) was Dr. Chuck’s teaching style and course materials. It was nice to feel like I was “back in school” again, but it was even better to be able to work at my own pace. I’ve surprised myself by how quickly I went through most of the material, and really grateful to have been able to spend extra time on parts I found complex or parts I really wanted to take the time to explore and enjoy. Coursera is a pass/fail program, but you do get a numerical grade for your own records: I finished WA4E with a score of 99.7 percent.

WA4E and Py4E are all open education resources and can be used and reproduced without permission. I highly recommend them. (Start with Python if you’re new, like me! Python was a great first language.)

I have been thinking about where I’d like to go next. The web applications courses were about back-end app development, and there’s a complementary specialization for web design, which is more front-end and making things pretty– and accessible. Accessibility is near and dear to me, and will forever influence my development and engineering. That may be my next step.

I think I’ll be taking a little more time to wind down and polish up some more projects to show you here (or github), and gearing up to really ramp up my involvement in some interesting open source projects… with some serious job hunting, too. But in the meantime, I think I’ll be checking out Advent of Code.

Cheers!