#100DaysofCode Day 12

I fully admit I’m slacking with the documenting– I’m getting so wrapped up in whatever’s caught my eye that day, that I forget to jot it down here after I jot it down in my notebook when it’s time to walk away for the day. (as an aside: all this learnin’ has reminded me how much I love to just WRITE stuff in notebooks. I retain everything a lot better if I physically write it with a pen and paper. So far I’ve gone through half a box of pens, and countless random pens, several notebooks, and my hands are TIRED.)

I’ve been working with Django more. Current project: a CATalogue of my cats. (get it? CATalogue?) I’ve created the model and the view(s) and next on my agenda is to figure out how to get image files in on this action. Because what’s the point of cataloguing my cats, if I’m not including pictures with adorable captions and descriptions?

example: models.py
from django.db import models
class CatProfile(models.Model):
cat_name = models.CharField(max_length=200)
# should change this to approximate year of birth:
cat_age = models.IntegerField("cat's age")
cat_desc = models.CharField(max_length=200)
def __str__(self):
return self.cat_name
def elderly(self):
return self.cat_age >= 10
elderly.short_description = 'Is this cat a senior?'

#100DaysofCode Day 11

I took the previous day‘s code for the Morse Translator and changed it to include list comprehension.

Through a series of unfortunate events, I had an unexpected allergic reaction two days in a row. One reaction often throws me for a loop for a day or two, requiring extra rest, but two in a row have left me feeling pretty wiped. It can take a short minute to get back in the swing of things when something like this happens (I partly blame the Benadryl hangover). This is one of life’s minor annoyances when living with chronic illness or disability. Some annoyances are bigger than others, of course. This could’ve been much worse, all things considered.

#100DaysofCode Day 10

I didn’t get too fancy with the Morse code converter… I ended up reading a whole lot of stuff about testing, though. The Hitchhiker’s Guide to Python has a great primer on code testing to start.

I really like testing.

I dropped today’s code on Github.

#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)
        tempWord = ' '.join(tempChars)
    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
        for c in chars:
            chardict = { k:v for k,v in morseCode.items() if v == c }
            char = list(chardict.keys())[0]
        word = ''.join(translatedChars)
    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)
    translated = alphaInput(secretMsg)

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. 🙂