/r/ProgrammerTIL

Photograph via snooOG

Learn something new? Wanna share? Post here along with the language/framework you learned it in.

This is a great place for novice and advanced programmers alike to come and discover all the interesting things they could learn tomorrow ;)

Learn something new? Wanna share? Post here along with the language/framework you learned it in.

This is a great place for novice and advanced programmers alike to come and discover all the interesting things they could learn tomorrow


  Sort by language C# Java Javascript PHP .NET C++ Python C Objective-C R Swift VBA Visual Basic Matlab Ruby Perl ScalaDelphi lua SQL Other Languages Other

 

Remove filter


  Learn something about technology? Post it on r/technologytil

Learn something about real life or something not programming? Post it on the original /r/todayilearned


  Rules

  1. TIL posts should be made in the following format:

[programming language] TIL rest of post...

If you don't you'll need to flair your post manually.

  • Refrain from putting two languages in between the brackets in the title.

  • Don't post suggestion threads, message the moderators instead.

  • This isn't an AskProgrammers sub, ask questions on /r/learnprogramming

  • Don't use the code as the title.


  •  

    Guidelines

    1. Try not to post vague titles, if possible, provide the name of the feature in the title so people aren't clicking on your post because of "this fast and clever way to do x" that they already knew but didn't realize it's what you where going to show.

    2. Don't criticize posts because they're "too obvious", not everyone here is a level 100 master champion Assembly programmer that made their own OS from scratch.

    3. General programming TILs should be tagged with [General].

    4. Be nice to your fellow programmers. :)

    /r/ProgrammerTIL

    38,219 Subscribers

    0

    Code Quality - Essential Metrics To Track Explained

    The article below explores code quality metrics as an objective measure of code quality, identify areas for improvement, track progress over time, and enable data-driven decision-making: Code Quality Excellence: Essential Metrics

    0 Comments
    2024/05/03
    08:33 UTC

    4

    [C#] Switch On String With String Cases

    I knew you could use a switch with a string and I thought you could also have case statements that were strings. I was wrong:

    //This works

    switch( s )

    {

    case "abc123":

    break;

    }

    //This doesn't

    string stringCase = "abc123";

    switch( s )

    {

    case stringCase:

    break;

    }

    But you can use pattern matching to get it to work:

    string stringCase = "abc123";

    switch( s )

    {

    case string x when x == stringCase:

    break;

    }

    1 Comment
    2024/04/26
    20:55 UTC

    3

    Telegram founder runs competitive coding platform contest.com

    Telegram founder was interviewed by Trung Phan. Surprising that he actually first started contest.com and that's his funnel to hire engineers in his team (just total of 30 employees)

    2 Comments
    2024/04/18
    17:54 UTC

    8

    Today I Q-learned!

    For one of my final projects this semester I had to read about and code a q-learning algorithm (the q-learning algorithm? Not sure). For anyone who was like me 48 hours ago and has never heard of it, q-learning is a method of reinforcement learning that aims to discern the best possible action to take in a given state. A state, for the purposes of my assignment, was an individual position on a square grid, like this:

    12 13 14 15
    8  9  10 11
    4  5  6  7
    0  1  2  3

    What a state is can be defined in other ways, that's just how we were doing it for this assignment. So the goal is to, from any random start position, get to the goal. The goal is currently defined as the highest value state (15 in the example above). Originally the agent could only move up, down, left, and right, but I added diagonal movement as well. These movements are the actions I mentioned earlier. So together, the states and the actions form the q-table, something like this:

    State  up  down  left  right  ul  ur  dl    dr
    0      1   0     0     1      0   1   0     0
    1      1   0     0.1   1      0.1 1   0     0
    ...
    14     0   0.1  -0.1   5      0   0  -0.1  -0.1
    15     0   0     0     0      0   0   0     0

    The values in the q-table represent potential future rewards for taking an action in a given state. So we see moving up from state 0 has a q-value of 1, which for the purposes of this example we'll say is a very positive reward. We can also see that moving left from state 1 has a q-value of 0.1, while we can move there and still get a reward, it might not happen right away. The q-value has a bias toward events in the present while considering potential events in the future. Lastly, notice that moving left from 14 has a q-value of -0.1, that is considered a penalty. In the reward function I wrote I rewarded moving closer to the goal, but you could also penalize moving away from the goal.

    The reward function is what determines the potential reward in a given state. For my assignment I gave it a reward for hitting a randomly place "boost", for moving toward the goal, and for reaching the goal. I also penalized moving into a "trap", of which many were randomly spread around the map.

    Once the model was trained, I created an agent to walk through the grid from a randomly chosen spot, just as the model was trained, and had it move using the best moves as determined by the q-table once it was trained. That...sort of worked. But there are times when traps are too scary and rewards are too tempting and the agent gets stuck pacing back and forth. So after trying about a million different things I decided to give my agent a memory, so this time as it walked through grid world it kept track of the path it took. One of the aspects of the q-learning algorithm is the concept of exploration vs exploitation. Exploring new options vs exploiting existing knowledge. In order for my agent to take advantage of that as well, I added in the same conditions for choosing to make the best decision or a new decision that I used to train the model. So, combined, those two things meant that when it chose to explore a new option, it would move into a state not already on it's path. That mostly worked, but there were still times it would get stuck because of some quirk of the training that resulted in the q-table suggesting the agent move to an adjacent space with an almost equal reward and then getting stuck in a cycle. So then I made my agent learn from it's mistakes. If the q-table suggested that the agent move to a state that it had already been in, the q-value associated with making that move would be lowered.

    That seemed to do it! I know there's still SOOOO much more to explore with this topic and I'm so excited but I need to go to sleep and just had to info dump lol. I had my script spit out a bunch of graphs and stitch them into a gif which I will post a link to in the comments

    3 Comments
    2024/04/12
    11:15 UTC

    0

    Dataset

    Hello everyone,

    I'm looking for a dataset containing data from a business, specifically from a minimarket or a store.

    I've checked some sources like Kaggle and the UCI Machine Learning Repository, but so far, I haven't found a dataset that fits my needs. I need a dataset that contains at least 1 million records to conduct meaningful analysis. The dataset can be in either Spanish or English.

    If you know of any sources where I can find this type of dataset or if you have access to one that you can share, I would greatly appreciate it. Any help or suggestions would be greatly appreciated for my project.

    0 Comments
    2024/04/02
    01:23 UTC

    2

    Python (Noob-Mid) to Java

    Today I spent one day to port my MacOS Tiny Useful Toolkit for my personal usage that I originally wrote in Python to Java because my friend asked me questions about his com. sci. homework in Java, but I realized that I don't know Java and the best way to understand the syntax is to do a project on it, so I did this C:

    My Original Toolkit (Python)
    https://github.com/litszwaiboris/toolkit

    New Toolkit (Java)
    https://github.com/litszwaiboris/toolkit4java

    (I also learnt maven when trying to compile)

    1 Comment
    2024/03/07
    02:28 UTC

    0

    Free Technology and Programming Courses

    Free Technology and Programming Courses

    Gain In-Demand Skills with Free Technology and Programming Courses"

    Meta Description: "Boost your career prospects with our curated selection of free technology and programming courses. Learn valuable skills in popular languages like Python and JavaScript, and stay ahead of the curve in a fast-paced industry. Start learning today and enhance your resume with relevant and up-to-date knowledge.

    https://formationgratuite.net/Technology-and-Programming

    1 Comment
    2024/01/22
    13:01 UTC

    34

    TIL: A tiny difference between document.getElementByID and document.querySelector

    I have an element with randomly generated UUIDs as HTML element id.

    In JavaScript, I would do document.querySelector('#' + id) and it sometimes worked, but not always. It turns out, that it worked, as long as the first character was not numerical.

    let id = "037e3778-e157-4715-bff5-e466230fe7a3"
    
    const byId = document.getElementById(id) console.log(byId) // works
    
    const bySelectorConcat = document.querySelector("#" + id) console.log(bySelectorConcat) 
    // Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '#037e3778-e157-4715-bff5-e466230fe7a3' is not a 
    valid selector.
    
    const bySelector = document.querySelector(#${id}) console.log(bySelector) 
    // Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '#037e3778-e157-4715-bff5-e466230fe7a3' is not a valid selector.

    The simple fix was basically to rewrite the code:

    let id = "037e3778-e157-4715-bff5-e466230fe7a3"
    
    const querySelectorFixed = document.querySelector([id='${id}']) console.log(querySelectorFixed)
    
    // better approach const querySelectorEscaped = document.querySelector(#${CSS.escape(id)}) console.log(querySelectorEscaped)

    I wrote this on my TIL: https://kiru.io/til/entries/2024-01-16-javaScript-difference-querySelector-and-getElementById/

    4 Comments
    2024/01/16
    13:48 UTC

    0

    Invitation for Tech Professionals to Conduct Seminar at PUP

    Hello there!

    The students of Polytechnic University of the Philippines, pursuing Bachelor of Science in Information Technology at Quezon City Campus, are actively seeking experienced professionals in the field of Technology to serve as Guest Speakers for an upcoming seminar.

    We are particularly interested in individuals currently working in roles such as Web Marketing Manager or Security Analyst. We believe that your expertise and experiences would greatly benefit our students.

    Seminar Details:

    • Target Month: February or March

    • Duration: TBA

    • Topics: Current and noteworthy subjects within the speaker's field of expertise.

    In appreciation of your contribution, we will provide a certificate acknowledging your participation in educating our 2nd and 3rd-year students.

    Additionally, we are seeking experts who are willing to sign a Memorandum of Agreement (MOA) to formalize the collaboration for this activity.

    For further details and to express your interest, please do send a direct message here or send an e-mail to my e-mail address for more details, we're hoping for your positive response!

    Contact Information:

    Email: reymarkcalexterio@iskolarngbayan.pup.edu.ph

    0 Comments
    2024/01/12
    15:19 UTC

    14

    TIL about [Cosmopolitan]: A [C] build-once-run-anywhere (Mac, Windows, Linux, etc...) framework to allow [C] programs behave as if they had a VM

    0 Comments
    2023/12/30
    19:18 UTC

    8

    From Transistor to CPU – How computers really work

    In this playlist you can find an explanation about how a CPU works. CPU is a quite complex and sophisticated component so the best is describing a simple version of CPU. Here we analyze Scott’s CPU which is perfect for educational purpose. We are going to build a CPU together step by step.

    https://youtube.com/playlist?list=PLnAxReCloSeTJc8ZGogzjtCtXl_eE6yzA

    2 Comments
    2023/12/29
    08:39 UTC

    0

    Two level branch prediction, can anyone help me with this C code

    1 Comment
    2023/11/18
    09:38 UTC

    0

    Most important problem-solving Algorithms in C#

    0 Comments
    2023/11/06
    11:50 UTC

    0

    Demystifying Software Architecture: A Journey Begins

    Join me on a journey into the world of software architecture! 🚀 I've just published an article that demystifies the core concepts of software architecture. Dive in and discover the vital role it plays in shaping the digital world. Let's explore together! 👉 Read More

    1 Comment
    2023/10/24
    07:24 UTC

    0

    🧠 Mastering the Bellman-Ford Algorithm: Code, Apps, and Insights 🌐

    Uncover the secrets of the Bellman-Ford algorithm! Dive into code examples in Python, Golang, and TypeScript, explore real-world applications, and learn how to handle negative cycles. Your guide to mastering shortest path algorithms in data networks. 🚀 Read the article here: https://blog.kelynnjeri.me/a-journey-through-the-bellman-ford-algorithm-navigating-the-maze

    0 Comments
    2023/10/22
    16:53 UTC

    2

    Unlock the Power of Bipartite Graphs: Mastering Maximum Matchings with Hopcroft-Karp, Hungarian, and More [Golang]

    Hey Reddit Community,
    🔗 Article Link: Read the Full Article
    Are you ready to dive deep into the world of graph algorithms? We've just published an in-depth article that explores the fascinating realm of bipartite graphs and their applications in solving real-world problems.
    🤯 In this comprehensive guide, we cover popular algorithms like Hopcroft-Karp, Hungarian Method, Blossom Algorithm, Dinic's Algorithm, and the Fast Bipartite Matching Algorithm. You'll discover how these algorithms work, their time and space complexities, and when to use each one.
    💡 Highlights of the Article:
    🧩 Learn how to match elements efficiently in bipartite graphs.
    🚀 Explore the Hopcroft-Karp Algorithm's elegance and performance.
    🧮 Master the Hungarian Method for solving assignment problems.
    🌸 Unveil the power of the Blossom Algorithm for matching in general graphs.
    ⚙️ Discover the efficient Dinic's Algorithm and Fast Bipartite Matching Algorithm.
    Whether you're a computer science enthusiast, a data scientist, or a developer seeking practical solutions, this article is a valuable resource for your algorithmic toolkit.
    Join the discussion, ask questions, and share your insights in the comments section of the article. Let's unlock the secrets of maximum matchings together!
    Ready to take your graph algorithm skills to the next level? Read the full article now: Read the Full Article
    Don't miss out on this opportunity to deepen your understanding of these powerful algorithms. Like, share, and let's engage in a meaningful conversation about bipartite graphs and matching algorithms!

    0 Comments
    2023/10/06
    20:54 UTC

    1 Comment
    2023/10/04
    08:44 UTC

    12

    TIL JavaScript provides string interpolation with string template literals

    I started learning JavaScript in 2012 before this was full supported, never realized the backtick was used in JavaScript. It works great

    const number = 2
    const message = `The number is ${number}`
    console.log(message); // => 'The number is 2'

    3 Comments
    2023/10/02
    16:25 UTC

    6

    TIL React Strict mode renders components twice

    3 Comments
    2023/09/20
    06:54 UTC

    0

    Im new studying programming

    Peoplee, can you send me exercise to do in C code?, i only know how to do a little back end. Be gentle

    5 Comments
    2023/09/19
    00:42 UTC

    0

    Pro tip: DO NOT use string literals in your code unless they end up in some form of output

    Basically the title. Every time you write a string literal like "Foo" in your IDE think about whether it's actually used to show something to the user, written to a file, send over network, reprogram a hardware device etc. If not, delete it immediately and think about better code structure. Do not use strings to access data in dicts, as state constants, parameter names etc. This only creates technical debt and there are much better type safe ways to do this. Start thinking about quality today.

    19 Comments
    2023/09/13
    14:16 UTC

    2

    Is UML an actual full Time job?

    17 Comments
    2023/08/31
    19:31 UTC

    10

    Understanding and Overcoming Programmer Imposter Syndrome in Software Developers

    The following guide shows how creating a supportive work environment an help mitigate the effects of imposter syndrome: Understanding and Overcoming Programmer Imposter Syndrome in Software Developers

    It explains dealing with imposter syndrome as a continuous process involving individual effort and organizational support, and how, with awareness, action, and resilience, software developers can navigate through their feelings of self-doubt and imposter syndrome, harnessing their full potential in the tech world.

    1 Comment
    2023/08/29
    16:10 UTC

    12

    I'm trying to recreate the pseudo 3D road effect used in OutRun(1986)

    Since my teenage years I have been trying to understand the mechanics behind the video game OutRun. Now, 25 years later I've tried to figure it out by trying to implement the game using the basic knowledge of trigonometry learned in high school.

    I have taken the opportunity to explain the entire development process in a series of very simple and visual video tutorials on my YouTube channel.

    I thought this might be of interest to some developer curious about those algorithms used during the 80's and 90's, just for fun.

    https://youtu.be/JPbz-575BS4

    * Subtitles available in English, Spanish and Catalan.

    I hope you enjoy it as much as me!
    Albert,

    1 Comment
    2023/08/18
    11:22 UTC

    0

    Referral

    Hi everyone, Does your company support referral program? Like if you recommend someone for a job does your company give you money and how much?

    2 Comments
    2023/08/13
    13:00 UTC

    0

    dependency injection is like sipping global variables through a straw

    really more like an insight, or perhaps even a showerthought.

    am I way off?

    4 Comments
    2023/08/06
    17:50 UTC

    0

    What computer do you use?

    I’m new to programming and I am looking for a computer that would be efficient enough to run large projects but not cost an arm and a leg. I plan on working my way up to build bigger projects like an AI, etc.

    Update: Thank you everyone for the helpful answers. Some of us would’ve liked a little more information so here we go.

    I’m looking for less than $1,000 for now, upgradeable in the long run for when I do run huge projects. The language I plan to use, and know, is Python.

    18 Comments
    2023/06/16
    20:12 UTC

    11

    how to compute the developmental cost of a mobile application for startups

    hello developers of reddit. i’m a computer engineering student and i need help for my research paper. the thing is, me and my group mates made an application that classifies the batch of a bean (50 pcs per image and it classifies 20 types of classification of beans. it includes the color, grade, and damaged beans) when uploaded or taken through the camera of the application. the other features are, it has a register and login, bottom navigation, and navigation drawer. we made the app in android studio using kotlin language. so it’s only compatible in android devices. can i ask the marketability of the app? supposed that we are startups and someone wants to buy the application from us. should we include the money we spent when we were gathering the data and the time spent as well? I once saw a research paper wherein they made a research focused on hardware then what they did was they compute the total cost of the materials + 20% of the mark-up value. is that applicable to us? if no, then how will we compute for the software/mobile application???

    btw i’m from the philippines and we already searched for the possible price but we cannot just simply say that it’s Php 150,000 (based on google, the mobile application for startups is around Php150,000-Php300,000). thank you.

    6 Comments
    2023/06/11
    17:00 UTC

    27

    Shortcut to forward standard output and error to another command in bash

    You have command in bash and want to pipe the output and error to another command. Usually I would do like this:
    > command 2>&1 | tee -a log.txt

    This will pipe the error and output to tee, which will append it into log.txt and print it to the console as well.
    There exists a shortcut in bash 4 (via this answer):
    > command |& tee -a log.txt

    I put it here as well: https://kiru.io/til/entries/2023-06-05-shortcut-to-forward-standard-output-and-error-to-another-command/

    0 Comments
    2023/06/05
    17:03 UTC

    0

    [Javascript] Learned how to build an LLM app with node and react

    I built a simple React app with a Node server that connects to Open AI's large language model (LLM). Sharing a tutorial of how to build this LLM React and Node app by following an LLM React and Node javascript template

    Tutorial: https://blog.golivecosmos.com/build-an-llm-app-with-node-react-and-langchain-js/

    Github repo with project template: https://github.com/golivecosmos/llm-react-node-app-template

    0 Comments
    2023/05/29
    16:49 UTC

    Back To Top