Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond.

Sandeep Gupta sangupta

💭
I may be slow to respond.
View GitHub Profile
@sangupta
sangupta / main.go
Created Apr 27, 2022
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.
View main.go
package main
import (
"fmt"
"io/ioutil"
v8 "rogchap.com/v8go"
)
func main() {
@sangupta
sangupta / main.go
Last active Apr 27, 2022
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.
View main.go
package main
import (
"errors"
"fmt"
"io/ioutil"
"time"
stdruntime "runtime"
@sangupta
sangupta / StringJoinBenchmark.java
Created Oct 5, 2020
A simple benchmark to compare performance of String.join() and String concatenation for 2 arguments.
View StringJoinBenchmark.java
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 Jan 4, 2018
Python script to serve local files with caching disabled.
View httpd.py
#!/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 Mar 18, 2017
CDN and Working
View CDN.md

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 Dec 14, 2016
Sparse BitArray implementation in Java
View SparseBitArray.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
The following script shows how to highlight a particular element on an HTML page using PhantomJS before taking a screenshot.
View highlight-and-rasterize.js
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 May 14, 2020
A simple shell script to run a Java program from Linux shell in the background
View README.md

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 Jun 25, 2015
Configure logback using pure Java
View LogbackConfigureExample.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 {
View 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: