Skip to content

Instantly share code, notes, and snippets.

View chaitanyagupta's full-sized avatar

Chaitanya Gupta chaitanyagupta

View GitHub Profile
@chaitanyagupta
chaitanyagupta / ffmpeg-frame-timestamp-overlay.sh
Created February 4, 2022 20:43
ffmpeg video with frame timestamp overlaid
# 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 December 28, 2021 11:54
Name shadowing in Kotlin
// 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 September 14, 2021 03:02
Format SQL statements in Postgres logs
// 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 August 30, 2021 20:08
Why long lived feature branches are harmful

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

@chaitanyagupta
chaitanyagupta / ffmpeg.md
Created July 16, 2021 11:21 — forked from protrolium/ffmpeg.md
ffmpeg guide

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 March 15, 2021 10:20
Learning about files in Python

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 March 16, 2021 13:20
Simple problems to learn how django's querysets work

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 February 22, 2021 11:20
Questions around TCP/IP networking

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 January 24, 2022 09:13
Topics to understand in TCP/IP networking
  • 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
(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))))