teleren/devto huggingface dataset:
Understanding Context in android Application
Published: 2022-09-23 19:40:15

**what is android context ?**


- used to get info about activity or application 

- both of Application Class and activity extends context class 

- used to access android resources and database etc ....

**Context**
 almost used everywhere in application wrong use for context 
     can easily causes memory leaks

 **Main Types of Context**

1. Application Context
2. Activity Context



## Application Context 

it is  singleton instance can access in activity via (getApplicationContext) tie to application life cycle 
used when you need to access context separate of activity  lifecycle

Example Use: If you have to create a singleton object for your application and that object needs a context, always pass the application context.


## Activity Context 

available in activity and  tie to activity lifecycle .The activity context should be used when you are passing the context in the scope of an activity or you need the context whose lifecycle is attached to the current context.

Example Use: If you have to create an object whose lifecycle is attached to an activity, you can use the activity context.

ex: like get resources to display

## How memory leaks is happens ?

memory leaks happens when you use activity context in task that is still running after activity destroy in this cases garbage collector can not remove reference of activity in memory  

Simple Example 

```
class LeaksClass(private val context: Context) {

    companion object {
        fun getInstance(context: Context): LeaksClass{
            return LeaksClass(context)
        }
    }

    fun doProcessing() {
        Thread {
            while (true) {
                Thread.sleep(100)
            }
        }.start()
    }

}
```
        LeaksClass.getInstance(activityContext(this)).doProcessing()

and class instance of this class and pass activity context and than start new activity or else... and make memory dumpheap 
in this case garbage collector(GC) can not remove reference of 
activity 

Solution -> 
`   LeaksClass.getInstance(applicationContext).doProcessing()



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1dsqxyc8u9hszycy58ic.png)


debugging using android studio profiler or LeakCanary

https://square.github.io/leakcanary/getting_started/
Quick LaTex: Footnotes with no Counter
Tags: latex
Published: 2023-01-06 03:00:05

---
title: Quick LaTex: Footnotes with no Counter
published: true
date: 2022-09-23 19:34:28 UTC
tags: LaTex
canonical_url: https://brandonrozek.com/blog/latex-footnote-no-count/
---

Let’s say there’s a scenario where you want to have a footnote, but you don’t want a counter associated with it. In order to stay consistent with the document style, the solution should use `\footnote` within its implementation.

The solution: Define `\blfootnote{text}` in the preamble.

```
\newcommand\blfootnote[1]{
    \begingroup
    \renewcommand\thefootnote{}\footnote{#1}
    \addtocounter{footnote}{-1}
    \endgroup
}

```

This makes use of the footnote command while also re-adjusting the footnote counts so that our variant doesn’t increase it. We can then use this command within the document. Here’s a beamer example:

```
\begin{frame}{Some Topic}
	This is where I explain some topic.
	\blfootnote{Numberless Footnote}
\end{frame}

```

Complete Minimal Example:

```
\documentclass[aspectratio=169]{beamer}
\usepackage[utf8]{inputenc}
\usetheme{Copenhagen}

\newcommand\blfootnote[1]{
    \begingroup
    \renewcommand\thefootnote{}\footnote{#1}
    \addtocounter{footnote}{-1}
    \endgroup
}

\begin{document}

\begin{frame}{Some Topic}
	This is where I explain some topic.
	\blfootnote{Numberless Footnote}
\end{frame}

\end{document}

```
Palindrome
Tags: javascript, algorithms
Published: 2022-09-23 19:10:04

**QUESTION**
Given an integer x, return true if x is palindrome integer.

An integer is a palindrome when it reads the same backward as forward.

For example, 121 is a palindrome while 123 is not.

**STEP**
- Reverse Integer

- Compare integer and reversed integer

**CODE**
- Reverse Integer 

The integer x is converted to a string using [toString()](https://www.google.com/url?sa=t&source=web&cd=&ved=2ahUKEwjMsID7xqv6AhUuMuwKHd5jC9AQFnoECA8QBQ&url=https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FWeb%2FJavaScript%2FReference%2FGlobal_Objects%2FFunction%2FtoString%23%3A~%3Atext%3DtoString%2520.%2Cis%2520concatenated%2520with%2520a%2520string.&usg=AOvVaw1W9rsegTar106tHu2zOMf5) method and a for loop is applied to convert the string to it's reverse state using the decrementing for loop

```
//convert interger to string
  var str = x.toString()

//reverse string
 let reverseStr = ""
    for(condition){
       //logic to reverse string
    }
```

- Compare integer and reversed integer string

The condition statement if else was used to compare interger `x` and the reversed string `str` using  type coercion, otherwise the condition would return false even if it's a palindrome number. 

[Type coercion](https://www.google.com/url?sa=t&source=web&cd=&ved=2ahUKEwjIw_i7yqv6AhUHwAIHHaJvBC8QFnoECA8QBQ&url=https%3A%2F%2Fitnext.io%2Fjavascript-type-coercion-implicit-conversion-and-why-to-use-and-avoid-ea9a38ecc777%23%3A~%3Atext%3DWhat%2520is%2520Type%2520Coercion%2520in%2Calso%2520known%2520as%2520type%2520conversion.&usg=AOvVaw3CJToQXclCIIh3NWSVfNKY)  helps convert one value type to another which make is it easy to compare values of difference types. Since I'm comparing a string and an interger, I used loose equality `==` which makes use of type coercion. In this case, string is coerced to an integer before comparism

```
//loose equality(using type coercion)
123 == "123" -> true
// strict comparis
123 === "123" -> false`
```
```
if(condition) {
        return true 
    } else{
        return false
    }
```

**Final Run**

```
var isPalindrome = function(x) {
    //convert interger to string
    var str = x.toString()
    
    //reverse string
    //var reverseStr = str.split("").reverse().join("")
    let reverseStr = ""
    for(condition){
       //logic to reverse string
    }
    
    //check for palindrome
  if(condition) {
        return true 
    } else{
        return false
    }
};

```
What was your win this week?
Tags: discuss, weeklyretro
Published: 2022-09-23 18:50:03

---
title: What was your win this week?
published: true
description: Got to all your meetings on time? Started a new project? Fixed a tricky bug?
tags: discuss, weeklyretro
cover_image: https://cl.ly/188e843c2985/download/Image%202019-02-15%20at%202.36.37%20PM.png
---

Hey y'all! 👋

Hope everybody is having a fantastic Friday and that you all have wonderful weekends!

Looking back on this past week, what was something you were proud of accomplishing?

All wins count — big or small 🎉

Examples of 'wins' include:

- Starting a new project
- Fixing a tricky bug
- Playing a new game 🎮
 
---

Kick back, relax, and enjoy your weekend! 😎

![Orange cat sitting back like a human, relaxed, in a green chair. A grey cat walks up to the cat in the chair, sniffs it, and walks away. The orange cat couldn't care less. There's another cat loafed up in the background.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2eihiqxb1xs9jcprbiwb.gif)
Machine Learning Basic
Tags: machinelearning, beginners, programming, python
Published: 2022-09-23 18:25:54

**Machine Learning**
Machine Learning is the field of study that gives computers the ability to learn and adapt without following explicit instructions, by using algorithms and statistical models.

The two main types of machine learning are

1. Supervised Learning.
2. Unsupervised Learning.

**(1) Supervised Learning**
In supervised learning, we provide a dataset where we have the result for certain inputs. Then the computer analyze and train itself to predict the result for any given inputs.

The two major types of supervised learning are

a. Regression 
b. Classification

**(a) Regression**
A regression is a statistical technique that relates a dependent variable to one or more independent (explanatory) variables. A regression model is able to show whether changes observed in the dependent variable are associated with changes in one or more of the explanatory variables.

Basically, from the dataset, the computer tries to draw a graph which helps to predict the result.

Predicting house prices depending on the location and size is the example of regression.

**(b) Classification**
Classification refers to a predictive modeling problem where a class label is predicted for a given example of input data.

Basically, from the dataset, the computer tries to find some class and differentiate them. Then it tries to predict the class from the given inputs.

Predicting if a email is spam or not is the example of classification.

**Difference Between Regression and Classification**
In regression, the model has to predict result from infinitely many possible output numbers. On the other hand, classification has to the category which has a small set of possible outputs.

**(2) Unsupervised Learning**
In unsupervised learning, the dataset only has some values without any result. Then the model tries to group them or find some pattern. Based on the pattern the model tries to give result for any given inputs.

Anomaly detection, which is used to detect unusual events is done by unsupervised learning.

**Difference Between Supervised and Unsupervised Learning**
In supervised learning, the data comes with both inputs x and input labels y, and the algorithm tries to find a graph from where it can predict result. On the other hand, in unsupervised learning, the data comes only with inputs x but not output labels y, and the algorithm has to find some structure or some pattern or something interesting in the data.
Palindrome Number - Leetcode
Published: 2022-09-23 18:03:48

[Palindrome Number](https://leetcode.com/problems/palindrome-number/)

Given an integer x, return true if x is palindrome integer.

---

Solving this could be as easy as converting the integer to a string and checking if the string is equal to it's reverse.

---
But there is a statement at the bottom of the question

> 
Follow up: Could you solve it without converting the integer to a string?

This is the approach I used as to task my mind a bit.

So first I checked for possible matches in additions and subtractions but it wasn't providing useful output.

I tried converting to binary to see if I could see patterns but I didn't find any.

Then I used the following steps:

1. Create an empty array which I would use later to store the reverse integers

2. Create a loop that would run if the integer was greater than 0

3. Divide the integer by 10

4. Store the remainder in the array and have the new integer run through the loop until it gets to 0.

5. Check if the array is equal to its reverse to return True or False.

This approach stores the remainder of the integer after being divided by 10 which forms the reverse of the integer in the array.
What You Need to Know about UX
Tags: usability, ux, petpeeves
Published: 2022-09-23 17:35:23

---
title: What You Need to Know about​ UX
published: true
description: UX advice without understanding the context can be worse than saying nothing at all.
tags: Usability, UX, petpeeves
canonical_url: https://tenmilesquare.com/resources/user-experience/what-you-need-to-know-about-ux/
cover_image: https://tenmilesquare.com/wp-content/uploads/2019/08/design-desk-eyewear-313690-1024x768.jpg
# Use a ratio of 100:42 for best results.
---
In a recent conversation, I was asked about pet peeves at work. As someone who’s been working in the user experience field for 25+ years, long before it was even called UX, I can give you an earful. Similar to UI design, where a single line blurted out at the project’s kick-off can ruin the whole mood (“It’s gotta pop!”), projects can get off on the wrong foot when I’m asked questions out of the blue about what’s the best approach in a particular situation. 

**Advice without understanding the context can be worse than saying nothing at all**.

Besides, the act of expressing that context is beneficial to both parties. That said, my pet peeves fall into these categories:

##A UX Designer Cannot Start Designing on Day 1!

Before you start, you need to:

1. Define what success looks like for the organization
2. Describe everyone who will use or be impacted by your product’s use
3. Map out the user behaviors that will allow you to achieve your goals

Either the client has done this work up front or, more likely, they have that built into the statement for work for the UX designer. I prefer the latter because it allows me to fully grok the context in which the client operates.

##The User in UX Is a Plural!

Each individual interacting with your product arrives with their own history and experience. UX is not a one-size-fits-all proposition. That said, you cannot please all people all of the time, so you need to prioritize. The prioritization must be done by the client. As a UX designer, with my understanding of the context, I can make suggestions, but the product owner has to *OWN* the success of the product.

##UX is Not Immutable!

A user’s experience the first time interacting with your product is different from the second, the tenth, the thousandth, etc., etc. The key is to implement a framework that gathers usage metrics that allow you to evaluate the current UX and adjust as necessary. If I’ve done my job right, the organization will now have:

* Access to people who fully understand the universe in which the product operates
* Know how that universe and the people who populate it might change over time
* Have the metrics to evaluate that evolution
* Understand how to express that to the development team

That is the sign of a project well executed.
Relaxing Arduino's work with Ruby
Tags: ruby, arduino
Published: 2022-09-23 17:34:13

One of the ways to break into the system is to use bad USBs and to use bad USBs you must know Arduino and the syntax of Arduino language is a bit difficult.  But don't worry, we solved this problem to some extent, you can use 'rubyino' library and convert your ruby   codes to arduino codes.  In this method, you don't need to learn Arduino codes and you only need Arduino IDE to upload the codes. Let's get started.

## how to install ?

- install with gem 
```
gem install Rubyino
```
- install with git ( [github page](https://github.com/nimacpp/rubyino.git)
```
git clone https://github.com/nimacpp/rubyino.git
cd rubyino
gem build rubyino.gemspec
gem install rubyino*.gem
```
## Rubyino's functions
first you need include gem and then set value for it like this :
```ruby
require "Rubyino"
app = Rubyino.new("namefile")
```
now you can work with Rubyino
## functions on Rubyino
delay(timer sleep) :
```ruby
app.delay(500)
```
print(print keyboard) :
```ruby
app.print "hello world"
```
Enter(Enter key) :
```ruby
app.enter
```
Window or cmd key + key :
```ruby
win_pls "r" # win+r
```
and for translate codes to Arduino need `ter` function like this :
```ruby
app.ter
```
one Example for know that :
```ruby
require "rubyino"
app = Rubyino.new("file")
app.delay(5000)
app.win_pls('r')
app.print "echo hello world"
app.enter
app.print "ls -a"
app.ter
```
save it and run it . script will create a file named file.ino for you .
Please open the file with the Arduino ide program and press the upload button to upload the script to the arduino
Different Ways To Create Objects In JavaScript
Tags: javascript, beginners, programming, webdev
Published: 2022-09-23 17:10:03

**There are majorly four ways of creating the objects in JavaScript :**

_1 .Using Object Literals
2 .Using Factory Functions
3 .Using Object.create()
4 .Using Classes_

**Using Object Literals:**This is the most common way of creating the objects in JavaScript. Object literals are the set of key value pairs separated by comma which are enclosed within the flower braces.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s93ovtunw1xjzl82bqdx.png
)

**Using Factory Functions:**are the type of function that returns the object 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/62riqtndndvsp8hq0fa1.png
)

**Using Object.create():**It is used to create a new object by using an existing object as prototype for new object

_Syntax for Object.create():_

`Object.create(proto)`

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljs22ppbsbi91cf2el1y.png
)

In the above example we can see that firstObj acts as a prototype for secondObj. we can also see that secondObj has access to the myIntro function which is a part of firstObj

**Using Classes:**Classes are the ES6 syntactic sugar for creating the objects 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tyz13xk1xpshi5h7mxq2.png)
Finding the Minimum and Maximum Values of an Array in JavaScript
Tags: javascript, interview, tutorial
Published: 2022-09-23 17:10:00


![singularity](https://bigthink.com/wp-content/uploads/2022/04/13.8_Singularities-In-Nature_Lead.jpg)
In javascript it is possible to find the minimum and maximum value of an integer in an array

This is among the most common coding interview question that interviewers use to test the skills of developers. 

### Chapter 1 <a name="chapter-1">Using in built library</a>

The simplest method of finding the minimum value of an array is by using the in built `Math` library that has both `Math.min` and `Math.max` functions for finding minimums and maximums.

```js
//Find the maximum in an array
let maxValue = Math.max(...arr);

//Find the minimum in an array
let minValue = Math.min(...arr);
```


### Chapter 2 <a name="chapter-2">Using in `for` loops</a>

One can also accomplish this by the use of a `for` loop as shown

```js
//Find the maximum in an array
function arrMax(arr) {
  let maxArr = Number.NEGATIVE_INFINITY;
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] >= maxArr) {
      maxArr = arr[i];
    }
  }
}
```

The same can be used in finding the smallest number

```js
//Find the minimum in an array
function arrMin(arr) {
  let minArr = Number.POSITIVE_INFINITY;
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] <= minArr) {
      minArr = arr[i];
    }
  }
}
```

`Number.NEGATIVE_INFINITY` and `Number.POSITIVE_INFINITY` are used in javascript to represent the lowest and highest number representation of the language.

### Chapter 3 <a name="chapter-3">Using in `reduce` function</a>
Alternatively, one may opt to use the `Array.prototype.reduce()` function in finding the minimum and maximum values of an array. The reduce function simply uses a provided callback to return a single element. In our case, this is either the minimium value or the maximum value.

```js
//Find the minimum in an array
function arrMin(arr) {
  return arr.reduce((a, b) => (a < b ? b : a));
}
```

```js
//Find the maximum in an array
function arrMax(arr) {
  return arr.reduce((a, b) => (a < b ? a : b));
}
```

The `(a, b) => (a < b ? b : v)` expression works as an `if.. else` statement. In javascript it is referred to as the Ternary operator with a method signature as

`variable = Expression1 ? Expression2: Expression3`

Leave a like :heart: if you found this useful
Happy coding :fire: :fire:
HTML: Display tooltip with only HTML
Tags: webdev, beginners, programming, html
Published: 2022-09-23 17:03:10

We can build awesome tooltips using CSS and other external libraries but we may not need to build every time.

```html
<p title="This is a tooltip">It is a sample paragraph.</p>

<hr>

<abbr title="World Health Organization">WHO</abbr>
```
Output:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t7t7ceebsgmtpfugjcfr.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8bk7ogrzu5msh86ngxw4.png)

Thanks.
Animate a Math Object With a Trace Path Using Python Manim Library
Published: 2022-09-23 16:52:49

### Learn the basics of manim library to create beautiful animation

![](https://cdn-images-1.medium.com/max/2000/1*gMchhxA5Cazbs6GtBkQxXw.png)

Manim is a python library used to create beautiful animation, especially if you want to visualize a mathematical concept. it was invented by [3blue1brown](https://www.youtube.com/c/3blue1brown).

Unfortunately, the explanation in the [**documentation](https://docs.manim.community/en/stable/index.html)** of manim is challenging to grasp especially for beginners. Since understanding the basics of any technology is key to building a mental framework and how you can reinvent the wheel, this article will try to explain some simple basic concepts that will explain some code in the documentation.

I have a pdf copy where I explain all the classes and methods we will use in detail through this [link](https://payhip.com/b/ao1BJ). It simplifies the classes for a beginner to grasp

### One of the basics is to understand the manim coordinate system.

![source: author](https://cdn-images-1.medium.com/max/2560/1*C_RcZf68lz3Ug5xQaZ8iAQ.png)

This is very important when positioning your objects in the scene canvas.

In manim, maths object (mobject) is the basic object that we add to our scene canvas and also animate.

All mobjects are positioned at the centre of the canvas i.e. (0,0) coordinate by default. every cell represents one **Munit** (manim unit)

When you count the cell in the **height**, you get 8 **Munit** and the **width** will give you around 14.22 **Munit. **I will be creating a cheat sheet in positioning manim mobjects soon.

### **Let's use the TracedPath class from the manim library to animate a moving dot leaving a trace**

We will be using google colab to run the code. just run the following code to install the manim library and its dependencies.

    !sudo apt update

    !sudo apt install libcairo2-dev ffmpeg \n
    texlive texlive-latex-extra texlive-fonts-extra \n
    texlive-latex-recommended texlive-science \n
    tipa libpango1.0-dev

    !pip install manim

    !pip install IPython — upgrade

The next step is to all classes, methods and functions from the library.

    **from** manim **import** *****

This is the complete code and I will be explaining what each line does use the python comment
{% gist https://gist.github.com/bldrkamal/8ad43ee1617325cde1de781b67872aea.js %}



![result of animation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b6dobio7rlqvuysshtho.gif)

### conclusion

Experimenting with python and manim library can be a fun way to learn programming, especially objected-oriented concepts. you will be able to see the result of code through animating mathematical objects(mobjects) and concepts. my next article will be on animating functions and plotting the results.

*Originally published at https://[www](https://www.instructables.com/Animate-a-Math-Object-With-a-Trace-Path-Using-Pyth/).instructables.com.*
Creating stores with pinia in Vue 3 + Typescript
Tags: vue, typescript, pinia
Published: 2022-09-23 16:48:46

Pinia is the new state management system for Vue and in this article I'll show two ways of use this amazing tool with Typescript and simple examples.

## 1 - Simple store with Typescript assertion

```javascript
import { defineStore } from "pinia";
import type { MyInterface } from "@/types";

type RootState = {
  myState: MyInterface[];
};

const useMyStore = defineStore("franchiseStore", {
  state: () =>
    ({
      myState: [],
    } as RootState),
  actions: {
    setCurrentState(state: MyInterface[]) {
      this.myState = state
    },
  },
});

export default useMyStore;
```


## 2 - Simple store with Typescript assertion and using **Composition API**

```javascript
import { defineStore } from 'pinia';
import { ref } from 'vue';
import type { MyInterface } from '@/types'

export const useMyStore = defineStore('myStore', () => {

  const myState = ref<Array<MyInterface>>([]);

  function setCurrentState(state: MyInterface[]) {
    myState.value = state
  }
  
  return { myState, setCurrentState };
});

export default useMyStore;
```