Skip to content

Instantly share code, notes, and snippets.

View pushkarnk's full-sized avatar

Pushkar N Kulkarni pushkarnk

  • Canonical | ex-IBM
  • India
View GitHub Profile
Iteration Time taken in
checkpointing run (ms)
Time taken in
the restore run (ms)
0 37101493 15505
100 106442 13759
200 46307 13480
300 29963 22211
400 31919 10546
500 18090 9150
600 15226 8032
700 15086 9639
@pushkarnk
pushkarnk / PrimeTime.java
Last active October 27, 2023 06:12
A toy program to demonstrate the C/R abilities using CRaC JDK
import java.util.*;
import java.lang.*;
import java.text.*;
import jdk.crac.*;
public class PrimeTime implements jdk.crac.Resource {
/* - get the current time in milliseconds - T1
- print the time as a human readable date
- reverse the digits in T1 to create a T2
- print the time T2 as a human readable date
@pushkarnk
pushkarnk / Dockerfile
Created October 6, 2023 15:00
Copying jre-8 from a chiseled jre-8 image as a non-root user
FROM ubuntu/chiselled-jre:8-22.04_edge as chiselled-jdk8
FROM ubuntu:16.04
# Run as a non-root user
RUN addgroup --system test
RUN adduser --system testuser --ingroup test
USER testuser:test
COPY --from=chiselled-jdk8 /usr/lib/jvm/java-8-openjdk-amd64 /usr/lib/jvm/java-8-openjdk-amd64
@pushkarnk
pushkarnk / keyagreement.c
Created September 27, 2023 11:54
Key Agreement
#include <openssl/evp.h>
#include <stdio.h>
typedef enum Algo {
AlgoDH, AlgoEC
} Algo;
int generate_shared_secret(EVP_PKEY *private_key,
EVP_PKEY *peer_public_key,
unsigned char **secret) {
@pushkarnk
pushkarnk / poll_test.c
Last active March 10, 2021 07:52
reproducer: poll returns POLLIN for fd on which out-of-band data arrived
#define _XOPEN_SOURCE_EXTENDED 1
#define _OPEN_THREADS
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <errno.h>

Random points on Direct IO

  1. Files reside on disks. When they are opened, their contents are cached in the kernel space. They may also be cached in user-space by applications.

  2. Reads and writes to files, by default, actually happen on their kernel-cached copy. The actual commit to the hard disk happens asynchronously, sometime later.

  3. Of course, the OS kernels do ensure correctness of reads and writes in almost all the cases, while implementing optimizations to reduce the number of reads and writes from the disk sectors.

const WebSocket = require('ws');
for (i=0; i < 50; i++) {
let ws = this.ws = new WebSocket("ws://localhost:9001/");
ws.onopen = (event) => {
console.log("Websocket opened");
ws.send("This is the first message that was sent");
ws.send("This is the second message that was sent");
};
struct Foo {
var bar
let foo
}
@pushkarnk
pushkarnk / isNil.swift
Last active July 19, 2018 16:27
This is a cool way to replace `x == nil` checks
extension Optional {
var isNil: Bool {
switch self {
case .none: return true
case .some: return false
}
}
}
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/IBM-Swift/Kitura", .branch("kitura-nio")),
],