Skip to content

Instantly share code, notes, and snippets.

View chaitanyagupta's full-sized avatar

Chaitanya Gupta chaitanyagupta

View GitHub Profile
@chaitanyagupta
chaitanyagupta / openssl-csr-and-packaging.md
Last active October 4, 2017 11:01
Using OpenSSL to generate a CSR and packaging the certs and private key in a .p12 file
  • generate an RSA key
    openssl genrsa -out domain_name.key 2048
    
  • generate a certificate signing request (CSR) using the private key
    openssl req -new -sha256 -key domain_name.key -out domain_name.csr
    
  • verify that public key in the certificate matches the private key
@chaitanyagupta
chaitanyagupta / split-command.md
Last active November 16, 2017 10:02
Using the split command

An example:

cat file.ext | split -b 4m - file.ext.

This will create:

file.ext.aa
@chaitanyagupta
chaitanyagupta / install-gm-w-librvg.sh
Created August 18, 2016 15:08 — forked from whyvez/install-gm-w-librvg.sh
Installs ImageMagick --with-librsvg on Amazon Linux
export PKG_CONFIG_PATH=/usr/lib64/pkgconfig:/usr/lib/pkgconfig
export PATH=/usr/bin:$PATH
export LDFLAGS=-L/usr/lib64:/usr/lib
export LD_LIBRARY_PATH=/usr/lib64:/usr/lib
export CPPFLAGS=-I/usr/include
sudo yum-config-manager --enable epel
#sudo yum update -y
sudo yum install -y gcc gcc-c++ glib2-devel.x86_64 libxml2-devel.x86_64 libpng-devel.x86_64 \
libjpeg-turbo-devel.x86_64 gobject-introspection.x86_64 gobject-introspection-devel.x86_64
@chaitanyagupta
chaitanyagupta / ffmpeg-tricks.md
Created December 14, 2018 17:35
ffmpeg tricks

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 / fswatch.sh
Created July 17, 2019 11:40
Using fswatch to run a command when a file changes
fswatch -o presentation.md | xargs -n1 -I{} ./make-presentation.sh presentation.html
@chaitanyagupta
chaitanyagupta / security-exercises.md
Last active January 19, 2020 11:12
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>')
(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 / 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 / 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