Skip to content

Instantly share code, notes, and snippets.

@Back2Basics
Back2Basics / Monopoly.py
Created May 4, 2013 19:39
buggy version of Monopoly.
from collections import OrderedDict, namedtuple
import random
# <codecell>
criteria = namedtuple('criteria', ['owner', 'cost', 'square_type', 'rent'], verbose=True)
# <codecell>
board = OrderedDict() # you need to add the sale price before the group
import string
with open('somefile.txt', 'r') as infile:
fread = infile.readlines()
d = {}
for x in fread:
if "\xe2\x80\xa2 " in x:
x = x.strip()
val = x.split("\xe2\x80\xa2 ")
d[value].append(val[1])
@Back2Basics
Back2Basics / won't yield
Created November 27, 2013 07:44
can't get this generator to yield a math expression.
import itertools as it
import math
import sympy as sy
Energy, Frequency, Kinetic_energy, Mass, Momentum, Wavelength, Work_function, Speed_of_light,Force,Acceleration= sy.symbols("Energy Frequency Kinetic_energy Mass Momentum Wavelength Work_function Speed_of_light Force Acceleration")
Symbols_list=[Energy, Frequency, Kinetic_energy, Mass,
Momentum, Wavelength, Work_function, Speed_of_light]
Equations= [sy.Eq(Energy,Mass * Speed_of_light**2),sy.Eq(Force,Mass * Acceleration)]
Term_dict={}
@Back2Basics
Back2Basics / get_data
Last active January 4, 2016 18:59
webserver
from multiprocessing import Process
import webbrowser as wb
def shutdown_server():
func = request.environ.get('werkzeug.server.shutdown')
if func is None:
raise RuntimeError('Not running with the Werkzeug Server')
func()
def webserver():

Keybase proof

I hereby claim:

  • I am Back2Basics on github.
  • I am back2basics (https://keybase.io/back2basics) on keybase.
  • I have a public key whose fingerprint is E00C 4FA6 2288 F2C4 21D5 CCA4 158D D0A0 44B8 C5AA

To claim this, I am signing this object:

@Back2Basics
Back2Basics / deep_eq.py py3.x
Last active March 7, 2017 09:29 — forked from samuraisam/deep_eq.py
Deep Equality Test for Nested Python Structures
# Copyright (c) 2010-2013 Samuel Sutch [samuel.sutch@gmail.com]
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
@Back2Basics
Back2Basics / Context Manager.ipynb
Created October 20, 2016 19:08
Context Mangers
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Back2Basics
Back2Basics / sets.ipynb
Created November 17, 2016 05:46
Python Sets
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Back2Basics
Back2Basics / sliding_window.py
Last active May 22, 2019 07:20
n_things at a time
from collections import deque, Counter
from typing import Iterable, Callable
def sliding_window(someiterable: Iterable, n: int, returnable: Callable = ''.join):
"""
generates an n element sliding window one element
at a time in whatever type you want returned
returnable could be tuple or list
"""
n_things = deque()
@Back2Basics
Back2Basics / readit.py
Created October 2, 2019 08:04
have your mac read filtered text
# this was used in the youtube clip
data = “”” <paste data here> “””
read_this = [line.partition(‘\xa0’)[2] for line in data.split(‘\n’)]
import subprocess as sp
sp.call([‘say’, ‘ ‘.join(read_this)])