Skip to content

Instantly share code, notes, and snippets.

Avatar

Chaitanya Gupta chaitanyagupta

View GitHub Profile
@chaitanyagupta
chaitanyagupta / ffmpeg-frame-timestamp-overlay.sh
Created Feb 4, 2022
ffmpeg video with frame timestamp overlaid
View ffmpeg-frame-timestamp-overlay.sh
# shows time in milliseconds
# source: https://superuser.com/a/1613753/95678
ffmpeg -i input.mp4 -vf drawtext="fontsize=60:fontcolor=yellow:text='%{e\:t*1000}':x=(w-text_w):y=(h-text_h)" output.mp4
@chaitanyagupta
chaitanyagupta / NameShadowing.kt
Created Dec 28, 2021
Name shadowing in Kotlin
View NameShadowing.kt
// This simple example shows that name shadowing in Kotlin depends on type specificity
//
// Foo().baz(1) after evaluating this class returns 43
class Foo() {
fun bar(x: Int): Int = x + 42
fun baz(bar: Int): Int = bar(bar)
}
@chaitanyagupta
chaitanyagupta / pg-format-sql.js
Last active Sep 14, 2021
Format SQL statements in Postgres logs
View pg-format-sql.js
// pg-format-sql.js
//
// Format SQL statements in Postgres logs
// i.e. If a log line contains a SQL statement, it will be transformed from this:
//
// 2021-09-14 08:02:37.255 IST [20200] LOG: statement: SELECT MAX("my_notification"."id") AS "latest_id", COUNT(*) AS "count" FROM "my_notification" WHERE ("my_notification"."is_unread" AND "my_notification"."organization_id" = 1 AND "my_notification"."recipient_id" = 2)
//
// to this:
//
// 2021-09-14 08:02:37.255 IST [20200] LOG: statement:
@chaitanyagupta
chaitanyagupta / long-lived-feature-branches.md
Created Aug 30, 2021
Why long lived feature branches are harmful
View long-lived-feature-branches.md

You will find a lot of material online for why long lived feature branches are harmful. Intead of deferring to one of those articles, I wanted to highlight why I believe they are harmful, and why they are an unsustainable practice for most software projects.

In projects where long lived feature branches are the norm, the code in the feature branch is effectively silo'ed from development happening in other branches. This has two effects:

  1. you cannot test how code in the long lived branch plays with other code under development
  2. painful merge conflicts become a recurring event when the long lived branch gets merged into the mainline

To handle these issues, it is generally recommended to merge the mainline into your long lived feature branch on a regular basis. However, the catch is, if all feature development happens on long lived branches, there won't usually be anything new in the mainline apart from small fixes. Since all features sit in their own long lived branch, you cannot see how your branch will

View ffmpeg.md

ffmpeg

Converting Audio into Different Formats / Sample Rates

Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma

You can get the list of supported formats with:
ffmpeg -formats

You can get the list of installed codecs with:

@chaitanyagupta
chaitanyagupta / python-files.md
Last active Mar 15, 2021
Learning about files in Python
View python-files.md

Files in Python

Basics

Read about reading and writing files in Python.

  1. Why is it recommended to use the with keyword when opening file objects? Why is it important to close a file even if an exception is raised?
  2. The documentation states that, "Using with is also much shorter than writing equivalent try-finally blocks". What is the finally block and, if the with keyword did not exist, could you have used it to properly close a file after it was opened?
  3. The documentation warns: > Calling f.write() without using the with keyword or calling f.close() might result in the arguments of f.write() not being completely written to the disk, even if the program exits successfully.
@chaitanyagupta
chaitanyagupta / simple-querysets.md
Last active Mar 16, 2021
Simple problems to learn how django's querysets work
View simple-querysets.md

Simple Querysets

Objective of this exercise is to implement some of the interesting behaviours exhibited by Django querysets:

  • Lazy loading or on-demand evaluation
  • Results caching
  • Filters and chaining

Getting Started

@chaitanyagupta
chaitanyagupta / tcp-ip-questions.md
Last active Feb 22, 2021
Questions around TCP/IP networking
View tcp-ip-questions.md

Assumes you've gone through the [topics to study][topics] for TCP/IP networking.

You can use [GNS3][] to emulate TCP/IP networks inside a single host.

Link/Network Layer

  1. Assume you've got two machines with working ethernet ports and an ethernet [crossover cable][]. You connect the two. Your objective is to send a message from one machine to the other. How will you do that? What networking protocols are required to achieve this and why?
  2. Assume you've got more than two machines, an ethernet hub and straight through ethernet cables for each machine. You connect all of these machines to the hub. Your objective is to send a message from one machine to any of the other machines. How will you do that? What networking protocols are required to achieve this and why?
  3. If you replace the hub in the previous question with a switch, what advantages do you get?
  4. You have three machines, an ethernet hub/switch and required cables. As does your neighbour. You want to connect your network with your neighbour
@chaitanyagupta
chaitanyagupta / tcp-ip-topics.md
Last active Jan 24, 2022
Topics to understand in TCP/IP networking
View tcp-ip-topics.md
  • What is encapsulation
  • Link layer
    • Link layer basics (pick something like Ethernet to get a quick overview of what the link layer entails)
    • What is a MAC address
  • IP - this is a vast topic but there are several important concepts to understand here
    • IP addresses and subnet masks
    • How are IP addresses different from MAC addresses and why are they required
    • How do you discover a MAC address of a device on the same network if you only have its IP address (hint: see ARP)
    • What are routers and how IP routing works
  • Route tables
View search-and-replace-all.lisp
(defun search-and-replace-all (old new string)
(loop
with start = 0
for pos = (search old string :start2 start)
while pos
do (setf string (concatenate 'string
(subseq string 0 pos)
new
(subseq string (+ pos (length old))))
start (+ pos (length new))))