Skip to content

Instantly share code, notes, and snippets.

@chaitanyagupta
chaitanyagupta / cowin.lisp
Created May 6, 2021
Co-WIN API for Common Lisp
View cowin.lisp
;;; You need to set the *TOKEN* to access the private APIs
;;; Either get it from the browser by observing the bearer token sent on the Co-WIN website,
;;; or use the VALIDATE-MOBILE function below
(defpackage #:cowin
(:use #:cl))
(in-package #:cowin)
(eval-when (:compile-toplevel :load-toplevel :execute)
@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 Feb 21, 2021
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))))
@chaitanyagupta
chaitanyagupta / security-exercises.md
Last active Jan 19, 2020
Webapp security exercises for beginners
View security-exercises.md

(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
chaitanyagupta / fswatch.sh
Created Jul 17, 2019
Using fswatch to run a command when a file changes
View fswatch.sh
fswatch -o presentation.md | xargs -n1 -I{} ./make-presentation.sh presentation.html
View ffmpeg-tricks.md

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
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
USAGE:
JSON-PARSER> (parse-with-lexer (json-lexer
"{\"foo\":\"bar\",\"baz\":\"bang\",\"bing\":100,\"bingo\":1.1,\"bazo\": [1,2,\"foo\"]}")
json-parser)
(:OBJ ("foo" . "bar") ("baz" . "bang") ("bing" . 100) ("bingo" . 1.1) ("bazo" 1 2 "foo"))
JSON-PARSER> (with-open-file (*standard-input* "test.json")