<?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: Takuro Goto</title>
    <description>The latest articles on DEV Community by Takuro Goto (@__e19a78719dbdd7bc958).</description>
    <link>https://dev.to/__e19a78719dbdd7bc958</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%2F2170451%2Fdb691e1e-ccc0-48a2-96f6-81da01be0f11.png</url>
      <title>DEV Community: Takuro Goto</title>
      <link>https://dev.to/__e19a78719dbdd7bc958</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/__e19a78719dbdd7bc958"/>
    <language>en</language>
    <item>
      <title>Important thoughts on JavaScript</title>
      <dc:creator>Takuro Goto</dc:creator>
      <pubDate>Sat, 16 Nov 2024 03:20:26 +0000</pubDate>
      <link>https://dev.to/__e19a78719dbdd7bc958/important-thoughts-on-javascript-3ik8</link>
      <guid>https://dev.to/__e19a78719dbdd7bc958/important-thoughts-on-javascript-3ik8</guid>
      <description>&lt;p&gt;&lt;strong&gt;1.Closures&lt;/strong&gt;&lt;br&gt;
A closure occurs when a function retains access to variables from its outer (enclosing) scope, even after the outer function has finished executing. This means that even though the outer function has returned, its local variables are still accessible by the inner function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function counter() {
    let count = 0;
    return function() {
        return ++count;
    };
}

const increment = counter();
console.log(increment()); // 1
console.log(increment()); // 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the outter function is counter()&lt;br&gt;
the inner function is return function() in the outter function&lt;br&gt;
So a closure let the inner function access to the count variable in the outter function's scope even after the outert funcion has done with execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Prototypes&lt;/strong&gt;&lt;br&gt;
In JavaScript, prototypes allow you to share functions across multiple instances of an object. Instead of defining the same function in each instance, you can define it once on the object's prototype. This way, all instances of the object can access the same function, reducing redundancy and improving efficiency by saving memory and resources in your code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Constructor function (similar to a class in other languages)
function Person(name, age) {
    this.name = name;
    this.age = age;
}

// Adding a method to the `Person` prototype
Person.prototype.greet = function() {
    return `Hello, my name is ${this.name} and I am ${this.age} years old.`;
};

// Creating new instances
const person1 = new Person('Alice', 30);
const person2 = new Person('Bob', 25);

// Calling the method on the instances
console.log(person1.greet()); // "Hello, my name is Alice and I am 30 years old."
console.log(person2.greet()); // "Hello, my name is Bob and I am 25 years old."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Person1 and Person2 can access the greet function even though they don't have the greet function defined on their own.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Important thoughts on JavaScript</title>
      <dc:creator>Takuro Goto</dc:creator>
      <pubDate>Sat, 16 Nov 2024 03:20:26 +0000</pubDate>
      <link>https://dev.to/__e19a78719dbdd7bc958/important-thoughts-on-javascript-433p</link>
      <guid>https://dev.to/__e19a78719dbdd7bc958/important-thoughts-on-javascript-433p</guid>
      <description>&lt;p&gt;&lt;strong&gt;1.Closures&lt;/strong&gt;&lt;br&gt;
A closure occurs when a function retains access to variables from its outer (enclosing) scope, even after the outer function has finished executing. This means that even though the outer function has returned, its local variables are still accessible by the inner function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function counter() {
    let count = 0;
    return function() {
        return ++count;
    };
}

const increment = counter();
console.log(increment()); // 1
console.log(increment()); // 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the outter function is counter()&lt;br&gt;
the inner function is return function() in the outter function&lt;br&gt;
So a closure let the inner function access to the count variable in the outter function's scope even after the outert funcion has done with execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Prototypes&lt;/strong&gt;&lt;br&gt;
In JavaScript, prototypes allow you to share functions across multiple instances of an object. Instead of defining the same function in each instance, you can define it once on the object's prototype. This way, all instances of the object can access the same function, reducing redundancy and improving efficiency by saving memory and resources in your code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Constructor function (similar to a class in other languages)
function Person(name, age) {
    this.name = name;
    this.age = age;
}

// Adding a method to the `Person` prototype
Person.prototype.greet = function() {
    return `Hello, my name is ${this.name} and I am ${this.age} years old.`;
};

// Creating new instances
const person1 = new Person('Alice', 30);
const person2 = new Person('Bob', 25);

// Calling the method on the instances
console.log(person1.greet()); // "Hello, my name is Alice and I am 30 years old."
console.log(person2.greet()); // "Hello, my name is Bob and I am 25 years old."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Person1 and Person2 can access the greet function even though they don't have the greet function defined on their own.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Reuse the same exception logic in Python</title>
      <dc:creator>Takuro Goto</dc:creator>
      <pubDate>Mon, 04 Nov 2024 07:17:36 +0000</pubDate>
      <link>https://dev.to/__e19a78719dbdd7bc958/reuse-the-same-exception-logic-in-python-1bd1</link>
      <guid>https://dev.to/__e19a78719dbdd7bc958/reuse-the-same-exception-logic-in-python-1bd1</guid>
      <description>&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;br&gt;
When coding, it's essential to handle exceptions carefully. Today, I want to share a method that allows you to reuse the same exception handling logic in Python, making your code more readable and maintainable for others.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CHandling Exceptions with a Decorator&lt;/strong&gt;&lt;br&gt;
Below is a simple implementation of a decorator designed to manage exceptions consistently across different functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def error_handler(func):
    def wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except FileNotFoundError as e:
            print(f"File not found: {e}")
        except ZeroDivisionError as e:
            print(f"Zero division error occurred: {e}")
        # Additional error handling can be added here
    return wrapper
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using the Decorator&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@error_handler
def read_file(filename):
    with open(filename, 'r') as file:
        # Process the file
        print(file.read())  # Example of processing the file

@error_handler
def divide_numbers(a, b):
    return a / b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example Calls&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;read_file('test.txt')  # Attempting to read a non-existent file
divide_numbers(2, 0)   # Attempting to divide by zero
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;br&gt;
The code defines a decorator named error_handler, which is used to manage exceptions for any decorated functions. A decorator is a higher-order function that takes another function as an argument and extends or alters its behavior without modifying the original function's code.&lt;/p&gt;

&lt;p&gt;When the error_handler decorator is applied to a function, it wraps the function call in a try block. If the decorated function raises a FileNotFoundError or ZeroDivisionError, the decorator catches these exceptions and prints a user-friendly error message. This approach not only enhances code readability but also promotes code reuse, as the same error handling logic can be applied to multiple functions.&lt;/p&gt;

&lt;p&gt;By employing this technique, you can create cleaner, more robust Python code that is easier for others to understand and maintain.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to mosic your face!?</title>
      <dc:creator>Takuro Goto</dc:creator>
      <pubDate>Sun, 03 Nov 2024 06:39:21 +0000</pubDate>
      <link>https://dev.to/__e19a78719dbdd7bc958/how-to-mosic-your-face-3j5f</link>
      <guid>https://dev.to/__e19a78719dbdd7bc958/how-to-mosic-your-face-3j5f</guid>
      <description>&lt;p&gt;Today, I want to share how to create a mosaic effect on human faces in Python. If you enjoy taking pictures, you probably also want to know how to modify them to make them look even better. This will enhance your photographic experience!&lt;br&gt;
So, let's get started!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Required Documents&lt;/strong&gt;&lt;br&gt;
Face detection tool&lt;br&gt;
&lt;a href="https://github.com/opencv/opencv/blob/master/data/haarcascades/haarcascade_frontalface_alt.xml" rel="noopener noreferrer"&gt;https://github.com/opencv/opencv/blob/master/data/haarcascades/haarcascade_frontalface_alt.xml&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;import libraries&lt;br&gt;
・cv2&lt;br&gt;
・matplotlib&lt;br&gt;
・mosaic_creator.py(this is one you make by your self)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Detailed Method&lt;/strong&gt;&lt;br&gt;
mosaic_creator.py&lt;br&gt;
①Calculate mosaic width and height based on the dataset.&lt;br&gt;
②Apply the mosaic effect to a specified area of the original image.&lt;br&gt;
③Combine the modified area with the original image.&lt;/p&gt;

&lt;p&gt;mosaic_creator.py------------------------------------------------------&lt;br&gt;
import cv2&lt;/p&gt;

&lt;p&gt;def mosaic(img, rect, size):&lt;br&gt;
    ①Calculate mosaic width and height based on the dataset.&lt;br&gt;
    (x1, y1, x2, y2) = rect&lt;br&gt;
    w = x2 - x1&lt;br&gt;
    h = y2 - y1&lt;br&gt;
    i_rect = img[y1:y2, x1:x2]&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;②Apply the mosaic effect to a specified area of the original image.
i_small = cv2.resize(i_rect, (size, size))
i_mos = cv2.resize(i_small, (w, h), interpolation=cv2.INTER_AREA)

③Combine the modified area with the original image.
img_m = img.copy()
img_m[y1:y2, x1:x2] = i_mos
return img_m
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;test.py&lt;br&gt;
①Create a face detection model.&lt;br&gt;
②Read an image file and convert it to grayscale.&lt;br&gt;
③Call the mosaic function.&lt;br&gt;
④Save the mosaic image.&lt;/p&gt;

&lt;p&gt;test.py----------------------------------------------------------------&lt;br&gt;
import matplotlib.pyplot as plt&lt;br&gt;
import cv2&lt;br&gt;
from mosaic import mosaic as mosaic&lt;/p&gt;

&lt;p&gt;①Create a face detection model.&lt;br&gt;
cascade_file = 'haarcascade_frontalface_alt.xml'&lt;br&gt;
cascade = cv2.CascadeClassifier(cascade_file)&lt;/p&gt;

&lt;p&gt;②Read an image file and convert it to grayscale.&lt;br&gt;
img = cv2.imread('face.png')&lt;br&gt;
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)&lt;/p&gt;

&lt;p&gt;faces_list = cascade.detectMultiScale(img_gray, minSize=(900, 900))&lt;br&gt;
if len(faces_list) == 0: quit()&lt;/p&gt;

&lt;p&gt;③Call the mosaic function.&lt;br&gt;
for (x, y, w, h) in faces_list:&lt;br&gt;
    img = mosaic(img, (x, y, x+w, y+h), 10)&lt;/p&gt;

&lt;p&gt;④Save the mosaic image.&lt;br&gt;
cv2.imwrite('face-m.png', img)&lt;br&gt;
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))&lt;br&gt;
plt.show()&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The code performs regression analysis on temperature data and visualizes the model's prediction results</title>
      <dc:creator>Takuro Goto</dc:creator>
      <pubDate>Sat, 02 Nov 2024 07:20:20 +0000</pubDate>
      <link>https://dev.to/__e19a78719dbdd7bc958/the-code-performs-regression-analysis-on-temperature-data-and-visualizes-the-models-prediction-results-4oaj</link>
      <guid>https://dev.to/__e19a78719dbdd7bc958/the-code-performs-regression-analysis-on-temperature-data-and-visualizes-the-models-prediction-results-4oaj</guid>
      <description>&lt;p&gt;&lt;strong&gt;Today's Purpose&lt;/strong&gt;&lt;br&gt;
Today, I want to share how you can conduct a simple regression analysis using several libraries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Libraries Used&lt;/strong&gt;&lt;br&gt;
LinearRegression&lt;br&gt;
pandas&lt;br&gt;
matplotlib&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data file&lt;/strong&gt;&lt;br&gt;
Temperature_10y.csv&lt;br&gt;
 Year,Month,Day,Temperature,Quality,Homogeneity&lt;br&gt;
 2006,1,1,3.6,8,1&lt;br&gt;
 ・・・&lt;br&gt;
 2016,12,31,6.3,8,2&lt;br&gt;
※This file contains 10 years of temperature data&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Detailed Method&lt;/strong&gt;&lt;br&gt;
①Import libraries necessary for regression analysis.&lt;br&gt;
②Read the temperature data file.&lt;br&gt;
③Split the 10 years of temperature data into 9 years (2006–2015) for training and 1 year (2016) for testing.&lt;br&gt;
※The 9 years of data will serve as training data, while the 1 year will be the test data.&lt;br&gt;
④The make_data function prepares the input features and target values from the dataset.&lt;br&gt;
Example:&lt;br&gt;
temps = [3.6, 4.0, 3.7, 4.0, 3.6, 2.1, 2.8,…]&lt;br&gt;
x = [[3.6, 4.0, 3.7, 4.0, 3.6, 2.1], …]&lt;br&gt;
y = [2.8, …]&lt;br&gt;
⑤Create a model using the training data.&lt;br&gt;
⑥Generate predictions using the model and the test data.&lt;br&gt;
⑦Plot a graph showing both the predicted and test data.&lt;br&gt;
⑧Calculate the difference between the predicted and test data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Source Code&lt;/strong&gt;&lt;br&gt;
①Import libraries&lt;br&gt;
from sklearn.linear_model import LinearRegression&lt;br&gt;
import pandas as pd&lt;br&gt;
import matplotlib.pyplot as plt&lt;/p&gt;

&lt;p&gt;②Read the temperature file&lt;br&gt;
df = pd.read_csv('Temperature_10y.csv', encoding='utf-8')&lt;/p&gt;

&lt;p&gt;③Split the data&lt;br&gt;
train_year = df['年'] &amp;lt;= 2015&lt;br&gt;
test_year = df['年'] &amp;gt;= 2016&lt;br&gt;
interval = 6&lt;/p&gt;

&lt;p&gt;④Prepare data&lt;br&gt;
def make_data(data):&lt;br&gt;
    x = []&lt;br&gt;
    y = []&lt;br&gt;
    temps = list(data['Temperature'])&lt;br&gt;
    for i in range(len(temps)):&lt;br&gt;
        if i &amp;lt; interval: continue&lt;br&gt;
        y.append(temps[i])&lt;br&gt;
        xa = []&lt;br&gt;
        for p in range(interval):&lt;br&gt;
            d = i + p - interval&lt;br&gt;
            xa.append(temps[d])&lt;br&gt;
        x.append(xa)&lt;br&gt;
    return (x, y)&lt;/p&gt;

&lt;p&gt;train_x, train_y = make_data(df[train_year])&lt;br&gt;
test_x, test_y = make_data(df[test_year])&lt;/p&gt;

&lt;p&gt;lr = LinearRegression()&lt;br&gt;
⑤Create the model&lt;br&gt;
lr.fit(train_x, train_y)&lt;br&gt;
⑥Make predictions&lt;br&gt;
pre_y = lr.predict(test_x)&lt;/p&gt;

&lt;p&gt;⑦Plot the results&lt;br&gt;
plt.figure(figsize=(10, 6), dpi=100)&lt;br&gt;
plt.plot(test_y, c='r')  # Actual data in red&lt;br&gt;
plt.plot(pre_y, c='b')   # Predicted data in blue&lt;br&gt;
plt.savefig('temperature-lr.png')&lt;br&gt;
plt.show()&lt;/p&gt;

&lt;p&gt;⑧Calculate differences&lt;br&gt;
diff_y = abs(pre_y - test_y)&lt;br&gt;
print('Average Difference =', sum(diff_y) / len(diff_y))&lt;br&gt;
print('Maximum Difference =', max(diff_y))&lt;br&gt;
print('Minimum Difference =', min(diff_y))&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;&lt;br&gt;
temperature-lr.png&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1qk1whkiuw4jdt79f413.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1qk1whkiuw4jdt79f413.png" alt="Image description" width="800" height="480"&gt;&lt;/a&gt;&lt;br&gt;
avg= 1.6640684971954247&lt;br&gt;
max= 8.471949619908472&lt;br&gt;
min= 0.01187698362363232&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The first small step in experiencing JavaScript</title>
      <dc:creator>Takuro Goto</dc:creator>
      <pubDate>Sat, 05 Oct 2024 13:17:53 +0000</pubDate>
      <link>https://dev.to/__e19a78719dbdd7bc958/the-first-small-step-in-experiencing-javascript-1mfm</link>
      <guid>https://dev.to/__e19a78719dbdd7bc958/the-first-small-step-in-experiencing-javascript-1mfm</guid>
      <description>&lt;p&gt;Today, I created my own account on this site, and I wanted to share a small step in learning JavaScript.&lt;/p&gt;

&lt;p&gt;What I developed today is &lt;br&gt;
Todo List&lt;/p&gt;

&lt;p&gt;Hierarchical Structure Example is&lt;br&gt;
my-todo-app/&lt;br&gt;
│&lt;br&gt;
├── index.html&lt;br&gt;
├── style.css&lt;br&gt;
├── script.js&lt;/p&gt;

&lt;p&gt;Detailed Code is&lt;br&gt;
&lt;strong&gt;index.html&lt;/strong&gt;&lt;br&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br&gt;
&lt;br&gt;
    &lt;/p&gt;
&lt;br&gt;
        &lt;br&gt;
        &amp;lt;!--difine the size when it pops up in device--&amp;gt;&lt;br&gt;
                &lt;br&gt;
        Todo List in head&lt;br&gt;
    &lt;br&gt;
    &lt;br&gt;
        &lt;h1&gt;Todo List in body&lt;/h1&gt;
&lt;br&gt;
        &amp;lt;!--client input, input type, text in field--&amp;gt;&lt;br&gt;
        &lt;br&gt;
        add&lt;br&gt;
        &lt;ul id="todo-list"&gt;&lt;/ul&gt;
&lt;br&gt;
        &lt;br&gt;
    &lt;br&gt;


&lt;p&gt;&lt;strong&gt;style.css&lt;/strong&gt;&lt;br&gt;
body{&lt;br&gt;
    font-family:Arial, sans-serif;&lt;br&gt;
    margin: 20px;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;input{&lt;br&gt;
    margin-right: 10px;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;ul{&lt;br&gt;
    list-style-type: none;&lt;br&gt;
    padding:0;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;li{&lt;br&gt;
    margin:5px 0;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;script.js&lt;/strong&gt;&lt;br&gt;
document.getElementById('add-button').addEventListener('click', function() {&lt;br&gt;
    const input = document.getElementById('todo-input');&lt;br&gt;
    const newTodo = input.value;&lt;br&gt;
    if (newTodo) {&lt;br&gt;
        const li = document.createElement('li');&lt;br&gt;
        li.textContent = newTodo;&lt;br&gt;
        document.getElementById('todo-list').appendChild(li);&lt;br&gt;
        input.value = ''; // clear in input field&lt;br&gt;
    }else{&lt;br&gt;
        alert("type something please");&lt;br&gt;
    }&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;There is one input field and one button displayed on the screen when the client accesses index.html.&lt;/p&gt;

&lt;p&gt;If the client fills in the input field with text and clicks the button, the text entered will be displayed on the screen.&lt;/p&gt;

&lt;p&gt;If the client does not enter anything and clicks the button, an alert saying "Please type something." will pop up.&lt;/p&gt;

&lt;p&gt;I believe these codes are very basic but useful for learning JavaScript. They especially help you understand the relationship between the HTML file and the JavaScript file (script.js), and how they interact with each other.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
