Skip to content

Instantly share code, notes, and snippets.

@sriharshav
sriharshav / pytorch_mps.py
Created October 15, 2022 09:03
PyTorch with Apple M1 MPS
import torch
print(f"PyTorch version: {torch.__version__}")
# Check PyTorch has access to MPS (Metal Performance Shader, Apple's GPU architecture)
print(f"Is MPS (Metal Performance Shader) built? {torch.backends.mps.is_built()}")
print(f"Is MPS available? {torch.backends.mps.is_available()}")
# Set the device
device = "mps" if torch.backends.mps.is_available() else "cpu"
print(f"Using device: {device}")
@sriharshav
sriharshav / rsa.hpp
Created March 17, 2022 23:55 — forked from lillypad/rsa.hpp
OpenSSL RSA Encryption / Decryption C++ Wrapper
// c includes
#include <stdio.h>
#include <string.h>
// cpp includes
#include <algorithm>
#include <iostream>
#include <sstream>
// lib includes
@sriharshav
sriharshav / libtar-list.c
Last active November 19, 2021 07:54 — forked from cat-in-136/libtar-list.c
Study for reading/writing a tar file using libtar
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <libtar.h>
int main(int argc, char *argv[]) {
TAR *tar = NULL;
int ret = 0;
int exitcode = 0;
import requests
import json
from datetime import date
# Refer Meta data apis to get district ids https://apisetu.gov.in/public/api/cowin#/Metadata%20APIs
districts = [
294, # BBMP
265, # Bangalore Urban
]
@sriharshav
sriharshav / gist:185aaf8122f64e089aa6dc93b1816a34
Created January 19, 2018 04:09
Clear known hosts for chrome secure shell app
Reference : https://groups.google.com/a/chromium.org/d/msg/chromium-hterm/XZtSm6P0acw/Ww4UCE1b-I0J
Configure to open the app in new tab instead of seperate window.
Once it is open in new tab, open developer tools and follow steps below.
If you know the index of the offending host entry (it's usually reported
by ssh if the connection fails) you can open the JavaScript console and
// bits and pieces of map in 'go'
package main
import (
"fmt"
"regexp"
"log"
)
@sriharshav
sriharshav / gist:3904970
Created October 17, 2012 11:02
Javascript date time helpers
//##Gets x days Ago##
Date.prototype.daysAgo = function (days) {
if (isNaN(days) || (days ==0)) {
return;
}
this.setDate(this.getDate() - days);
}
//##Gets x weeks Ago##
Date.prototype.weeksAgo = function (weeks) {
@sriharshav
sriharshav / gist:3683571
Created September 9, 2012 09:59
CSS3 menu bar
<style>
nav > ul > li { /* Main menu float left */
float : left;
}
nav ul ul li { /* Position Sub menu and Details menu relative */
position: relative;
}