Skip to content

Instantly share code, notes, and snippets.


Chaitanya Gupta chaitanyagupta

View GitHub Profile


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 /
Last active Mar 15, 2021
Learning about files in Python

Files in Python


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 /
Last active Mar 16, 2021
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 /
Last active Feb 22, 2021
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 /
Last active Feb 21, 2021
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
View search-and-replace-all.lisp
(defun search-and-replace-all (old new string)
with start = 0
for pos = (search old string :start2 start)
while pos
do (setf string (concatenate 'string
(subseq string 0 pos)
(subseq string (+ pos (length old))))
start (+ pos (length new))))
chaitanyagupta /
Last active Jan 19, 2020
Webapp security exercises for beginners

(All hints are encoded in base64)

Q1 Here's a Django view that serves an HTML response, whose content depends on a request query parameter:

def hello_view(request, name):
    return HttpResponse(f'<html><body><p>Hello {name}</p></body></html>')
chaitanyagupta /
Created Jul 17, 2019
Using fswatch to run a command when a file changes
fswatch -o | xargs -n1 -I{} ./ presentation.html

Concatenate or loop a file

$ cat concat.txt
file '/path/to/file1'
file '/path/to/file2'

$ ffmpeg -f concat -i concat.txt -c copy output.mp3
chaitanyagupta / json-parser.lisp
Created Apr 2, 2018 — forked from tanakahx/json-parser.lisp
JSON parser implemented with cl-lex and CL-Yacc
View json-parser.lisp
JSON parser implemented with cl-lex and CL-Yacc
JSON-PARSER> (parse-with-lexer (json-lexer
"{\"foo\":\"bar\",\"baz\":\"bang\",\"bing\":100,\"bingo\":1.1,\"bazo\": [1,2,\"foo\"]}")
(:OBJ ("foo" . "bar") ("baz" . "bang") ("bing" . 100) ("bingo" . 1.1) ("bazo" 1 2 "foo"))
JSON-PARSER> (with-open-file (*standard-input* "test.json")