Skip to content

Instantly share code, notes, and snippets.

View sangupta's full-sized avatar
💭
I may be slow to respond.

Sandeep Gupta sangupta

💭
I may be slow to respond.
View GitHub Profile
@sangupta
sangupta / main.go
Created April 27, 2022 05:50
Parse Typescript code in Go lang using v8go. The idea is to re-use the original Typescript library than rolling out a parser of our own.
package main
import (
"fmt"
"io/ioutil"
v8 "rogchap.com/v8go"
)
func main() {
@sangupta
sangupta / main.go
Last active June 28, 2023 03:54
Parse Typescript code in Go lang using QuickJS. The idea is to re-use the original Typescript library than rolling out a parser of our own.
package main
import (
"errors"
"fmt"
"io/ioutil"
"time"
stdruntime "runtime"
@sangupta
sangupta / StringJoinBenchmark.java
Created October 5, 2020 23:50
A simple benchmark to compare performance of String.join() and String concatenation for 2 arguments.
public class StringJoinBenchmark {
public static void main(String[] args) {
final int MAX_ITER = 1000 * 1000;
final int RUNS = 1;
long delta = 0;
long delta2 = 0;
for(int run = 0; run < RUNS; run++) {
@sangupta
sangupta / httpd.py
Created January 4, 2018 19:04
Python script to serve local files with caching disabled.
#!/usr/bin/env python
import http.server
class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
http.server.SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
@sangupta
sangupta / CDN.md
Last active March 18, 2017 08:09
CDN and Working

What are CNAME, A records?

The way Internet works is that we first type a domain name in browser: say google.com. The browser then hits the DNS servers for resolution of IP address, so that the browser know which machine to send the request to. The DNS servers return an IP (v4 or v6) against google.com and that IP is then used for all requests going forth. There is a TTL (time to live) associated with every DNS resolution after which the browser is required to re-ask the DNS servers for the new IP again (in case it has changed - this is meant to make sure that in case the machines fail or IPs change - the website can again be reached after the TTL is expired.

Now there are multiple types of DNS records:

1. A Record

Called as Address mapping records - these are used to map a domain/subdomain to a given IP - say,

@sangupta
sangupta / SparseBitArray.java
Created December 14, 2016 11:58
Sparse BitArray implementation in Java
package com.sangupta.jerry.ds.bitarray;
import java.io.IOException;
import com.sangupta.jerry.util.BitUtils;
import com.sangupta.jerry.util.ByteArrayUtils;
import net.jcip.annotations.NotThreadSafe;
@NotThreadSafe
@sangupta
sangupta / highlight-and-rasterize.js
Created May 12, 2016 07:01
The following script shows how to highlight a particular element on an HTML page using PhantomJS before taking a screenshot.
var webpage = require('webpage');
var page = webpage.create();
page.viewportSize = { width: 1600, height: 900 };
page.open('http://sangupta.com/poetry/best-of-luck.html', function() {
// execute the selector
var ev = page.evaluate(function(sel) {
var ele = document.querySelector(sel);
if(ele) {
ele.style.border = "2px solid red";
@sangupta
sangupta / README.md
Last active July 6, 2022 23:26
A simple shell script to run a Java program from Linux shell in the background

This is a simple script to run a Java program from Linux shell in the background - so that the process does not terminates when you log out of the shell.

Usage is simple:

  • Start the process
$ ./java-app-run.sh start
@sangupta
sangupta / LogbackConfigureExample.java
Created June 25, 2015 17:36
Configure logback using pure Java
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.FileAppender;
public class LogbackConfigureExample {
@sangupta
sangupta / Keybase.md
Created June 16, 2014 12:39
Keybase.md

Keybase proof

I hereby claim:

  • I am sangupta on github.
  • I am sangupta (https://keybase.io/sangupta) on keybase.
  • I have a public key whose fingerprint is 9127 C67F 5CEE 90F2 EC65 83D1 CE65 932B DD59 F1A9

To claim this, I am signing this object: