<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: btryon-glitterkitty</title>
    <description>The latest articles on DEV Community by btryon-glitterkitty (@btryonglitterkitty).</description>
    <link>https://dev.to/btryonglitterkitty</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1001399%2Fc679fff5-cdfe-4d3d-a440-25c0494a1279.png</url>
      <title>DEV Community: btryon-glitterkitty</title>
      <link>https://dev.to/btryonglitterkitty</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/btryonglitterkitty"/>
    <language>en</language>
    <item>
      <title>Meerkats! SQLAlchemy! Mob magic?</title>
      <dc:creator>btryon-glitterkitty</dc:creator>
      <pubDate>Sun, 23 Apr 2023 23:25:02 +0000</pubDate>
      <link>https://dev.to/btryonglitterkitty/meerkats-sqlalchemy-mob-magic-18md</link>
      <guid>https://dev.to/btryonglitterkitty/meerkats-sqlalchemy-mob-magic-18md</guid>
      <description>&lt;p&gt;-ben tryon&lt;/p&gt;

&lt;p&gt;Of all the relationships you encounter in life, the most important, by far, is the one between you and your colony.  As a meerkat, I have a responsibility to stand atop photographer's heads, tree stumps, other 'kats... it's a life to... look out for.&lt;/p&gt;

&lt;p&gt;One-to-many relationships and many-to-many relationships are pivotal to the life of a meerkat when they interact with Flask, Python (not that type!) and SQLAlchemy.  These three languages are how we had our first house and all it's tables built.&lt;/p&gt;

&lt;p&gt;A one-to-many relationship is when one item in a table is associated with multiple items in another table.  My colony can have many meerkats, multiple meerkats. A many-to-many relationship is when multiple items in one table are associated with multiple items in another table.  One meerkat can dig many tunnels in our home colony, and one colony can have multiple meerkats contributing to digging one tunnel. &lt;/p&gt;

&lt;p&gt;To represent these relationships in Flask, we can use SQLAlchemy. We can create two tables, one for colonies and one for members - these are one-to-many relationships - and use a foreign key to link the two:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///meerkats.db'
db = SQLAlchemy(app)

class Colony(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)
    tunnels = db.relationship('Tunnel', backref='colony')

class Tunnel(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    length = db.Column(db.Float, nullable=False)
    colony_id = db.Column(db.Integer, db.ForeignKey('colony.id'), nullable=False)


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two classes, 'Colony' and 'Tunnel' are defined and correspond with the tables in the database. The 'Colony' class has a 'tunnels' attribute that creates a one-to-many relationship with the 'Tunnel' class using the db.relationship() function. I also defined a foreign key 'colony_id' in the 'Tunnel' class to link it back to the 'Colony' class. It is amazing what one can do with curved claws and a propensity to watch. We, the mob, saw a researcher from NatGeo typing away on their Lenovo.  We one-upped her.  She was like 'whoa!  Meerkats! Coding in Python! And with claws-adapted keyboards!'  That was a fun day.&lt;/p&gt;

&lt;p&gt;Let's move on to many-to-many relationships. I created a third table, called a join table (they wouldn't call it a 'mob' table! Owls and their parliament, wildebeests and their confusions get all the good group names...)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Meerkat(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)
    tunnels = db.relationship('Tunnel', secondary='meerkat_tunnel', backref='meerkats')

meerkat_tunnel = db.Table('meerkat_tunnel',
    db.Column('meerkat_id', db.Integer, db.ForeignKey('meerkat.id'), primary_key=True),
    db.Column('tunnel_id', db.Integer, db.ForeignKey('tunnel.id'), primary_key=True)
)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My NEW 'Meerkat' class was created and I updated the 'Tunnel' class to use a many-to-many relationship.  These relationships are mad real for us. Without them, we'd be a bunch of house cats. I also defined a join table called 'meerkat_tunnel' that has the foreign keys to both the 'Meerkat' and 'Tunnel' tables.  This is the magic of tables - the join and the relationships allow an interplay of activity and code. The join table is the bridge to the two tables being linked - it stores the foreign keys of both tables and maps the associations of each. The defining of the foreign keys - the column of integers to identify row-embedded information for meerkat_id and tunnel_id - allowed the queen to query all the tunnels that a particular meerkat had dug or gave her the tools to find that the mob had worked on a particular tunnel. She had admonished us for laziness a few days earlier.  Little did she know, she was soon to have a midnight meeting with a hyena, not our fault she took a wrong turn!&lt;/p&gt;

&lt;p&gt;I am next on lookout, so gotta wrap it up: designing and building robust databases are dependent upon an acute understanding of one-to-many and many-to-many relationships. Our tunnels would not have been built without the planning of our python crew. It helped us visualize and scale the growth to make our colony an interconnected maze of a subterranean city. Whether you're a NatGeo researcher or a wildebeest, SQLAlchemy is a powerful tool that can help you efficiently manage your data and relationships. &lt;/p&gt;

</description>
      <category>flas</category>
      <category>back</category>
    </item>
    <item>
      <title>Python - classless hooligan?</title>
      <dc:creator>btryon-glitterkitty</dc:creator>
      <pubDate>Sat, 01 Apr 2023 04:03:11 +0000</pubDate>
      <link>https://dev.to/btryonglitterkitty/python-classless-hooligan-9be</link>
      <guid>https://dev.to/btryonglitterkitty/python-classless-hooligan-9be</guid>
      <description>&lt;p&gt;-ben tryon&lt;/p&gt;

&lt;p&gt;Python3 has been used to create maps of both the modern and ancient world navigable by sound and touch. It has been used to create a weather forecast system that scores historical forecast data with actual weather data, producing data mining of striking accuracy. And it has been used for collaborative drug discovery. One could say Python is an amazing tool of the future, even the language of the future. But that only matters if the code works. Understanding the top-level properties within python is a powerful manner of ensuring working code.&lt;br&gt;
            &lt;br&gt;
Classes are user-defined. They are blueprints waiting to be filled with data and functionality, making them and python easy to reuse and maintain.  &lt;br&gt;
For example, we define a Person class as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person:
            def __init__(self, name, age):
                        self.name = name
                        self.age = age
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;strong&gt;init&lt;/strong&gt; is a specific method that is called when an instance of class is created.&lt;br&gt;
To create an object, we first define the class, then we create an instance of the class.  We would create an instance of the Person class like so: &lt;br&gt;
 &lt;br&gt;
&lt;code&gt;person1 = Person(‘Awad’,30)&lt;/code&gt;&lt;br&gt;
 &lt;br&gt;
In this example, we created an instance of the Person class with the name “Awad” and an age of 30 years old.&lt;br&gt;
 &lt;br&gt;
Instances are objects that are created from a class. They are unique, as each may have it’s own attributes.  Attributes are variables that belong to an object and are tiny containers, used to store data. In Python3, attributes can be defined at both the instance and the class levels. A gender attribute is added to the Person class, below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person:
            def __init__(self, name, age, gender):
                        self.name = name
                        self.age = age
                        self.gender = gender
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We then can update the instance of the updated class:&lt;br&gt;
 &lt;br&gt;
&lt;code&gt;person2 = Person(“Jewel”, 25, “female”)&lt;/code&gt;&lt;br&gt;
 &lt;br&gt;
Class objects are objects that represent a class and are used to access class-level attributes and methods. Class-level attributes are shared by all instances of a class, while instance-level attributes are unique to each instance. Our Person class receives a class-level attribute, representing the total number of persons. It is then incremented:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person:
            def __init__(self, name, age, gender, count):
                        self.name = name
                        self.age = age
                        self.gender = gender
                        Person.count += 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
The count attribute can be accessed using the class object:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Print(Person.count)`
 
Method objects are objects that represent a method of a class. They can be used to access or call the method of an instance or of a class. Methods can be defined at both the instance and the class levels. 
 
In Python3, class-level methods are defined using the @classmethod decorator. A class-level method is added to our Person class to print the total number of persons:
 
class Person:
            count=0
            def __init__(self, name, age, gender, count):
                        self.name = name
                        self.age = age
                        self.gender = gender
                        Person.count += 1
            
            @classmethod
            def print_total_count(cls):
                        print(f”Total number of persons: {cls.count}”)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
Understanding the top-level properties of Class and Method with their attendant attributes and instances will help any programmer utilize the powerful Python language.&lt;/p&gt;

</description>
      <category>oop</category>
      <category>python</category>
    </item>
    <item>
      <title>The sexy expressions between the slashes</title>
      <dc:creator>btryon-glitterkitty</dc:creator>
      <pubDate>Sat, 11 Mar 2023 03:27:42 +0000</pubDate>
      <link>https://dev.to/btryonglitterkitty/the-sexy-expressions-between-the-slashes-4m94</link>
      <guid>https://dev.to/btryonglitterkitty/the-sexy-expressions-between-the-slashes-4m94</guid>
      <description>&lt;p&gt;by ben tryon &lt;br&gt;
 &lt;br&gt;
Form Validation is that part of a form or webpage that says "no, your password must have a plus, asterisk, capital letter or kitchen sink to be a valid password".  &lt;/p&gt;

&lt;p&gt;Form validation takes any form… such as validating an ISBN to search for a book.  ISBNs are either 13 or 10 alpha-numeric characters that identify a book.&lt;br&gt;
 &lt;br&gt;
When this search occurs, a few behind-the-scenes actions are taking place:&lt;br&gt;
First, the data controls of the form are taken into account.  In other words, the controls that determine the text-boxes have text, that the radio buttons are clicked, that the checkboxes are marked, etc.  &lt;br&gt;
 &lt;br&gt;
If these controls are exactly entered, this is a quick action. If incorrect, the ghost in the machine appears and everything slows down: forms are rejected by the server, travel back to the client and the process starts over. &lt;br&gt;
 &lt;br&gt;
Client-side is defined as processes within the browser. Client-side validation checks of form data determine if entered data is exactly correct within the application constrains.  If so, that data is allowed to be saved on the server and server-database when it reaches there.( That process is not part of this article scope. )&lt;br&gt;
 &lt;br&gt;
Regular expressions are the lynchpin of form validation. Why? Because “RegExp” allow code within the code to work and thus, truly power the controls process.  A regular expression literal begins with this pattern: &lt;code&gt;‘const re = /’&lt;/code&gt;as in&lt;br&gt;
 &lt;br&gt;
&lt;code&gt;const re = /ab+c/i;&lt;/code&gt;&lt;br&gt;
 &lt;br&gt;
and  between the slashes is:  /pattern/modifiers (the pattern is &lt;code&gt;ab+c&lt;/code&gt; and the modifier is &lt;code&gt;i&lt;/code&gt;)&lt;br&gt;
 &lt;br&gt;
Keeping the code between the slashes as “constant”, performance improves… if the ISBN is always the target of your backend or database search, and only the 10 values change, the other database information can be ignored, and everything is then faster:&lt;br&gt;
 &lt;br&gt;
&lt;code&gt;const re = /isbn/;&lt;/code&gt;&lt;br&gt;
 &lt;br&gt;
To enable event better performance, use a constructor: The constructor function takes either a string or a RegExp object as its first parameter and a string of optional flags as its second parameter. These flags are modifiers.&lt;br&gt;
 &lt;br&gt;
&lt;code&gt;const re = /ab+c/i    &lt;/code&gt;    //regular expression literal notation again&lt;br&gt;
&lt;code&gt;const re = new RegExp(/ab+c/, “i”)&lt;/code&gt; //a constructor with a literal notation expression&lt;br&gt;
&lt;code&gt;const re = new RegExp(“ab+c”, “i”)&lt;/code&gt; //a constructor with a string {“”} pattern as the first argument&lt;br&gt;
 &lt;br&gt;
In general, there are three RegularExpression modifiers:&lt;br&gt;
&lt;code&gt;i&lt;/code&gt; – a global case search of all words, regardless of capitalization&lt;br&gt;
&lt;code&gt;g&lt;/code&gt; – a global search to return the specific combination (either a word or phrase or number, etc)… by the way, you can combine “i and g” for a global, case insensitive search&lt;br&gt;
&lt;code&gt;m&lt;/code&gt; – a simple, multiline search that stops after the first match and is case sensitive &lt;br&gt;
 &lt;br&gt;
The regex snippet below matches a 10-digit ISBN. The test() checks if the input matches the format. An error is presented if it does not match.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function handleChange( e ) {
…
  } else if (name === "isbn") {
    const regex = /^(97(8|9))?\d{9}(\d|X)$/;
    if (!regex.test(value)) {
      error = "Invalid ISBN format! Only 10 characters!”
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
    •&lt;code&gt;^&lt;/code&gt; indicates the start of the string&lt;br&gt;
    •&lt;code&gt;(97(8|9))?&lt;/code&gt; matches the prefix for the ISBN-10 format. &lt;br&gt;
    •&lt;code&gt;\d{9}&lt;/code&gt; matches the 9 digits that make up the core of the ISBN code. This can be the 10 digits of an ISBN-10 code.&lt;br&gt;
    •&lt;code&gt;(\d|X)&lt;/code&gt; matches the last digit of the code. This can be either a digit or the letter "X", which is used to represent the digit “10” in ISBN-10 codes.&lt;br&gt;
    •&lt;code&gt;$&lt;/code&gt; indicates the end of the string.&lt;/p&gt;

&lt;p&gt;Form validation is pivotal in client-side and server-side interactions. Creating and enabling validation makes for faster interactions, correct information and more complete code.&lt;br&gt;
 &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;

</description>
      <category>react</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>The power of the bar graph: DOM manipulation via Javascript</title>
      <dc:creator>btryon-glitterkitty</dc:creator>
      <pubDate>Fri, 17 Feb 2023 18:57:19 +0000</pubDate>
      <link>https://dev.to/btryonglitterkitty/the-power-of-the-bar-graph-dom-manipulation-via-javascript-k1</link>
      <guid>https://dev.to/btryonglitterkitty/the-power-of-the-bar-graph-dom-manipulation-via-javascript-k1</guid>
      <description>&lt;p&gt;-ben tryon&lt;br&gt;
Back at the beginning of the browser wars, Netscape and Microsoft were battling for supremacy. The results were the DOM iterations.  The Document Object Model gives users the ability to relate to and manipulate HTML elements and layers of webpages and scripts.&lt;/p&gt;

&lt;p&gt;Part of programming is grabbing and changing the interior structure of computer memory. The DOM represents this memory structure in a Document, and includes style and content. Each element of the Document is a part of this structure and the overall DOM structure looks like a bar graph reaching to the sky. Each bar is a Node, each Node has parts –“parents” and “children” - that are attached to it and can be manipulated. &lt;/p&gt;

&lt;p&gt;Both the “recent” DOM iteration and event manipulation are considered the keystone markers of longevity for Javascript. Javascript works exceedingly well with the DOM, even though the DOM is “language-neutral”.   JS throws few errors when manipulating the DOM.  Event listeners are methods of “Event Targets”. “Event Target” is a node that acts when a function targets it and changes the DOM (if applicable).&lt;/p&gt;

&lt;p&gt;Event Listeners are powerful because they can add, subtract and otherwise influence the DOM “bar graph”.  For example, one needs a button added to the page.  This is a function button that did not exist in the HTML beforehand.  It can be clicked, and,  by user action, create a response:&lt;/p&gt;

&lt;p&gt;`const button = document.createElement("btn");&lt;/p&gt;

&lt;p&gt;document.getElementById("btn").addEventListener("click", displayDate);`&lt;/p&gt;

&lt;p&gt;JavaScript moves through the DOM by creating an Element of the HTML, grabbing it by a handle (the Id) and adding the button and it’s action (a function, defined elsewhere, that displays the date).  &lt;/p&gt;

&lt;p&gt;When the browser wars were hot, a major question was why and how to capture interaction beyond submitting forms, prompt alerts and the like.  DOM evolution, developer democratic criticism and the browser developers taking note, allowed the browsers to become open forums for change. In other words: we can now make CSS, HTML and the Document conform to our needs because early client-side devs wanted control, the Netscapes/Microsofts helped them and the DOM allowed it. Javascript was the best language for this new level.&lt;/p&gt;

&lt;p&gt;Event Listeners change DOM interaction via Javascript to a further degree because the Target node of the DOM is accessible via JavaScript. This Target allows a processing interaction to occur with data-node access and the right data.  Targets are the aim of Event Listeners.&lt;/p&gt;

&lt;p&gt;Below, the Target demonstrates the ability of the developer to start with an idea (starting/stopping gas pump flow). They may then manipulate the DOM through Elements. The user, developer, and browser can make choices now via logic: They all decide whether conditionally stopping or starting the gas flow/the Target meets their purpose.&lt;/p&gt;

&lt;p&gt;`function gasPump(event) {&lt;/p&gt;

&lt;p&gt;const pump = document.getElementById("pump");&lt;br&gt;
  if(event.target.style.background-color == "red"){&lt;br&gt;
      event.target.style.background-color = "blue";&lt;br&gt;
      event.target.innerText = "Stop Pump Flow?";&lt;br&gt;
          pump.style.visibility = "visible";&lt;br&gt;
   } else {&lt;br&gt;
      event.target.style.background-color = "red";&lt;br&gt;
      event.target.innerText = "Continue Gas Flow";&lt;br&gt;
          pump.style.visibility = "hidden"&lt;br&gt;
   }&lt;br&gt;
 }&lt;/p&gt;

&lt;p&gt;document.getElementById("myBtn").addEventListener("click", gasPump);`&lt;/p&gt;

&lt;p&gt;Overall, computers are simple – they take information and display it.  Javascript and the DOM allowed unparalleled access to the browser, the Document layer underlying it and the foundational structure. Users and developers benefited from this. This combination finds the ability to use conditional, actionable functions to make computers resources and tools of a previously quixotic future.&lt;/p&gt;

</description>
      <category>dom</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
