Skip to content

Instantly share code, notes, and snippets.

View chaitanyagupta's full-sized avatar

Chaitanya Gupta chaitanyagupta

View GitHub Profile
@chaitanyagupta
chaitanyagupta / _reader-macros.md
Last active September 12, 2024 16:16
Reader Macros in Common Lisp

Reader Macros in Common Lisp

This post also appears on lisper.in.

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.

@chaitanyagupta
chaitanyagupta / re-sign-ios-app.md
Last active August 15, 2024 02:39
How to re-sign an iOS app with another developer account

WARNING These steps are probably out dated and will not work.

To re-sign an iOS app with another developer account, ensure that the following are in place first.

  1. Distribution certificate of the other developer account
  2. A provisioning profile from the other developer account

Note that the Apple requires bundle IDs to be globally unique, even across accounts. So a bundle ID i.e. CFBundleIdentifier from one account can't be used in a different account, even though the team id/prefix would be different.

Ensure that the new distribution certificate is in your keychain and the new provisioning profile on your disk.

@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 / 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 / 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
@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 / 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")