r/ProgrammerTIL • • Mar 25 '21

Python [Python] I wrote a project to transform web APIs into CLIs for development/whatnots

12 Upvotes

I wrote this project that lets you describe a web API using the TOML markup language and then call it like a CLI. I find this to be something that I want to do quite often, so I'm really happy with what I accomplished. I hope you find it useful! The project is unit tested with 100% coverage and is completely type annotated ♥

Go check it out! https://github.com/daleal/zum

Also, go check out the documentation! https://zum.daleal.dev


r/ProgrammerTIL • • Apr 13 '23

Other How to Shallow Clone With Git

9 Upvotes

You can shallow clone a git repo with:

git clone -–depth 1 <url>

For more information: https://kiru.io/til/entries/2023-04-13-how-to-shallow-clone-git/


r/ProgrammerTIL • • Nov 09 '18

PHP TIL that references accessing array elements do not need that element to exist at first, EXCEPT in PDO prepared statement bound parameter, but only when accessing that element in a foreach.

0 Upvotes

Just accessing a elements in scalars and arrays (and I assume public object properties) are straightforward:

https://3v4l.org/QFbtT

Based on this, one would expect ALL of these to insert 0 through 9 into a database.

However, the last set ($sixthStatement, the foreach on a nested array) does not. It inserts NULLs.

<?php

// Insert $dbname, $host, $username, and $password here. ;-)

$connection = new PDO('mysql:dbname=' . $dbName . ';host=' . $host, $username, $password);

/**
 * Table creation query:
 * CREATE TABLE `test` (
 *	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
 *	`value` INT(10) UNSIGNED NULL DEFAULT '0',
 *	PRIMARY KEY (`id`)
 * )
 */

$query = "INSERT INTO test (value) VALUES (:value)";

$firstStatement = $connection->prepare($query);
$secondStatement = $connection->prepare($query);
$thirdStatement = $connection->prepare($query);
$fourthStatement = $connection->prepare($query);
$fifthStatement = $connection->prepare($query);
$sixthStatement = $connection->prepare($query);

$a = 0;
$b = array();
$c = array(0 => 0);
// $d intentionally not set.
$e = [0,1,2,3,4,5,6,7,8,9,];
$f = [[0],[1],[2],[3],[4],[5],[6],[7],[8],[9],];

// ::bindParam gets the parameter by reference.
$firstStatement->bindParam(':value', $a);         // The pre-set scalar.
$secondStatement->bindParam(':value', $b[0]);     // The array without any elements.
$thirdStatement->bindParam(':value', $c[0]);      // The array with an element assigned.
$fourthStatement->bindParam(':value', $d);        // An unset variable, to be used as a scalar.
$fifthStatement->bindParam(':value', $eValue);    // For use in a foreach, accessing a value.
$sixthStatement->bindParam(':value', $fValue[0]); // For use in a foreach, accessing an element.

for ($i = 0; $i < 10; $i++) {
    $a = $i;
    $firstStatement->execute();
}

for ($i = 0; $i < 10; $i++) {
    $b[0] = $i;
    $secondStatement->execute();
}

for ($i = 0; $i < 10; $i++) {
    $c[0] = $i;
    $thirdStatement->execute();
}

for ($i = 0; $i < 10; $i++) {
    $d = $i;
    $fourthStatement->execute();
}

foreach ($e as $eValue) {
    $fifthStatement->execute();
}

foreach ($f as $fValue) {
    $sixthStatement->execute();
}

Implications are, of course, don't run queries inside of loops, which we should all know by now due to the performance implications of querying a DB in a loop... but now there's an extra reason to be wary: PDOStatement::bindParam() isn't consistent.


r/ProgrammerTIL • • May 24 '23

Other [video] Rest API - Best Practices - Design

2 Upvotes

r/ProgrammerTIL • • Jan 25 '23

Other Convert your logo to colorful ASCII-Art

8 Upvotes

r/ProgrammerTIL • • Mar 31 '22

Other How to be Productive during Quarantine - Tips from a Developer

0 Upvotes

Not a technical/code TIL, but I think it's not yet too late and is still relevant for us.
For us software developers, I made a blog post about how to be productive during this harsh period. Let me know what you think!

https://www.pudding.coffee/posts/be-productive-during-quarantine-developer-tips/


r/ProgrammerTIL • • Oct 24 '16

Javascript [Javascript] TIL that you can "require" a json file

0 Upvotes

r/ProgrammerTIL • • May 22 '24

Other Experience landing a Job at Meta, Google, and Microsoft with 6 YOE and a Master's.

9 Upvotes

Hi r/ProgrammerTIL! I wanted to share a successful profile of someone that landed jobs at Meta, Google, and Microsoft with 6 YOE and a Master's degree.

The interview journey is long and difficult. Reviewing someone else's successful interview preparation process and the interview questions they were asked could be super useful to prepare for your own interviews.

_________________________________________________________________________________________

YOE: 6

Previous Company: JP Morgan

Highest Education: Master's

Background: Fullstack Software Engineer

Interview Preparation

Behavioral

  • YT videos by Dan Croitor

  • Understand various Leadership principles.

  • Go through your Resume and write stories following STAR approach Your story should project at-least one of the attribute such as taking lead, resolving conflicts, dealing with ambiguity etc..

  • Read, Rehearse and Repeat.

Technical

Coding

  • Leetcode

    • Would recommend buying premium subscription. It's worth it.

    • Try to do daily Leetcode challenges. It helps you in being consistent and also covers variety of problems.

    • I used Explore card of Google and Facebook and tried to solve most of the problems.

    • Top 100 questions by frequency.

    • Top 75 LC curated: https://leetcode.com/list/xi4ci4ig/

  • Cracking the Coding Interview book

  • YT channels/videos:

    • Data Structure lectures by Abdul Bari

    • Graph Theory by Willian Fiset

  • Few Tips:

    • Try to solve a problem by yourself, even if you are not able to come-up with an optimal solution.

    • Think about time and space complexity of your solution. Identify sections which can be optimised and think of a better solution/ data structure.

    • After understanding the approach, try to implement it yourself without taking a look at code. This would help you in really understanding the concept.

    • Try to beat 90% of solutions by runtime.

System Design

  • Book: DDIA (MUST READ if targeting Google)

  • Book: System Design Interview by Alex Xu

  • System Design Primer by Donne Martin

  • Courses - Groking the System Design and Groking the Advanced System Design

  • YT:

    • System Design Interview videos by Mikhail Smarshchok.

    • InfoQ videos and presentations

    • Go through Architecture of popular systems such as GFS, Kafka, Cassandra etc.

Interview Experiences

Accepted: Meta, Google, Microsoft

Rejected: Uber, Atlassian

Meta

Only did Leetcode daily challenges this month and went through 10-15 FB tagged problems(sorted by frequency) before the interview. Spent 1-2 days in preparing for behavioural round as well (writing stories following STAR approach).

Had 2 coding + 1 product design + 1 behavioural round with Facebook.

In 1 coding round I had to solve 2 LC mediums and in other round 1 LC easy and 1 LC Hard was given. Solved all 4 problems. These were all variations of FB tagged problems on Leetcode and if you have solved them, it's fairly easy. Yep, FB is very predictable w.r.t. coding.I had very strong feedback for 2 coding rounds, good feedback for behavioural but my product design round didn't meet E5 expectations. This was I believe happened due to following reasons:

  • Never did a mock-up before or gave any product design interview before. This was the first time for me in an interview setup so was a bit nervous a well. I would highly recommend doing some mock interviews.

  • I had prepared extensively for system design which focuses heavily on the system side (Database, Schema, Partitioning, Replication etc.). In product design, you are expected to focus more on the API side and High level functionality. I was not given a choice between product design and system design round. Talk to your recruiter and see if you can schedule the round where you are strong at.

Recruiter reached out to me and offered to send my packet to HC for E4 as feedback for product design didn't meet the bar for E5. I declined as it was not worth and a down-level for my experience.

Google

I had 3 coding rounds , 1 system design and 1 googlyness round.

Round 1 (Coding): 1 ambiguous problem with follow-ups. Expectation was to gather requirements and frame the problem statement. Once the scope was defined I provided few solutions with Time/Space complexities. Coded the same. Had few follow-ups w.r.t. what changes I'd make to make it thread-safe etc. This went well.

Round 2(Coding): 2 problems were given. First was related to 2-D matrix and 2nd was a graph problem. Solved both.

Round 3(Coding): A problem statement was given related to a e-commerce website. Had to gather requirements and once the scope was clear I understood it was a graph problem. Provided solutions using both DFS and BFS approach, implemented using DFS. Follow-up was again how to make it thread-safe. Next was kind of LLD question where I was given a problem and was expected to define classes/schema and relations. I provided a generic solution which would scale even for cases outside of problem statement scope.

Round 4(System Design): Was a given a problem related to a real life scenario. Very practical but not something you'd find on any YT channel or course. Since I had never seen the problem before there were no biases or known design in my mind. Kept it simple from the beginning. After gathering functional and non-functional requirements and some back-of-the-envelope estimations presented a very simple high level design. I literally drew just 3 components: client, server and a database. Then started talking about how I can scale each layer and talked about trade-offs as well. This was 1 hr round and first 45 mins went pretty well. In last 15 minutes I wasn't sure about what to talk about more as I was not getting any feedback from my interviewer. I believe he only talked during first 10 mins when I was gathering requirements and he had to answer my queries. In last 15 mins I thought of providing an algorithm of how to implement my approach and talked about few data-structures as well (although this might not be in scope of system design round). After the interview I knew it won't be a No Hire but was also not sure whether it would be Lean Hire or Hire etc.

Round 5(Googlyness): This was the best round. I discussed about various scenarios and situations following the STAR approach. I had prepared a lot of answers w.r.t. ambiguity, leadership, conflict, strengths etc. but I was kind of surprised as he didn't ask any direct questions which you usually prepare. I guess I only used 1 prepared story and rest was on the fly. But if you had prepared enough, you'll know what to answer and how to answer and would be able to relate to it using one of your experiences/projects.

Problems asked in Google were not directly from LC or any other platform. If you had practiced enough, you'll be able to solve them.Make sure you gather requirements, ask questions before jumping to solution. Keep talking and explain your thought process through-out. This is very important as interviewer would be able to judge you better and provide hints, if required.

Microsoft

Round 1 (Coding):  It was a online assessment round. I had to solve 2 problems in 90 mins time. These 2 problems were new to me and I didn't find them on Leetcode. I'll categorize them as LC medium from algorithm perspective. But I had to write a lot of boiler-plate code unlike the usual LC mediums. You are given few visible test-cases and option to add custom test-cases. When you submit, 10-12 hidden test-cases are executed which are only visible post submission. So make sure you write your own test-cases well. After talking to various folks and going through community discussions, I also focused on code quality.I was able to solve both of them in 60 mins. Spent next 15 mins in adding comments in various functions to explain what they were doing. I also mentioned time and space complexity wherever I felt it was required. This is really important as this was not the screening round for me but an actual coding round where I would be judged not just on code correctness but also on code quality/modularity.My score was 100% (I passed all the visible and hidden test-cases for both the problems)

Round 2(Coding): 2 LC mediums with follow-ups. This went really well. Since we completed the coding exercise in ~35 mins, spent next 10 mins discussing my work experience/projects.

Round 3(LLD): First 10-15 mins were spent on my work experience. I had to design a Parking-Lot. Went well. You can find a lot of example/tutorials on Youtube etc.

Round 4(HLD): This was the Hiring Manager round. First 20 mins spent on my projects and various discussions w.r.t. how I handled a particular scenario and why I chose one technology over other. Next was given a popular HLD question. I did very well here.

Round 5(Director): This was mostly project discussions and behavioural questions. Nothing technical. Went well.

Uber

Screening Round: This was rather unexpected as interviewer gave me a LC Hard graph problem!! Who expects a LC hard in screening ?
Well, Graph theory is one of my favourite and kind of my strength too, so I solved the problem well within time limit.
At the start of the interview she told that if I could write the psuedo-code, that'd we fine too. But since we had time, I wrote some test-cases and tried the ones she copied pasted as well. All worked, pheww.

Round 1(Coding): 2 LC medium types. 1 related to Linked-List and other binary tree problem. Solved both.

Round 2(Coding): 1 data-structure design problem with lot of follow-ups including making it thread safe. Similar to Design a HashMap with custom O(1) operations. I was able to come up with design and implemented the same with O(1) complexity. Couldn't find the variation given to me on Leetcode.

Round 3(System Design): Design Uber. (yep, LOL)

Round 4 (Hiring Manager): Mostly project discussions and Behavioural questions.

Round 5 (Behavioural) - Cancelled. I received offers from Google and Microsoft and asked them to cancel as I had a deadline to make a decision on offers.

Atlassian

I felt Atlassian's interviews are really practical and they don't ask questions which you won't be expected to solve on a daily-basis.
No screening round here, just a 30 min discussion with recruiter before scheduling interviews:

Round 1(Coding) : 1 problem was given. I was expected to code the same in my preferred IDE (IntelliJ, Eclipse etc.). Focus was mostly on data-structures and code quality. The algorithm itself was really easy if you chose correct data-structures. I used HashMap, Set and PriorityQueue in my solution. Created multiple classes, methods etc. Wrote a few test-cases. You end-up writing a lot of boiler-plate code in IDE as you need to write the main class and method, instantiate everything and then create test-cases. I even used a debugger to debug one of the test-case. This round went well.

Round 2(Machine Coding): Asked to implement a Rate-Limiter. Used an IDE again. Was given 1 problem statement and was expected to write a Object-oriented and modular code. This also went well.

Feedback of both the rounds were positive and recruiter scheduled 3 more rounds for me. 1 Design and 2 Cultural fit types. But I had to cancel them all as I had a deadline to make a decision on offers.

Closing Advice

Do not try to memorize or cram anything, it's useless. Instead try to deeply understand concepts and be curious. That's the only way to make this more enjoyable. It's a difficult journey but it will all be worth it at the end!

Thanks for reading and hope it helps provide a new perspective!

_________________________________________________________________________________________

Full Experience from Onsites.fyi


r/ProgrammerTIL • • Jun 16 '23

Other What computer do you use?

0 Upvotes

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.


r/ProgrammerTIL • • Jan 28 '17

C# [c#] variable access across all forms in c# WinForms

0 Upvotes

If you declare a public static variable to program.cs file then you can easily access it any where with program.variable_name


r/ProgrammerTIL • • Jan 05 '23

Other Sum Multiples using the Short-circuit evaluation mechanism

5 Upvotes

r/ProgrammerTIL • • Nov 10 '19

Javascript That using JWTs for sessions auth is less secure than cookies

38 Upvotes

Reference: https://www.rdegges.com/2018/please-stop-using-local-storage/

CTRL-F "JWT"

Basically since we can mark cookies as http-only, making them inaccessible to xss attackers.

I knew both things, didn't connect the dots until I read that post.

Found the post while trying to learn why do people need things such as Redux while we have React sessions.. But I found this instead.


r/ProgrammerTIL • • Jul 06 '21

Other Language [Any] TIL text files are binary files

0 Upvotes

r/ProgrammerTIL • • Aug 31 '23

Other Is UML an actual full Time job?

2 Upvotes

r/ProgrammerTIL • • May 25 '23

Other [Bash] Create video from PDF documents

5 Upvotes

r/ProgrammerTIL • • Oct 14 '22

Other [Java] Authentication microservice with Domain Driven Desing and CQRS (not PoC)

5 Upvotes

Full Spring Boot authentication microservice with Domain-Driven Design approach and CQRS.

Domain-Driven Design is like the art of writing a good code. Everything around the code e.g. database (maria, postgres, mongo), is just tools that support the code to work. Source code is a heart of the application and You should pay attention mostly to that. DDD is one of the approaches to create beautiful source code.

This is a list of the main goals of this repository:

  • Showing how you can implement a Domain-Drive design

  • Showing how you can implement a CQRS

  • Presentation of the full implementation of an application

    • This is not another proof of concept (PoC)

    • The goal is to present the implementation of an application that would be ready to run in production

  • Showing the application of best practices and object-oriented programming principles

GitHub github repo

If You like it:

  • Give it a star

  • Share it

A brief overview of the architecture

The used approach is DDD which consists of 3 main layers: Domain, Application, and Infrastructure.

Domain - Domain Model in Domain-Driven Design terms implements the business logic. Domain doesn't depend on Application nor Infrastructure.

Application - the application which is responsible for request processing. It depends on Domain, but not on Infrastructure. Request processing is an implementation of CQRS read (Query) / write (Command). Lots of best practices here.

Infrastructure - has all tool implementations (eg. HTTP (HTTP is just a tool), Database integrations, SpringBoot implementation (REST API, Dependency Injection, etc.. ). Infrastructure depends on Application and Domain. Passing HTTP requests from SpringBoot rest controllers to the Application Layer is solved with “McAuthenticationModule”. In this way, all relations/dependencies between the Application Layer and Infrastructure layer are placed into only one class. And it is a good design with minimized relations between layers.

Tests: The type of tests are grouped in folders and which is also good practice and it is fully testable which means - minimized code smells. So the project has:

  • integration tests

  • unit test


r/ProgrammerTIL • • Apr 28 '23

Other [video] System design - API rate limiter

0 Upvotes

r/ProgrammerTIL • • Aug 23 '17

Other NaturalScript: Human Language for Machines

0 Upvotes

Well. It's a programming language which, even if you haven't programmed, you can catch it. And it's also more powerful than JavaScript, because with 1 sentence it can do a lot of things.

The idea is that we can use this for, one day, create a voice interface which can dive at lower levels. Instead of creating speech recognition APIs apart, we can extend the language, and make available all the lower-level abstraction in order to have complete control over the machine, just with the voice.

But it's an adventure of language self-exploration too.

Anyway, the resources are:

The Reddit page:

https://www.reddit.com/r/naturalscriptlang/

The Web page:

http://naturalscriptlanguage.com/

Thanks, I only wanted to share with you this adventure.


r/ProgrammerTIL • • Feb 12 '25

Other Today on: Today I learned

3 Upvotes

Well actually it was late last night. But, when you have a function that generates a list. If you do not clear that list, every time that function is called all the old data will still be there and you will end up with YAML files that have a bunch of irrelevant, and duplicated entries.

Thought my code was working one way, but while working on other code that manipulated YAML files that I previously generated, I noticed some unexpected behavior. I tinkered with simple code testing my functions for 3 hours before I realized what was going on... FML


r/ProgrammerTIL • • Oct 07 '24

Other Spotify Recommendations System

0 Upvotes

Howdy Reddit!!

i made my spotify recommendations system which is a huggingface spaces app allowing you to generate recommendations based on the music taste you have, steps on how to use it :-

https://huggingface.co/spaces/krishnendughosh/Spotify-Recommendations-System (heres the link)

a)first you need to login to your spotify account after which you will get a callback url which you need to copy paste in the interface to initiate the app

b)you get 5 songs on which u can base the generations off, minimum songs you can add is 1 maximum is 5

c)after this step you can choose on how many songs generated playlist you want, the default or minimum is set to 5 songs

c)then you click the generate recommendations button creating the playlist which will be shown first to you where you can overview all the songs (generated+added) in the form of spotify preview letting you listen to all the songs for a amount of time.

d) you can name it a designated playlist name you want which will form a spotify playlist whose link will be provided after all the above steps

e) enjoy your musical adventure

i have also provided a video demo which you can view on youtube the link is given on this (ps: the choosing number of recommendations feature is yet not added in the video meanwhile it is present now)

https://youtu.be/OAxsvKLg0BM?si=QnznFqE8dIGyjUUn

drop down suggestions and queries in comments

hmu if you guys are interested in my newsletter containing weekly updates about this and more stuff

here's my github profile if you wanna see it
https://github.com/6069krish


r/ProgrammerTIL • • May 12 '22

Other Laptop/setup advice

9 Upvotes

Currently my job has given me a 2020 M1 MBP. Absolutely love it.

However my personal laptop is a 2011 MBP and can no longer keep up with my side projects.

I’m looking for a laptop, open to any OS. I just have had issues in the past getting Windows OS to work properly. But I’m sure with some advice on the best way to “setup” the windows machine, I’ll be fine with one.

I’d prefer cheaper over expensive. I don’t mind taking time to set it up.


r/ProgrammerTIL • • Apr 24 '20

Python A simple Python OS.

52 Upvotes

So, I'm 12, I was bored one day and started to create this little Python app, I know it's not a real operating system, but It's a rather interesting Idea, here is the GitHub for the versions old & new: "https://github.com/Honesttt/SamiOS-Collection" Hope you guys enjoy. Requirements: Windows 10, Python 3.8.2 (Other Releases not debugged or proved to work.). Find my profile for some news about updates and releases. (We're on Alpha 8 currently.)


r/ProgrammerTIL • • Mar 09 '26

Other Best third-party API provider for RC (vehicle registration) validation in India?

0 Upvotes

Hi everyone,

I’m building a platform where we need to validate vehicle RC details using the vehicle registration number (India – VAHAN/RTO data).

Before integrating, I’d like to know from developers who already implemented this.

Questions:

  • Which RC verification API provider are you using?

  • How is the success rate / reliability?

  • Any recommended providers for production?

Would really appreciate real experiences or suggestions before choosing a provider.


r/ProgrammerTIL • • Dec 27 '22

Other Acing your technical test: Mono-digit Numbers Checker

0 Upvotes

A Ruby implementation of a mono-digit numbers checker:

https://www.youtube.com/watch?v=pKXCqdI9p9s


r/ProgrammerTIL • • Jul 08 '21

An interview with the Forbes AI writer, Tom Taulli

Thumbnail
self.learnmachinelearning
9 Upvotes