dgplug member blogs

Reader

Read the latest posts from dgplug member blogs.

from sandeepk

I’ve been working on a few side projects and using ChatGPT for ideation and brainstorming around ideas and features for the MVP. As part of this, I needed a logo for my app. Naturally, I turned to AI to help me generate one.

However, I noticed that when generating images, ChatGPT doesn’t always follow the guidelines perfectly. Each time I asked for a new version, it would create a completely different image, which made it difficult to iterate or make small tweaks.

But I found a better way.

Instead of generating a brand new image every time, I first explained my app idea and the name. ChatGPT generated an image I liked.

So I asked ChatGPT to generate the JSON for the image instead. I then manually tweaked the JSON file to adjust things exactly the way I wanted. When I asked ChatGPT to generate the image based on the updated JSON, it finally created the image as per my request — no random changes, just the specific adjustments I needed.

Exploration Phase

SplitX logo

{
  "image": {
    "file_name": "splitX_icon_with_text.png",
    "background_color": "black",
    "elements": [
      {
        "type": "text",
        "content": "SplitX",
        "font_style": "bold",
        "font_color": "white",
        "position": "center",
        "font_size": "large"
      },
      {
        "type": "shape",
        "shape_type": "X",
        "style": "geometric split",
        "colors": [
          {
            "section": "top-left",
            "gradient": ["#FF4E50", "#F9D423"]
          },
          {
            "section": "bottom-left",
            "gradient": ["#F9D423", "#FC913A"]
          },
          {
            "section": "top-right",
            "gradient": ["#24C6DC", "#514A9D"]
          },
          {
            "section": "bottom-right",
            "gradient": ["#514A9D", "#E55D87"]
          }
        ],
        "position": "center behind text",
        "style_notes": "Each quadrant of the X has a distinct gradient, giving a modern and vibrant look. The X is split visually in the middle, aligning with the 'Split' theme."
      }
    ]
  }
}

Final Design

SplitX logo Updated JSON

{
  "image": {
    "file_name": "splitX_icon_with_text.png",
    "background_color": "transparent",
    "elements": [
      {
        "type": "shape",
        "shape_type": "X",
        "style": "geometric split",
        "colors": [
          {
            "section": "top-left",
            "gradient": [
              "#FF4E50",
              "#F9D423"
            ]
          },
          {
            "section": "bottom-left",
            "gradient": [
              "#F9D423",
              "#FC913A"
            ]
          },
          {
            "section": "top-right",
            "gradient": [
              "#24C6DC",
              "#514A9D"
            ]
          },
          {
            "section": "bottom-right",
            "gradient": [
              "#514A9D",
              "#E55D87"
            ]
          }
        ],
        "position": "center ",
        "style_notes": "Each quadrant of the X has a distinct gradient, giving a modern and vibrant look. The X is split visually in the middle, aligning with the 'Split' theme."
      }
    ]
  }
}

If you want to tweak or refine an image, first generate the JSON, make your changes there, and then ask ChatGPT to generate the image using your updated JSON. This gives you much more control over the final result.

Cheers!

P.S. Feel free to check out the app — it's live now at https://splitx.org/. Would love to hear what you think!

 
Read more...

from titas

Hello people of the world wide web.
I'm Titas, a CS freshman trying to learn programming and build some cool stuff. Here's how I understood the importance of open source.

The first time I heard of open source was about 3 years ago in a YouTube video, but I didn't think much of it.
Read about it more and more on Reddit and in articles.

Fast forward to after high school — I'd failed JEE and had no chance of getting into a top engineering college. So I started looking at other options, found a degree and said to myself:
Okay, I can go here. I already know some Java and writing code is kinda fun (I only knew basics and had built a small game copying every keystroke of a YouTube tutorial).
So I thought I could learn programming, get a job, and make enough to pay my bills and have fun building stuff.

Then I tried to find out what I should learn and do.
Being a fool, I didn't look at articles or blog posts — I went to Indian YouTube channels.
And there was the usual advice: Do DSA & Algorithms, learn Web Development, and get into FAANG.

I personally never had the burning desire to work for lizard man, but the big thumbnails with “200k”, “300k”, “50 LPA” pulled me in.
I must’ve watched 100+ videos like that.
Found good creators too like Theo, Primeagen, etc.

So I decided I'm going to learn DSA.
First, I needed to polish my Java skills again.
Pulled out my old notebook and some YT tutorials, revised stuff, and started learning DSA.

It was very hard.
Leetcode problems weren't easy — I was sitting for hours just to solve a single problem.
3 months passed by — I learnt arrays, strings, linked lists, searching, sorting till now.
But solving Leetcode problems wasn't entertaining or fun.
I used to think — why should I solve these abstract problems if I want to work in FAANG (which I don't even know if I want)?

Then I thought — let's learn some development.
Procrastinated on learning DSA, and picked up web dev — because the internet said so.
Learnt HTML and CSS in about 2-3 weeks through tutorials, FreeCodeCamp, and some practice.

Started learning JavaScript — it's great.
Could see my output in the browser instantly.
Much easier than C ,which is in my college curriculum (though I had fun writing C).

Started exploring more about open source on YouTube and Reddit.
Watched long podcasts to understand what it's all about.
Learnt about OSS — what it is, about Stallman, GNU, FOSS.
OSS felt like an amazing idea — people building software and letting others use it for free because they feel like it.
The community aspect of it.
Understood why it's stupid to have everything under control of a capitalist company — who can just one day decide to stop letting you use your own software that you paid for.

Now I’m 7 months into college, already done with sem 1, scored decent marks.
I enjoy writing code but haven't done anything substantial.
So I thought to ask for some help. But who to ask?

I remembered a I've heard about this distant cousin Kushal who lives in Europe and has done some great software and my mother mentioned him like he was some kind of a genius .I once had a brief conversation with him via text regarding if I should take admission in BCA than an engineering degree, and his advice gave me some motivation and positivity . He said:

“BCA or Btech will for sure gets a job faster Than tradional studying If you can put in hours, that is way more important than IQ.
I have very average IQ but I just contributed to many projects.”

So 7 months later, I decided to text him again — and surprisingly, he replied and agreed to talk with me on a call.
Spoke with him for 45 odd minutes and asked a bunch of questions about software engineering, his work, OSS, etc.

Had much better clarity after talking with him.
He gave me the dgplug summer training docs and a Linux book he wrote.

So I started reading the training docs.

  • Step 0: Install a Linux distro → already have it ✅
  • Step 1: Learn touch typing → already know it ✅

Kept reading the training docs.
Read a few blog posts on the history of open source — already knew most of the stuff but learnt some key details.

Read a post by Anwesha on her experience with hacking culture and OSS as a lawyer turned software engineer — found it very intriguing.

Then watched the documentaries Internet's Own Boy and Coded Bias.
Learnt much more about Aaron Swartz than I knew — I only knew he co-founded Reddit and unalived himself after getting caught trying to open-source the MIT archives.

Now I had a deeper understanding of OSS and the culture.
But I had a big question about RMS — why was he so fixated on the freedom to hack and change stuff in the software he owned?
(Yes, the Free in FOSS doesn’t stand for free of cost — it stands for freedom.)

I thought free of cost makes sense — but why should someone have the right to make changes in a paid software?
Couldn't figure it out.
Focused on JS again — also, end-semester exams were coming.
My university has 3 sets of internal exams before the end-semester written exams. Got busy with that.

Kept writing some JS in my spare time.
Then during my exams...

It was 3:37 am, 5 June. I had my Statistics exam that morning.
I was done with studying, so I was procrastinating — watching random YouTube videos.
Then this video caught my attention:
How John Deere Steals Farmers of $4 Billion a Year

It went deep into how John Deere installs software into their tractors to stop farmers and mechanics from repairing their own machines.
Only authorized John Deere personnel with special software could do repairs.
Farmers were forced to pay extra, wait longer, and weren’t allowed to fix their own property.

Turns out, you don’t actually buy the tractor — you buy a subscription to use it.
Even BMW, GM, etc. make it nearly impossible to repair their cars.
You need proprietary software just to do an oil change.

Car makers won’t sell the software to these business owners, BUT they'll offer 7500$/year subscriptions to use their software. One auto shop owner explained how he has to pay $50,000/year in subscriptions just to keep his business running.

These monopolies are killing small businesses.

It’s not just India — billion-dollar companies everywhere are hell-bent on controlling everything.
They want us peasants to rent every basic necessity — to control us.

And that night, at 4:15 AM, I understood:

OSS is not just about convenience.
It’s not just for watching movies with better audio or downloading free pictures for my college projects.
It’s a political movement — against control.
It’s about the right to exist, and the freedom to speak, share, and repair.


That's about it. I'm not a great writer — it's my first blog post.

Next steps?
Learn to navigate IRC.
Get better at writing backends in Node.js.
And I'll keep writing my opinions, experiences, and learnings — with progressively better English.

print("titas signing out , post '0'!")
 
Read more...

from sandeepk

1. Why did you make the blog in the first place?

This blog initially started as part of the summer training by DGPLUG, where the good folks emphasize the importance of blogging and encourage everyone to write—about anything! That motivation got me into the habit, and I’ve been blogging on and off ever since.

2. What platform are you using to manage your blog and why did you choose it?

I primarily write on WriteFreely, hosted by Kushal, who was kind enough to host an instance. I also occasionally write on my WordPress blog. So yeah, I have two blogs.

3. Have you blogged on other platforms before?

I started with WordPress because it was a simple and fast way to get started. Even now, I sometimes post there, but most of my recent posts have moved to the WriteFreely instance.

4. How do you write your posts?

I usually just sit down and write everything in one go. Followed by editing part—skimming through it once, making quick changes, and then hitting publish.

5. When do you feel most inspired to write?

Honestly, I don’t wait for inspiration. I write whenever I feel like it—sometimes in a diary, sometimes on my laptop. A few of those thoughts end up as blog posts, while the rest get lost in random notes and files.

6. Do you publish immediately after writing or do you let it simmer a bit as a draft?

It depends. After reading a few books and articles on writing, I started following a simple process: finish a draft in one sitting, come back to it later for editing, and then publish.

7. Your favorite post on your blog?

Ahh! This blog post on Google Cloud IAM is one I really like because people told me it was well-written! :)

8. Any future plans for your blog? Maybe a redesign, changing the tag system, etc.?

Nope! I like it as it is. Keeping it simple for now.

A big thanks to Jason for mentioning me in the challenge!

Cheers!

 
Read more...

from mrinalraj

Hey there! 👋 Welcome to my personal insights from the incredible Aero India 2025 event held at Yelahanka Air Base, Bengaluru! 🇮🇳✨ Buckle up, and let’s dive into this high-flying adventure! 🛩️🔥


🌅 Early Bird Adventures

Woke up super early ⏰ to beat the traffic towards Yelahanka ✨
Quickly grabbed some breakfast 🥪☕ and rushed to the bus stop 🚌
Took a connection via Hebbal ➡️ and then headed straight to Yelahanka Air Base 🚏🛫


👫 New Friends & Quick Access

Met some amazing people on the way 👋 — especially Shelja from HAL 👩‍🔧 who helped me get into the ADVA area swiftly 🔐💨
Such warmth and camaraderie! ❤️


🪑 Perfect Spot for Viewing

There were special seating arrangements 🎟️ with a direct view of the majestic birds in the sky 🛫🦅
There was a major buzz around:

  • 🇷🇺 Su-57
  • 🇺🇸 F-35
  • 🇮🇳 Hansa-S performing jaw-dropping aerobatics 🔄🎯

The sky was on 🔥 with excitement!


📅 How You Can Experience It Too!

🗓️ Dates: 10th – 14th Feb 2025
🎫 Single-Day Entry Passes Only

💼 Business Pass

  • Access to: Exhibitions (IDEX), Seminars, and Air Show (ADVA)
  • ❌ Excludes invite-only events (like Raksha Mantri Dinner, CEO Meet)
  • 💸 Cost: ₹5000/day

🎟️ ADVA Pass

  • Access to: Air Show and select exhibitions
  • ❌ May not include halls with foreign exhibitors (🇮🇱 Israel, 🇫🇷 Safran, 🇬🇧 Rolls-Royce, etc.)
  • 💸 Cost: ₹1000/day

🧑‍🤝‍🧑 General Pass

  • Access to: ADVA + Exhibitions
  • Only valid on: 4th & 5th day of the event
  • 🚸 Expect it to be crowded
  • 💸 Cost: ₹2500/day

🎫 My Experience with the Business Pass

Got myself a Business Pass 😎
Went straight to ADVA after a thorough bag check 🧳🔍
💡 Pro Tip: You can carry your own water bottle & snacks (chips, etc.) 💦🍿

By 11:45 AM, the air show was done 💥
I dashed over to the Exhibition Hall 🏛️ where I saw:

  • The mighty 🇮🇳 Kaveri Engine
  • Cutting-edge defense tech usually not open to public 👀📸

And yes, photography was allowed! 📷✨


🎤 Tech Talks & Seminars

After a bit of a hunt 🧭 I found the Seminar Hall
Was warmly welcomed 🤝 and walked into a room filled with:

  • 🪖 Top military generals
  • 💼 Business leaders from GE, Rolls-Royce, Safran

It was just wow — an incredible energy of innovation and strategy in the room! 🌐⚙️


🏁 Conclusion

This was a once-in-a-lifetime event 💫
I met brilliant minds 🧠, saw next-gen tech 🔧, and watched thrilling air stunts in real-time 🛩️💨

Highly recommend not missing this epic celebration of India's aviation might 🇮🇳✈️


💬 Got questions or want to connect?
📧 Reach me at: [email protected]
Let the skies inspire you! 🌤️🇮🇳

 
Read more...

from mrinalraj

Scenario

Folks! Have you ever wondered how to create a URL that always points to your router, even when its public IP address changes? It might sound complex and costly, but it's actually free!

Concept

This involves setting up Dynamic DNS (DDNS).

What you need

  1. A Wi-Fi Router supporting NO-IP as DDNS
  2. An account on NO-IP website

Steps for creating hostname in NO IP:

  1. Login to NO-IP website. Make sure to avoid use of special character in the password.
  2. Create a hostname.
  3. We are Done!!!

Steps for configuring DDNS in router:

  1. Login to your router with credentials.
  2. Navigate to DDNS which would possibly under Internet tab.
  3. Configuring DDNS. 3.1 Keep WAN Connection as 'auto'. 3.2 Provider: 'No-IP' 3.3 Username: 3.4 Password: 3.5 Hostname: Give the newly created hostname
  4. We are Done!!!

Testing

Reboot your router and verify if NO IP website is showing the recent router's public IP.

Result

Now every time your router public IP changes it would reflect the recent IP on the website.

Usage

NO-IP provides a free DDNS hostname that can be used in projects instead of the router's public IP address. Simply confirm the renewal email after 30 days.

Thank you !!! Follow Mrinal

 
Read more...

from mrinalraj

Scenario

Imagine wanting to stream video from a device behind your home router to your personal phone over the internet. This may sound like a complex task, but with port forwarding, it's simpler than you think.

What you need:

  1. A Wi-Fi Router
  2. A computer displaying the video feed connected to the Wi-Fi router
  3. A VNC viewer on your remote mobile device

The Solution:

Port forwarding is the secret sauce that makes this setup seamless. Here's how you can do it:

Steps:

Router –> Computer –> Display | Internet –> Mobile –> VNC

  1. Lets Visualize the network diagram as above.
  2. Be physically near your router.
  3. Login your Wi-Fi router with credentials.
  4. Navigate to Port Forwarding section. It must be in the Security section.
  5. Set the Port forwarding rules 5.1. Service Name: Give the port forwarding rule a descriptive name. 5.2. Port Range: Specify the range of ports you want to forward (e.g., 5900- 5901 for a single port). 5.3. Local IP Address: Enter the IP address of the device on your local network that you want to forward the ports to. Refer my previous post on How to make a connected device static. 5.4. Protocol: Select the protocol for the port forwarding rule (TCP, UDP, or both). 5.5 Keep WAN HOST IP as 0.0.0.0

We are done here!!! See its that simple. Lets now test it over is my port open? website.

On Personal Mobile over Internet

  1. Install VNC over mobile phone
  2. Enter the router public IP followed by port number eg. 24.57.121.123:5900
  3. Suppose you don't have a router public IP address handy you can get it from what's my IP address? website.
  4. Above IP means that in the router public IP, connect to device at port 5900
  5. Enter credentials and we are done!!!

Limitation

  1. Since your router IP changes after reboot. Refer my previous post on How to get free url for Router's public IPs
  2. If the local device streaming feed is not static. It me loose the IP after device restart. Making device static is better solution. Refer my previous post on How to make a connected device static.

Thank you !!! Follow Mrinal

 
Read more...

from mrinalraj

Scenario

I recently needed to establish a static IP for my Python project to facilitate SSH access. The issue I faced was that DHCP kept assigning a new IP every time my system rebooted.

I discovered that we can set the IP address to be static, and the steps for doing so are outlined below:

About:

dhcpcd.conf:

Location: /etc/dhcpcd.conf Usage: DHCP client daemon is used towards the client side to configure the interfaces.

while

dhcpd.conf

Location: /etc/dhcp/dhcpd.conf Usage: It acts as server for dynamically assigning IPs to devices in the network

Step 0: Setup dhcpcd:

Install: sudo apt-get install dhcpcd Enable: sudo systemctl enable dhcpcd sudo systemctl start dhcpcd Verify: sudo systemctl status dhcpcd

Step 1: Open the dhcpcd.conf file

sudo nano /etc/dhcpcd.conf

If your project uses Wi-Fi, proceed with the following steps; otherwise, replace the interface name accordingly. interface wlan0 static ip_address=your_desired_static_ip/24 static routers=your_router_ip static domain_name_servers=your_dns_server_ip or interface wlan0 static ip_address=your_desired_static_ip/24 static routers=192.168.0.1 static domain_name_servers=192.168.0.1 8.8.8.8

Replace “your_desired_static_ip”, “your_router_ip”, and “your_dns_server_ip” with the appropriate values for your network. Ensure you choose an IP address that is not already in use on your network.

How to get router ip: Refer whats my ip address?

How to get the dns server: On terminal do nslookup google.com

Note: you need to have package 'dnsutils' installed. (sudo apt-get install dnsutils)

Step 2: Restart the dhcp service

sudo service dhcpcd restart or do sudo reboot

 
Read more...

from mrinalraj

Scenario

I recently wanted my Python program to execute right after the system boots up. I discovered several options to achieve this, eliminating the need for manual intervention to run the program.

Option 1: Editing through Crontab

  1. Open a terminal with elevated privileges: sudo su -
  2. Edit the crontab configuration: crontab -e
  3. Add the following command to start the Python program (assuming you want to run it on a Raspberry Pi terminal): ```bash
  4. @reboot /usr/bin/python3 /path/to/your/script.py

Option 2: Editing through services using systemd

  • Create a script, name it as “myscript.sh”
  • Make the script executable: chmod +x myscript.sh
  • Navigate to the systemd directory: cd /etc/systemd/system/
  • Create a service file named “myscript.service” inside the systemd directory.
  • And below lines using nano myscript.sh
Description=My Script

[Service]
ExecStart=/path/to/myscript.sh
WorkingDirectory=/path/to/
StandardOutput=inherit
StandardError=inherit
Restart=always
User=<replace_username>

[Install]
WantedBy=multi-user.target
  • Reload systemd: sudo systemctl daemon-reload
  • Enable the service: sudo systemctl enable myscript.service
  • Start the service: sudo systemctl start myscript.service
  • To check the service status: sudo systemctl status myscript.service

Option 3: Autostart using lxsession

  • Edit the autostart configuration file: nano ~/.config/lxsession/LXDE-pi/autostart
  • Add the following line to automatically start the Python script: @lxterminal -e python3 /path/to/your/script.py
  • Save the file and initiate a system reboot: sudo reboot
 
Read more...

from sandeepk

In CSS, combinators are used to select content by combining selectors in specific relationships. There are different types of relationships that can be used to combine selectors.

Descendant combinator

The descendant combinator is represented by a space “ ” and typically used between two selectors. It selects the second selector if the first selector is the ancestor (parent, parent parent's) element. These selectors are called the descendant selectors.

.cover p {
    color: red;
}
<div class="cover"><p>Text in .cover</p></div>
<p>Text not in .cover</p>

In this example, the text “Text in .cover” will be displayed in red.

Child combinators

The child combinator is represented by “>” and is used between two selectors. In this, an element is only selected if the second selector is the direct child of the first selector element. This means there should not be any other selector between the first selector element and second element selector.

ul > li {
    border-top: 5px solid red;
} 
<ul>
    <li>Unordered item</li>
    <li>Unordered item
        <ol>
            <li>Item 1</li>
            <li>Item 2</li>
        </ol>
    </li>
</ul>

In this example, the <li> element with the text “Unordered item” will have a red top border.

Adjacent sibling combinator

The adjacent sibling combinator is represented by “+” is placed between the two CSS selector. In this element is selected if the selector element is directly followed by the first element selector or only the adjacent sibling

h1 + span {
    font-weight: bold;
    background-color: #333;
    color: #fff;
    padding: .5em;
}
<div>
    <h1>A heading</h1>
    <span>Veggies es bonus vobis, proinde vos postulo essum magis kohlrabi welsh onion daikon amaranth tatsoi tomatillo
            melon azuki bean garlic.</span>

    <span>Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea sprouts fava bean collard
            greens dandelion okra wakame tomato. Dandelion cucumber earthnut pea peanut soko zucchini.</span>
</div>

In this example, the first element will have the given CSS properties.

General sibling combinator

The general sibling combinator is represented by “~“. It selects all the sibling element, not only the direct sibling element, then we use the general sibling combinator.

h1 ~ h2 {
    font-weight: bold;
    background-color: #333;
    color: #fff;
    padding: .5em;
}
<article>
    <h1>A heading</h1>
    <h2>I am a paragraph.</h2>
    <div>I am a div</div>
    <h2>I am another paragraph.</h2>
</article>

In this example, every <h2> element will have the given CSS properties.

CSS combinators provide powerful ways to select and style content based on their relationships in the HTML structure. By understanding combinators, we can create clean, maintainable, and responsive web designs.

Cheers!

ReferencesMDN Web Docs

#CSS #Combinators #WebDevelopment #FrontendDev

 
Read more...

from sandeepk

Today, I decided to analyze my bank account statement by downloading it from the day I opened my bank account. To my surprise, it was presented as a web page. Initially, my inner developer urged me to write code to scrape that data. However, feeling a bit lazy, I postponed doing so.

Later in the evening, I searched the web to find an alternate way to extract the data and discovered that HTML tables can be converted to CSV files. All I had to do was save the code in CSV format. I opened the Chrome browser's inspect code feature, copied the table, saved it with the CSV extension, and then opened the file with LibreOffice. Voila! I had the spreadsheet with all my transactions.

Cheers!

#TIL #CSV #HTML Table

 
Read more...

from sandeepk

The Debug Diary – Chapter I

Lately, I was debugging an issue with the importer tasks of our codebase and came across a code block which looks fine but makes an extra database query in the loop. When you have a look at the Django ORM query

jato_vehicles = JatoVehicle.objects.filter(
    year__in=available_years,<more_filters>
).only("manufacturer_code", "uid", "year", "model", "trim")

for entry in jato_vehicles.iterator():
    if entry.manufacturer_code:
        <logic>
    ymt_key = (entry.year, entry.model, entry.trim_processed)
...

you will notice we are using only, which only loads the set of fields mentioned and deferred other fields, but in the loop, we are using the field trim_processed which is a deferred field and will result in an extra database call.

Now, as we have identified the performance issue, the best way to handle the cases like this is to use values or values_list. The use of only should be discouraged in the cases like these.

Update code will look like this

jato_vehicles = JatoVehicle.objects.filter(
    year__in=available_years,<more-filters>).values_list(
    "manufacturer_code",
    "uid",
    "year",
    "model",
    "trim_processed",
    named=True,
)

for entry in jato_vehicles.iterator():
    if entry.manufacturer_code:
        <logic>
    ymt_key = (entry.year, entry.model, entry.trim_processed)
...

By doing this, we are safe from accessing the fields which are not mentioned in the values_list. If anyone tries to do so, an exception will be raised.

** By using named=True we get the result as a named tuple which makes it easy to access the values :)

Cheers!

#Django #ORM #Debug

 
Read more...

from abbisk

Variable

Variable is a way to refer to memory locations being accessed by a computer program. In languages like C, C++, Java, a variable is a name given to a memory location. So when we say:

int x;
float y;

This small piece of code asks the compiler to create memory space for the variables, 4 bytes each (the size depends on the compiler and programming language). The variables are basically names assigned to the memory location, if the variable is defined for a particular data type then only declared type data can be stored in it. But in python, we do not need to declare a variable beforehand like int x, we can straightaway move to define the variable and start using it like x = 10. alt text

Now the point is, how does Python know what is the type of the variable and how to access it? In Python, data types (integer, list, string, functions, etc. ) are objects and every object has a unique id that is assigned to it, at the time of object creation. Variables are references (pointers) to these objects. What happens when we say :

x = 10
  • Python executes the right-hand side of the code
  • Identifies 10 to be an integer
  • Creates an object of Integer class
  • Assigns x to refer to the integer object 10 alt text

Now if we create new variable y which is equal to x, what do you think happens internally?

y=x

y now refers to the same object as x. alt text

How do we know that? It can be verified by checking the id of the object that these two variables x and y are pointing to.

id(y) == id(x)
# output
True

We can also print the id of the object

print(f"id of the object pointed by x:{id(x)}")
print(f"id of the object pointed by y:{id(y)}") 

# output
#your id value might be different from mine but the two ids printed must be the same
id of the object pointed by x:140733799282752 
id of the object pointed by y:140733799282752

Now, what if we assign a different value to y?

y=40

This will create another integer object with the value 40 and y will now refer to 40 instead of 10. alt text How to check Again, we will use id() to see the ids of the objects.

print(x) # outputs 10
print(y) # outputs 40
print(f"id of the object pointed by x:{id(x)}")
print(f"id of the object pointed by y:{id(y)}")  

# output
id of the object pointed by x:140733799282752
id of the object pointed by y:140733799283712

As we can see from above, the two ids are now different which means a new object with value 40 is created and y refers to that object now.

If we wish to assign some other value to variable x

x = "python"
print(id(x))

# output
1783541430128

We will get an object id that is different from the id “140733799282752” printed by id(x) for integer object 10 previously.

So what happened to the integer object 10? The integer object 10 now remains unreferenced and can no longer be accessed. Python has a smart garbage collection system that looks out for objects that are no longer accessible and reclaims the memory so that it can be used for some other purpose. alt text One last question: What if we create two integer objects with the same value?

p = 100
q = 100

Before I answer this question. Let's check their ids:

print(f"id of the object pointed by x:{id(p)}")
print(f"id of the object pointed by y:{id(q)}") 
# output
id of object pointed by x:140733799285632
id of object pointed by y:140733799285632

So what python does is optimize memory allocation by creating a single integer object with value 100 and then points both the variables p and q towards it.

Let's check one more example-

m = 350
n = 350

print(f"id of object pointed by x:{id(m)}")
print(f"id of object pointed by y:{id(n)}") 

# output
id of the object pointed by x:1783572881872
id of the object pointed by y:1783572881936

To our surprise the ids of the integer object 300 referred to by m and n are different. What is going on here?? Python allocates memory for integers in the range [-5, 256] at startup, i.e., integer objects for these values are created and ids are assigned. This process is also known as integer caching. So whenever an integer is referenced in this range, python variables point to the cached value of that object. That is why the object id for integer object 100 referenced by p and q print the same ids. For integers outside the range [-5, 256], their objects are created as and when they are defined during program implementation. This is the reason why the ids for integer object 350 referenced by m and n are different. As mentioned earlier, variables point to the objects stored in memory. Hence variables are free to point to object of any type.

x = 10 # x points to an object of 'int' type
x = ["python", 20, "apple"] # x now points to an object of type 'list'
x = "python" # x now points to a string type object

I hope you enjoyed reading it. Feel free to suggest improvements to the article or any other topic that you would like to know more about.

 
Read more...

from abbisk

Free Software

“Free” software “is software that can be used, studied, and modified,” copied, changed with little or no restriction, and which can be copied and redistributed in modified or unmodified form. Free software is available gratis (free of charge) in most cases. “In practice, for software to be distributed as free software, the human-readable form of the program (the source code) must be made available” along “ with a notice granting the” user permission to further adapt the code and continue its redistribution for free. This notice either grants a “free software license”, or releases the source code into the public domain.

Open-Source Software

In the beginning, all software was free in the 1960s, when IBM and others sold the first large-scale computers, these machines came with software which was free. This software could be freely shared among users, The software came written in a programming language (source code available), and it could be improved and modified. Manufacturers were happy that people were writing software that made their machines useful. Then proprietary software dominated the software landscape as manufacturers removed access to the source code. IBM and others realized that most users couldn’t or didn’t want to “fix” their own software and There was money to be made in leasing or licensing software. By the mid-1970s almost all software was proprietary “Proprietary software is software that is owned by an individual or a company (usually the one that developed it). There are almost always major restrictions on its use, and its source code is almost always kept secret.” users were not allowed to redistribute it, source code is not available users cannot modify the programs. Software is an additional product that was for sale In 1980 US copyright law was modified to include software In late 1970s and early 1980s, two different groups started what became known as the open-source software movement: East coast, Richard Stallman (1985), formerly a programmer at the MIT AI Lab, launched the GNU Project and the Free Software Foundation. “to satisfy the need for and give the benefit of ‘software freedom’ to computer users ultimate goal of the GNU Project was to build a free operating system the GNU General Public License (GPL) was designed to ensure that the software produced by GNU will remain free, and to promote the production of more and more free software.

 
Read more...

from darshna

A few months ago I came to know that pycon was happening in Chennai on the month of October, and I realized that attending this year's PyCon is necessary. Deep down I knew that after returning from Pycon I'll not only make new connection and potential people but also it'll change my perspective about the open-source world(in a good way). Also this was my first time that I'll be moving out from my home town, I asked mom that this will be a great opportunity for my exposure of life and experience, as unfortunately there's not much stuff happening in my college(except mass bunking and unnecessary gossip). And my Durga puja was over, packed my bags and left for Chennai. After 27 hours of a long journey, I reached the station, where communicating with people was a bit tough, but my ecstasy was unlimited of meeting that part of India(South). I couldn't sleep that night, I woke up early morning and got ready and reached the venue with one of my folks (@priyankasaggu) from dgplug. When I reached there I was amazed at the crowd which gathered there, I took my id card, and went in the venue, people were everywhere are. Earlier I didn't notice that goodies were being distributed if you play quiz from the respective booths of sponsors. At the evening after the event got over we (dgplug) members went to beach and spent some good time together. It was day 2 and coincidently I met some new friends who were from Kerala and thet were of my same batch and of same stream. So, I attended the keynote speaker who was Ines Montani, and yeah I did not understand everything as clear as water but yes, I did get an idea. And at the end of the day, we all the folks of dgplug went for dinner and enjoyed our meals and some quality time together.

Overall, my experience if I rate out of 10, it will 10/10...yeah every penny i spent to come here, every hour of my journey I spent to come here was worth it...Before coming to PyCon 2k19, I asked myself that none of my friends came from my college.. will it be worth it? Now I know yes it was worth it!

 
Read more...

from jason’s wotw blog

wotw, leisure

And to tell the truth I
don't want to let go of
the wrists of idleness, I
don't want to sell my life
for money, I don't even
want to come in out of
the rain.

And with this delightful Mary Oliver quote, this little blog, bids you adieu awhile.
I want to go and play in the rain :)

 
Read more...
OSZAR »