Skip to content

Instantly share code, notes, and snippets.

@brentshermana
brentshermana / main.py
Created March 2, 2018 21:30
Python generator based iterator
class X:
def __init__(self, l):
self.l = l
def __iter__(self):
for x in self.l:
yield x
x = X([1,2,3])
for i in x:
print(i)
@brentshermana
brentshermana / main.cpp
Created February 28, 2018 17:01
C++ ifstream reading
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream file; // stream object representing an open file
file.open("test.txt"); // path to some text file
@brentshermana
brentshermana / python_printing.py
Last active December 18, 2017 00:16
Low Level Printing in Python
import time
import sys
import itertools
# inspired by tqdm https://github.com/tqdm/tqdm
class ConsolePrinter:
def __init__(self, file):
self.prev_line_len = 0
self.file = file
def write(self, s):