Skip to content

Instantly share code, notes, and snippets.

View srishanbhattarai's full-sized avatar
💭
Make software fast again

Srishan srishanbhattarai

💭
Make software fast again
View GitHub Profile
@srishanbhattarai
srishanbhattarai / counter_async.rs
Last active March 8, 2020 00:10
Futures example with a simple counter
use std::sync::Arc;
use std::pin::Pin;
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
use std::task::{Context, Poll};
use std::thread;
use std::future::Future;
use futures::future::join;
struct Counter {
id: u8,
@srishanbhattarai
srishanbhattarai / main.go
Last active February 24, 2020 03:01
Determine if task set schedulable under Rate Monotonic scheduling (WIP)
package main
import (
"errors"
"fmt"
"io/ioutil"
"log"
"math"
"os"
"sort"
@srishanbhattarai
srishanbhattarai / dinero.py
Last active November 26, 2019 02:54
DineroIV experiments (3 trace files Trace1,2,3.din must exist)
#!/usr/local/bin/python3
import subprocess
from terminaltables import AsciiTable
###########################################################################
# Constants #
###########################################################################
CPI_BASE = 1
@srishanbhattarai
srishanbhattarai / chrono.cpp
Created November 21, 2019 02:04
chrono timer c++
typedef std::chrono::high_resolution_clock Time;
typedef std::chrono::milliseconds ms;
auto t1 = Time::now();
// do stuff
auto t2 = Time::now();
auto diff = std::chrono::duration_cast<ms>(t2 - t1); // returns type ms
auto diffValue = diff.count(); // this returns a constexpr "rep" type that can be used as a literal
@srishanbhattarai
srishanbhattarai / Makefile
Last active February 18, 2020 19:38
Interprocess sequencing system
# Compiler options
CXX = g++
CXXFLAGS = --std=c++11 -Wall -g -pthread
# Source code files, object files and the final binary name.
SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:.cpp=.o)
BIN = binary
.PHONY: file clean
@srishanbhattarai
srishanbhattarai / gdb
Created September 15, 2019 03:25
Fix GDB on MacOS
https://sourceware.org/gdb/wiki/PermissionsDarwin#Create_a_certificate_in_the_System_Keychain
@srishanbhattarai
srishanbhattarai / f1.js
Last active September 11, 2019 04:36
Simplified filtering Redux
return state.questions.map(q => {
if (q.item === payload.item) {
return {
...q,
steps: { ...q.steps, one: true }
}
}
return q
})
@srishanbhattarai
srishanbhattarai / singly.cpp
Created July 1, 2019 16:44
Linear singly linked list with C++ generics/templates
#include <stdexcept>
template <class T>
class Node {
public:
T data;
Node<T>* next;
Node(const T value) {
this->data = value;
@srishanbhattarai
srishanbhattarai / binarySearch.cpp
Last active June 4, 2019 17:48
Binary Search C++
#include <iostream>
using namespace std;
int binarySearch(int array[], int size, int searchValue) {
int lo = 0, hi = size - 1;
int mid;
while (hi > lo) {
mid = (lo + hi) / 2;
@srishanbhattarai
srishanbhattarai / bin_exists.rs
Created April 25, 2019 12:01
Check if a file exists in $PATH in Rust
// look_path returns a boolean indicating if the binary can be found in $PATH.
fn look_path(path: &str) -> Result<bool, std::env::VarError> {
std::env::var("PATH").and_then(|paths| {
Ok(paths
.split(":")
.map(|p| format!("{}/{}", p, path))
.any(|p| Path::new(&p).exists()))
})
}