Skip to content

Instantly share code, notes, and snippets.

View akashrajkn's full-sized avatar
🚀
Spaceship

akash raj akashrajkn

🚀
Spaceship
View GitHub Profile
@akashrajkn
akashrajkn / notion_api_cru.js
Last active November 27, 2021 08:59
Notion (JS) script for adding an entry, updating an entry and retrieving a item based on the paperLink
// Based on the blog post here: https://developers.notion.com/docs/getting-started
import { Client } from "@notionhq/client"
const notion = new Client({ auth: "<NOTION_KEY>" })
const databaseId = "<NOTION_DATABASE_ID>"
async function addItem(paperLink, paperTitle, tags, comments, completedReading) {
// Add an item to the database
// Each item has a link (unique), title, tags (list of objects), comments and (boolean) reading status
@akashrajkn
akashrajkn / impulse_response.py
Last active October 1, 2022 15:29
Python function to compute room impulse response using the exponential sine sweep method with librosa
import librosa
import numpy as np
def compute_impulse_response(ess_rec_path, ess_inv_path, target_ir_path):
"""
Computes impulse response using the Exponential sine sweep (ESS) method.
Code based on IR Capture project: http://tulrich.com/recording/ir_capture/
Args:
@akashrajkn
akashrajkn / fifo_writer.js
Last active July 6, 2021 20:50
IPC with pipes (Node.js): Write to pipe, Read processed data from pipe
const fs = require('fs');
const { spawn, fork } = require('child_process');
const path_a = 'pipe_a';
const path_b = 'pipe_b';
let fifo_b = spawn('mkfifo', [path_b]); // Create Pipe B
fifo_b.on('exit', function(status) {
console.log('Created Pipe B');
@akashrajkn
akashrajkn / fifo_reader.py
Last active February 15, 2021 21:35
IPC with pipes (Python): Read, Process and Write
import os
import select
IPC_FIFO_NAME_A = "pipe_a"
IPC_FIFO_NAME_B = "pipe_b"
def get_message(fifo):
'''Read n bytes from pipe. Note: n=24 is an example'''
return os.read(fifo, 24)
@akashrajkn
akashrajkn / read_mixed_csv.m
Created December 21, 2015 05:28
read the csv file with different data types in matlab
function lineArray = read_mixed_csv(fileName,delimiter)
fid = fopen(fileName,'r'); %# Open the file
lineArray = cell(100,1); %# Preallocate a cell array (ideally slightly
%# larger than is needed)
lineIndex = 1; %# Index of cell to place the next line in
nextLine = fgetl(fid); %# Read the first line from the file
while ~isequal(nextLine,-1) %# Loop while not at the end of the file
lineArray{lineIndex} = nextLine; %# Add the line to the cell array
lineIndex = lineIndex+1; %# Increment the line index
nextLine = fgetl(fid); %# Read the next line from the file
@akashrajkn
akashrajkn / downloadInParts.sh
Created November 6, 2015 06:09
download large file in parts using curl in linux
#!/bin/sh
#This script can be used as a sort of download accelerator and also it can be used to download large files from a url in parts.
#Here, as an example, I've used it to download the kubuntu 15.10 version
#url1, url2, url3, url4 are user-defined variables
url1=http://d33vwem6kwnf57.cloudfront.net/kubuntu-15.10-desktop-amd64.iso
url2=http://d33vwem6kwnf57.cloudfront.net/kubuntu-15.10-desktop-amd64.iso
url3=http://d33vwem6kwnf57.cloudfront.net/kubuntu-15.10-desktop-amd64.iso
url4=http://d33vwem6kwnf57.cloudfront.net/kubuntu-15.10-desktop-amd64.iso
@akashrajkn
akashrajkn / scrollToTop.js
Created July 27, 2015 18:26
simple scroll to top function in AngularJS
/** scroll to top function in AngularJS */
angular.module('demoApp').controller('controller', ['$scope', function($scope) {
$scope.scrollToTop = function($var) {
// 'html, body' denotes the html element, to go to any other custom element, use '#elementID'
$('html, body').animate({
scrollTop: 0
}, 'fast'); // 'fast' is for fast animation
};
@akashrajkn
akashrajkn / textMaxlengthDirective.js
Created July 26, 2015 17:48
angularjs directive to limit the length of message in a textbox
/* directive to disable input if num(chars) crosses maxLength in text-area in pagePopUp */
angular.module('notify.pageEOCApp').directive('textMaxlengthDirective', function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModelCtrl) {
var maxlength = Number(attrs.textMaxlength);
function fromUser(text) {
if(text.length > maxlength) {