Skip to content

Instantly share code, notes, and snippets.

View sivsivsree's full-sized avatar
👨‍💻
Focusing on Team building

Siv S sivsivsree

👨‍💻
Focusing on Team building
View GitHub Profile
func main() {
mux := http.NewServeMux()
finalHandler := http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
// the context value is retrieved from the request
user := request.Context().Value("user").(string)
writer.Write([]byte(user))
})
func main() {
// creating parent context
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// this is for graceful shutdown
exit := make(chan os.Signal, 1)
signal.Notify(exit, os.Interrupt, syscall.SIGTERM)
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
)
// An emptyCtx is never canceled, has no values, and has no deadline. It is not
// struct{}, since vars of this type must have distinct addresses.
type emptyCtx int
func (*emptyCtx) Deadline() (deadline time.Time, ok bool) {
return
}
@sivsivsree
sivsivsree / context.go
Last active June 30, 2022 10:16
Article: Code 01: Golang Context Interface
// A Context carries a deadline, a cancellation signal, and other values across
// API boundaries.
//
// Context's methods may be called by multiple goroutines simultaneously.
type Context interface {
// Deadline returns the time when work done on behalf of this context
// should be canceled. Deadline returns ok==false when no deadline is
// set. Successive calls to Deadline return the same results.
Deadline() (deadline time.Time, ok bool)
var Vue = (function (exports) {
'use strict';
/**
* Make a map and return a function for checking if a key
* is in that map.
* IMPORTANT: all calls of this function must be prefixed with
* \/\*#\_\_PURE\_\_\*\/
* So that rollup can tree-shake them if necessary.
*/
@sivsivsree
sivsivsree / main.c
Created January 13, 2022 20:18
Vigenere Chiper
/**
* Author: Siv Sugaman
* Created: 13-01-2021
*
* (c) Copyright by Siv S<sivsivsree@gmail.com>.
**/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
sudo apt update
sudo apt install nfs-kernel-server
sudo mkdir -p /mnt/nfs_share
sudo chown -R nobody:nogroup /mnt/nfs_share/
sudo chmod 777 /mnt/nfs_share
echo "/mnt/nfs_share *(rw,sync,no_subtree_check,insecure)" | sudo tee -a /etc/exports
sudo exportfs -a
sudo systemctl restart nfs-kernel-server
@sivsivsree
sivsivsree / signing.js
Created November 9, 2021 07:40
json data signing and verification in node.js
const crypto = require('crypto');
const buffer = require('buffer');
const algorithm = "SHA256"
// Create a private key
const { privateKey,publicKey } = crypto.generateKeyPairSync('rsa', {
modulusLength: 2048,
});
// JSON object
const person = {
{
"@context": [
"https://w3id.org/openbadges/v2",
"https://w3id.org/blockcerts/v2"
],
"type": "Profile",
"id": "https://raw.githubusercontent.com/blockchain-certificates/cert-issuer/master/examples/issuer/profile.json",
"name": "Smartworld",
"url": "https://www.smartworld.com/",
"introductionURL": "https://www.smartworld.com/intro/",