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 / 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 / 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 / gist:2993291
Created June 26, 2012 04:30
Code to determine overlaps in set of data ranges
/**
Problem: Given a set of data ranges (i.e. 2-7, 5-9, 10-20), write a function to determine if there is any overlap within the set.
Write test cases. Which data structure would be best to represent the intervals.
Solution: I would prefer to use an array of size 2N and then iterate over it. Another
way is to work up using interval tree's but I think that may be an overkill considering
it used to check overlaps in multiple ranges and points.
*/
@sangupta
sangupta / org.eclipse.egit.github.core.RepositoryCommit.java
Created November 10, 2011 16:44
Class to hold the statistics as returned by the GitHub Commit API for single commit details.
/**
Add the following lines to the original class:
org.eclipse.egit.github.core.RepositoryCommit.java
*/
private Stats stats;
private List<CommitFile> files;
public Stats getStats() {