Skip to content

Instantly share code, notes, and snippets.

View chaitanyagupta's full-sized avatar

Chaitanya Gupta chaitanyagupta

View GitHub Profile
@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 / bind_and_listen.c
Created August 15, 2017 20:06
Bind and listen on a Berkley socket
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int bind_and_listen (int port, int backlog) {
int listen_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (listen_fd == -1) {
perror("socket");
@chaitanyagupta
chaitanyagupta / nettop.md
Last active October 4, 2017 10:47
Using nettop on os x

Monitor tcp connections in a particular process

nettop -m tcp -p <proc-name>

Monitor tcp connetions in a process (delta mode)

nettop -m tcp -p  -d
@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 / mem-usage.lisp
Last active April 13, 2024 07:18
Memory usage in a Lisp image
;;;; mem-usage.lisp
;;; MEM-USAGE returns memory used by Lisp image in a plist.
;;; MEM-USED prints memory allocated while running the given forms.
;;; Works on SBCL, CMUCL, CCL and CLISP.
;;; Relies on internal APIs (the ones that ROOM uses). Can break at any time.
(defpackage #:mem-usage
(:use #:cl)
(:export #:mem-usage #:mem-used))
@chaitanyagupta
chaitanyagupta / json-parser.lisp
Created April 2, 2018 12:57 — forked from tanakahx/json-parser.lisp
JSON parser implemented with cl-lex and CL-Yacc
#|
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")
@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>')