teleren/devto huggingface dataset:
PYTHON
Tags: python, beginners, discuss
Published: 2023-06-05 17:36:53



##Python Introduction

Python is a high-level, interpreted programming language known for its simplicity and readability. It was created by Guido van Rossum and first released in 1991. Python's design philosophy emphasizes code readability, making it an excellent choice for beginners and experienced developers alike.

## Key Features

- **Easy to Learn**: Python has a clean and intuitive syntax that is easy to understand, making it ideal for beginners. Its readability helps in reducing the cost of program maintenance and development.

- **Versatile**: Python is a versatile language that can be used for various purposes, such as web development, data analysis, artificial intelligence, scientific computing, automation, and more. It has a vast collection of libraries and frameworks to support different domains.

- **Cross-platform Compatibility**: Python is available on multiple platforms, including Windows, macOS, and Linux, allowing developers to write code that can run seamlessly across different operating systems.

- **Large Community**: Python has a thriving community of developers who actively contribute to its growth. This community provides extensive documentation, tutorials, and support, making it easier for developers to learn and solve problems.

## Use Cases

Python's versatility makes it suitable for a wide range of applications:

- **Web Development**: Frameworks like Django and Flask enable rapid web application development using Python.

- **Data Analysis**: Python, along with libraries like NumPy, Pandas, and Matplotlib, is widely used for data manipulation, analysis, and visualization.

- **Machine Learning and AI**: Python's simplicity and powerful libraries like TensorFlow and PyTorch have made it a popular choice for machine learning and artificial intelligence projects.

- **Automation**: Python's scripting capabilities make it an excellent choice for automating repetitive tasks and system administration.

## Conclusion

Python's simplicity, versatility, and large community make it a popular programming language for a wide range of applications. Whether you are a beginner or an experienced developer, Python's readability and extensive library support make it a great language to learn and work with. With its broad range of use cases, Python continues to grow in popularity and remains a top choice for developers worldwide.

Start your Python journey today and unlock the endless possibilities it offers!
Ruby - DIY accessor methods
Tags: ruby, oop
Published: 2023-06-05 06:06:58

---
title: Ruby - DIY accessor methods
published: true
description: Ruby class macros and accessor methods
tags: ruby, oop
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2023-06-05 04:40 +0000
---

## 1. Ruby accessor methods
Ruby does not allow instance variables to be accessed outside of methods for that object.
```ruby
class Person  
  def initialize(name)
    @name = name
    @age = 10
  end
end
p = Person.new('steve')
p.name  # =>  undefined method `name=' for #<Person ..>
```
This design ensures OOP *encapsulation* - an object’s data is protected from the outside world.  
In some languages like Java, to access private instance variables, you must define getter/setter methods for each attribute. But in Ruby, you can generate getter/setter methods by using one of the methods in the `Module#attr_*` family. 
``` ruby
class Person
  attr_reader :name, :age      # getter 
  attr_writer :name, :age      # setter
  # attr_accessor :name, :age  # getter + setter
  # other code ....
end
p = Person.new('steve')
p.name  # =>  steve
p.age = 20
p.age # => 20
```
It just takes one or two lines for all of the attributes. These methods are called Class Macros which are class methods only used when in a class definition.

## 2. DIY accessor methods
There are advanced ways to access instance variables, like `instance_variable_get`, `instance_eval`.
For example:
``` ruby
p = Person.new('steve')
p.instance_variable_get(:@name)
p.instance_eval { @name }
```
Using some metaprogramming techniques, we can build attribute accessor methods by myself.
```ruby
module GetterSetter
  def attr_getter(*attributes)
    attributes.each do |attribute|
      define_method attribute do
        instance_variable_get("@#{attribute}")
      end
    end
  end

  def attr_setter(*attributes)
    attributes.each do |attribute|
      define_method "#{attribute}=" do |value|
        instance_variable_set("@#{attribute}", value)
      end
    end
  end

  def attr_getter_and_setter(*attributes)
    attr_getter(*attributes)
    attr_setter(*attributes)
  end
end
```
For simplicity, I define getter/setter in separated module and include in `Person` class.
``` ruby
class Person
  extend GetterSetter
  
  def initialize(name)
    @name = name
    @age = 10
  end

  attr_getter :name, :age
  attr_setter :name, :age
  # or 
  # attr_getter_and_setter :name, :age
end

p = Person.new('Luke')
p.name = 'anakin'
p.name # => anakin
```


## Summary
Class macros are one of Ruby's magic methods that help developers get rid of a lot of tedious, boilerplate methods. In rails, class macros are used a lot, for associations ( `has_many`, `belongs_to` ), validation, ...    
You can learn more about Ruby class macros or other metaprogramming techniques  in the Metaprogramming Ruby book ( https://pragprog.com/titles/ppmetr2/metaprogramming-ruby-2/)
2716. LeetCode's Minimize String Length - FASTEST JAVA SOLUTION BEATS 100% OF SOLUTIONS!!!!
Tags: java, beginners, programming, tutorial
Published: 2023-06-05 16:44:35

# Intuition
The problem is to find the minimum length of a string after removing all duplicate characters. One way to solve this problem is to use a boolean array to keep track of which characters have been seen before in the string. Then, we can iterate over the string and count how many unique characters there are. This will give us the minimum length of the string.

# Approach
We can use a boolean array of size 26 to represent the 26 lowercase letters in the alphabet. We initialize all the elements to false, meaning that we have not seen any character yet. Then, we convert the input string to a char array and loop through it. For each character, we check its corresponding index in the boolean array. If it is false, we set it to true and increment a counter variable. If it is true, we ignore it and move on to the next character. At the end of the loop, the counter variable will hold the number of unique characters in the string, which is also the minimum length of the string after removing duplicates.

# Complexity
- Time complexity:
The time complexity of this solution is $$O(n)$$, where n is the length of the input string. This is because we only need to loop through the string once and perform constant time operations for each character.

- Space complexity:
The space complexity of this solution is $$O(1)$$, because we only use a fixed size boolean array and a few variables that do not depend on the input size.

# Code
```JAVA
import java.util.ArrayList;

class Solution {
    public int minimizedStringLength(String s) {
        char[] characters = s.toCharArray();
        int count = 0;
        boolean[] seen = new boolean[26];
        for (int i = 0; i < characters.length; i++) {
            if (!seen[characters[i] - 97]) {
                seen[characters[i] - 97] = true;
                count++;     
            }   
        }
        return count;
    }   
}

```
Using LLMs the Right Way with Python
Tags: llm, python, opensource, chatgpt
Published: 2023-06-05 16:43:04

🚀 Excited to announce the release of [LLM-Client-SDK](https://github.com/uripeled2/llm-client-sdk), an open-source Python package for seamless integration with generative AI large language models! 🌟

With LLM-Client-SDK, developers can easily communicate with popular language models like OpenAI, Goggle, AI21 Labs, Hugging Face, Aleph Alpha, Anthropic and more, without sacrificing flexibility. Whether you're working with async native environments or need synchronous support, our SDK has got you covered.

Check it out: https://lnkd.in/dC32nWWj

Of course it's far from being perfect, but I'll constantly work on making it better and better! Stay tuned for updates on what comes next! 👾

🌟 Let's shape the future of AI together! Contributions to LLM-Client-SDK are welcome.
SIMPLE & EFFICIENT Java Solution BEATS 95%
Tags: java, beginners, programming, tutorial
Published: 2023-06-05 16:35:10

# Intuition
To solve this problem, I need to keep track of the value of x and update it according to the operations in the array.
# Approach
I will use a variable x to store the value of x and initialize it to zero. Then I will loop through the array of operations and use a switch statement to check each operation and increment or decrement x accordingly.

# Complexity
- Time complexity:
The time complexity is $$O(n)$$ where n is the length of the array, because I need to iterate through all the operations once.

- Space complexity:
The space complexity is $$O(1)$$ because I only use a constant amount of extra space for the variable x.

# Code
```JAVA
class Solution {
 public int finalValueAfterOperations(String[] operations) {
 int x = 0;
 int size = operations.length; // store the size of the array
 for (int i = 0; i < size; i++) { // use the size variable
 String operation = operations[i]; // store the operation in a variable
 switch (operation) { // use switch statement
 case "++X":
 case "X++":
 x++;
 break;
 case "--X":
 case "X--":
 x--;
 break;
 }
 }
 return x;
 }
}

```
Lookup disk properties on linux
Tags: linux, performance, internals
Published: 2023-06-05 16:21:51

When using linux systems, there sometimes is a need to understand the exact disk properties. One reason is to be able to understand IO read and write size, and how it affects latency.

Linux uses buffered IO by default. That means that any read or write request will use the cache. The cache in linux is completely automatic, essentially consisting of non-allocated memory. However, in most cases buffered IO will also require memory when there is memory shortage.

To understand which block device a filesystem is using, use the `lsblk` command:
```shell
$ lsblk
NAME               MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                  8:0    0 39.1G  0 disk
├─sda1               8:1    0    1G  0 part /boot
└─sda2               8:2    0 38.1G  0 part
  ├─almalinux-root 253:0    0   36G  0 lvm  /
  └─almalinux-swap 253:1    0  2.1G  0 lvm  [SWAP]
```
In this case the `lsblk` command tells me I got one disk (sda), with two partitions (sda1 and sda2). The disk here therefore is `sda`.

The disk exposes a lot of its properties via `/sys/block/<DISK>/queue`, such as:

- The disk maximum IO size: `max_hw_sectors_kb` (readonly).
- The disk current maximum IO size: `max_sectors_kb` (read-write).
- The disk IO queue size: `nr_requests` (read-write).
- The disk read-ahead size: `read_ahead_kb` (read-write).
- The scheduler for the disk: `scheduler` (read-write).
- Is the disk (set as/considered) to be on a rotating disk: `rotational' (readonly).
- Is the disk (set as/considered) to be on dax (writeable persistent memory): `dax` (readonly).

Read-write and readonly:
- 'read-write' means it's a setting that can be manipulated.
- 'readonly' means it's a property read by the driver from the underlying "hardware".
This week focus: Documentation
Tags: programming, documentation, ruby, rails
Published: 2023-06-05 16:13:03

Whenever you open a piece of code try to find a place where you can describe how that class or that feature can be used by fellow developers.

Focus on usage examples or use cases.

**You can start small with a PR description.**

Add some examples of usage in the PR description. This will be an easy start without any pressure, and it can be edited as required based on feedback from your colleagues.

**Add examples using YARD**

Another way is to use YARD structure to write before a class or method directly:

```ruby
# @example How to make this use case work
#    
#    t = http://MyObect.new(...)
#    t.run(email_param: "test")
#    
```

Try to write an example that, when copied/pasted to `irb` or `rails console` will work.

I like this because most IDEs know how to show YARD examples while writing the code and thus you will have examples of usage for your classes while typing.

**Write documentation in markdown format**

If you don't like to write documentation inside your code files, put your documentation outside your code files.

The easiest is to create a `./docs` folder inside your project and write in a markdown file. Both Github and Gitlab already know how to render markdown files thus you will have browsable and searchable documentation without any extra effort.

In case you want something more fancy [mdBook](https://rust-lang.github.io/mdBook/index.html) looks very good for providing a way to display this documentation.

### The best is to start anywhere

There are maybe other ways to write documentation. Focus this week on this. You will thank yourself in a couple of weeks if you will need to change the code you wrote today if you wrote documentation about it somewhere.

---

Enjoyed this article?

Join my [**Short Ruby News**](https://shortruby.com) **newsletter** for weekly Ruby updates. Also, check out my co-authored **book**, [**LintingRuby**](https://lintingruby.com), for insights on automated code checks. For more Ruby **learning resources**, visit [**rubyandrails.info**](https://rubyandrails.info).
CSS Framework KIBA-CSS
Tags: css, html, webdev, cssframework
Published: 2023-06-05 16:02:32

Hey,
I've created a small CSS framework called KIBA, which combines BEM with utilities.
https://kiba-css.com
My motivation in short: BEM alone is too rigid, and in large projects, it leads to a lot of repetition of the same CSS rules. Frameworks that rely solely on utility classes become quite cumbersome in terms of readability as the project grows. I believe that combining both approaches is a great solution. While this is not a new concept, I haven't seen it implemented as a framework before.

KIBA-CSS is still in its earliest stages and will continue to evolve. However, I thought it would be valuable to seek feedback from experts in this community. I don't want to write a lengthy post here, so I invite you to take a look at it and share your thoughts on the idea. :) Thank you.
Looking forward to your feedback /discussions/ questions. ;)
Binder Trace: a tool for intercepting and parsing Android Binder messages
Tags: linux, tooling, programming, python
Published: 2023-06-05 15:57:32

## Binder Trace

Binder Trace is a tool for intercepting and parsing Android Binder messages. Think of it as "Wireshark for Binder".

## ⚙️ Installation

You'll need a rooted Android device or emulator.

(Linux only) - install xclip or xsel for "copy to clipboard" functionality

```
sudo apt-get install xclip
sudo apt-get install xsel`

```
Clone the repo and install python dependencies

```
pip install -r binder_trace/requirements.txt

```
Check which version of frida is installed (make sure you've pip installed the requirements)

```
pip list | grep frida

```
Download the matching version of frida-server from the frida releases page

Make sure adb is running as root, push frida-server to your device and run it

```
adb root

adb push frida-server /data/local/tmp

chmod u+x /data/local/tmp/frida-server

adb shell /data/local/tmp/frida-server
```



## ▶️ Starting binder trace

To start binder trace we need to pick a device and process to attach to. In the following example we use adb and frida-ps to identify a process to attach to on a local emulator. As it's an Android 11 emulator we choose the Android 11 structs directory. Pick the struct directory that most closely matches your version of Android. If you would like structures for a different version of Android, please let us know. Once it's running start using the target app to generate some binder transactions.

> adb devices
List of devices attached
emulator-5554   device

> frida-ps -Ua
 PID  Name           Identifier
----  -------------  ----------------------------
8334  Messaging      com.android.messaging
7941  Phone          com.android.dialer
9607  Settings       com.android.settings

> cd binder_trace
> python -m binder_trace -d emulator-5554 -n Messaging -s ../structs/android11

## ⌨️ Controls

Key	Action
up	Move up
down	Move down
shift + up	Page up
shift + down	Page down
home	Go to top
end	Go to bottom
tab	Next pane
shift + tab	Previous pane
ctrl + c	Copy pane to clipboard
f	Open filter options
h	Open help
q	Quit

## 🔎 Filtering

If you're interested in specific messages you can filter the displayed results with the following options.

Interface - limit results to interfaces that contain the case sensitive search string e.g. "com.android" or "Sms".
Method - limit results to function names containing the specified case sensitive string.
Type - Limit results to certain types of messages e.g. requests or responses.
Once you've entered your filter options just press Enter to apply them.
[Download](https://github.com/foundryzero/binder-trace)
Adam Argyle Presents CSS Features for 2023 and beyond!
Tags: webdev, javascript, beginners, podcast
Published: 2023-06-05 15:48:09


Original: https://codingcat.dev/podcast/3-14-adam-argyle-presents-css-features-for-2023-and-beyond

{% youtube https://youtu.be/RxVJ2Oj1IWk %}

## Questions

1. Can you tell us more about yourself?
2. Last time we talked was December 2021, how is [Open Props](https://open-props.style/) doing?
3. What will you be doing for Google I/O this year?
4. Next Gen Color?
5. Tell us about [gradient.style](http://gradient.style)

## Links

* [Card Stacks](https://gui-challenges.web.app/card-stack/dist/)
* [Nerdy.dev](https://nerdy.dev/)
* [6 CSS snippets every front-end developer should know in 2023](https://web.dev/6-css-snippets-every-front-end-developer-should-know-in-2023/)

### At Container Query

`@container` is a new css selector

```css
.panel {
	container: layers-panel / inline-size;
}

.card {
	padding: 1rem;
}

@container layers-panel (min-width: 20rem) {
	.card {
		padding: 2rem;
	}
}

```

## Scroll Snap

Well orchestrated scroll experiences set your experience apart from the rest, and [scroll snap](https://developer.mozilla.org/docs/Web/CSS/scroll-snap-type) is the perfect way to match system scroll UX while providing meaningful stopping points.

```css
.snaps {
	overflow-x: scroll;
	scroll-snap-type: x mandatory;
	overscroll-behavior-x: contain;
}

.snap-target {
	scroll-snap-align: center;
}

.snap-force-stop {
	scroll-snap-stop: always;
}

```

## Grid Pile

[Grid Pile](https://web.dev/shows/gui-challenges/m4DKhRJeYx4/)

```css
.pile {
	display: grid;
	place-content: center;
}

.pile > * {
	grid-area: 1/1;
}

```

## Easy Circle

```css
.circle {
	inline-size: 25ch;
	aspect-ratio: 1;
	border-radius: 50%;
}

```

## Control variants with @layer

You probably have seen this if you are using TailwindCSS

```css
/* file buttons.css */
@layer components.buttons {
  .btn.primary {
    …
  }
}

```

## Memorize less and reach more with logical properties

Memorize this one new box model and [never have to worry](https://css-tricks.com/late-to-logical/) about changing left and right padding or margin for international [writing modes](https://developer.mozilla.org/docs/Web/CSS/writing-mode) and [document directions](https://developer.mozilla.org/docs/Web/CSS/direction) again. Adjust your styles from physical properties to logical ones like [padding-inline](https://developer.mozilla.org/docs/Web/CSS/padding-inline), [margin-inline](https://developer.mozilla.org/docs/Web/CSS/margin-inline), [inset-inline](https://developer.mozilla.org/docs/Web/CSS/inset-inline), and now the browser will do the adjusting work.

```css
button {
	padding-inline: 2ch;
	padding-block: 1ch;
}

article > p {
	text-align: start;
	margin-block: 2ch;
}

.something::before {
	inset-inline: auto 0;
}

```
Does anyone can help me to start with the #javascript ?
Tags: javascript
Published: 2023-06-05 15:47:24

Hello, does anyone here work as a JS developer? I wish i could speak to some of such people. I have a problem if i start learning JS using the YouTube videos, after the ending of the course i have some knowledge but i don't understand where shoul i go and what should i learn. So if anyone can be literally mine mentor and answer my questions permanently - i'll get tired of saying "thank you"::))
How a truck driver witnessed miracle of Neeb Karori Baba
Tags: hindu
Published: 2023-06-05 15:46:27

<p><span style="background-color: #fcff01;">&nbsp;<b>The Story</b></span></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDdKbAIP-ZMhoiJhSA3G0FSl2YvzOkHNeG226_SlTTpNAR0__bJZdkry-B6ymagiR_r2tKtum_XSOo_D76gE1qKQ9ZOzLfddy9ytyLyEOKW0nsm8bc3-s685AzLrMs0s7vawEVHTU7tviTWNkQrzJD8Eafe_l-s8i2cO7PeS3uqgAezfklIDyjTnSOvg/s1600/vibes.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="630" data-original-width="1600" height="164" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDdKbAIP-ZMhoiJhSA3G0FSl2YvzOkHNeG226_SlTTpNAR0__bJZdkry-B6ymagiR_r2tKtum_XSOo_D76gE1qKQ9ZOzLfddy9ytyLyEOKW0nsm8bc3-s685AzLrMs0s7vawEVHTU7tviTWNkQrzJD8Eafe_l-s8i2cO7PeS3uqgAezfklIDyjTnSOvg/w417-h164/vibes.png" width="417" /></a></div><br /><p>Once there was a truck driver who was surpassing Babaji's Dham in Nainital called Kainchi Dham. Suddenly he felt quite hungry and there was occasion </div><br /><p><br /></p>
[Read More](https://hungryworldera.blogspot.com/2023/06/how-truck-driver-witnessed-miracle-of.html)
Designing a Full-Featured Web Synthesizer
Tags: architecture
Published: 2023-06-05 15:45:00

## Recap

I ended my last post with a working prototype of a Rust and WebAssembly based synthesizer using `wasm-pack` to build the JavaScript wrappers. Now that the prototype is complete, it's time to start designing and building a more feature-complete synthesizer.

This update will be short compared with previous entries.

## Architecture

Here is an overview of the architecture I plan to use for the synthesizer.


![Design Diagram](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q6suovwkoh7ld9horgci.png)

The entry point for the synthesizer will be a wrapper struct that starts the process of fully synthesizing the sound:

The wrapper starts by sending information about  the note that should be playing to the oscillator bank which will use that information to generate the initial audio buffers. From there, the audio buffer will be passed along the chain of modifiers to apply filters and other transformations to the audio. Finally, the audio buffer will be returned to the wrapper to be passed back to the best available audio device.

## Why this design?

I chose this design to keep the code base as flexible as possible. I eventually want to turn the synthesizer into a plugin for [digital audio workstations](https://en.wikipedia.org/wiki/Digital_audio_workstation). To achieve that goal, I want to make the design as generic as possible so that it will be easily compatible with many different plugin formats.