Skip to content

Instantly share code, notes, and snippets.

View nimrodshn's full-sized avatar

Nimrod Shneor nimrodshn

View GitHub Profile
/// insert a key value pair possibly splitting nodes along the way.
pub fn insert(&mut self, kv: KeyValuePair) -> Result<(), Error> {
let root_offset = self.wal.get_root()?;
let root_page = self.pager.get_page(&root_offset)?;
let new_root_offset: Offset;
let mut new_root: Node;
let mut root = Node::try_from(root_page)?;
if self.is_node_full(&root)? {
// split the root creating a new root and child nodes along the way.
new_root = Node::new(NodeType::Internal(vec![], vec![]), true, None);
/// Implement TryFrom<Page> for Node allowing for easier
/// deserialization of data from a Page.
impl TryFrom<Page> for Node {
type Error = Error;
fn try_from(page: Page) -> Result<Node, Error> {
let raw = page.get_data();
let node_type = NodeType::from(raw[NODE_TYPE_OFFSET]);
let is_root = raw[IS_ROOT_OFFSET].from_byte();
let parent_offset: Option<Offset>;
@nimrodshn
nimrodshn / postgres-cheatsheet.md
Created July 28, 2017 17:36 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

If run with -E flag, it will describe the underlaying queries of the \ commands (cool for learning!).

Most \d commands support additional param of __schema__.name__ and accept wildcards like *.*

@nimrodshn
nimrodshn / Rarefactor
Last active August 29, 2015 14:19
Rarefactor
Simple script that plots rarefaction curve from a givenn data set using the following: http://en.wikipedia.org/wiki/Rarefaction_(ecology)
@nimrodshn
nimrodshn / Heatmap
Created August 8, 2014 18:51
Lightweight module for creating Heatmaps based on excel datasheets using matplotlib
'''
@param string: input file name with '.xlsx' ending
@author: Nimrod Shneor
'''
import numpy as np
import matplotlib.pyplot as plt
import xlrd
import matplotlib.cm as cm