Skip to content

Instantly share code, notes, and snippets.

View pidb's full-sized avatar
I need a lot of coffee...

Jackson Xu pidb

I need a lot of coffee...
View GitHub Profile
@pidb
pidb / clock_replacer.cpp
Created September 7, 2021 12:09
CMU 15-445 (Fall 2020) ClockReplacer
//===----------------------------------------------------------------------===//
//
// BusTub
//
// clock_replacer.cpp
//
// Identification: src/buffer/clock_replacer.cpp
//
// Copyright (c) 2015-2019, Carnegie Mellon University Database Group
//
@pidb
pidb / lru_replacer.cpp
Created September 7, 2021 14:12
CMU 15-445-2019 LRUReplacer
//===----------------------------------------------------------------------===//
//
// BusTub
//
// lru_replacer.cpp
//
// Identification: src/buffer/lru_replacer.cpp
//
// Copyright (c) 2015-2019, Carnegie Mellon University Database Group
//
@pidb
pidb / lc_lru_cache_array.cpp
Created September 7, 2021 15:08
Leetcode LRU Cache solution for array [but Time Limit Exceeded]
#include <vector>
struct LRUKV {
int key_;
int value_;
LRUKV(int key, int value) :key_(key), value_(value) {}
};
class LRUCache {
public:
@pidb
pidb / lc_lru_cache_hashmap.cpp
Created September 7, 2021 15:11
Leetcode LRU Cache solution for hashmap + double-linked list, but it can continue to be optimized
struct LRUKV {
int key_;
int value_;
LRUKV(int key, int value) :key_(key), value_(value) {}
};
class LRUCache {
public:
LRUCache(int capacity)
:cache_size_(capacity),
@pidb
pidb / buffer_pool_manager.cpp
Last active September 8, 2021 15:39
CMU 15-445: TASK #2 - BUFFER POOL MANAGER
//===----------------------------------------------------------------------===//
//
// BusTub
//
// buffer_pool_manager.cpp
//
// Identification: src/buffer/buffer_pool_manager.cpp
//
// Copyright (c) 2015-2019, Carnegie Mellon University Database Group
//
@pidb
pidb / vimrc
Created September 8, 2021 23:40
My vimrc
" Specify a directory for plugins
" - For Neovim: stdpath('data') . '/plugged'
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')
Plug 'rhysd/vim-clang-format'
" On-demand loading
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
@pidb
pidb / better-clean-slice-for-go-compiler.go
Created September 23, 2021 01:45
Better clean slice for go compiler
package main
type items []int
var nilItems = make(items, 16)
func (s *items) truncate1(i int) {
*s = (*s)[:i]
}

Editing remote files in Vim with SSH

  1. Configure SSH

    In ~/.ssh/config, include the lines:

    Host *
    ControlPath ~/.ssh/sockets/%r@%h-%p
    
@pidb
pidb / memlib.c
Created October 24, 2021 02:38
csapp/vm/malloc
/*
* memlib.c - a module that simulates the memory system. Needed
* because it allows us to interleave calls from the student's malloc
* package with the system's malloc package in libc.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
@pidb
pidb / memlib.h
Created October 24, 2021 02:39
csapp/vm/malloc
/* $begin memlibheader */
#include <unistd.h>
void mem_init(void);
void *mem_sbrk(int incr);
void mem_deinit(void);
void mem_reset_brk(void);
void *mem_heap_lo(void);
void *mem_heap_hi(void);