This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// curtesy of https://github.com/DavidSaxon and http://www.parashift.com/c++-faq-lite/ | |
#include <iostream> | |
// this function will be called by the base class | |
void baseFunction() { | |
std::cout << "Base Class!" << std::endl; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// why does makeTransform1 give the same results as makeTransform2? | |
mat3 rotationMatrix(float angle, vec3 axis) { | |
... // returns a 3x3 rotation matrix for rotating about the given axis | |
} | |
mat3 makeTransform1(float alpha, float beta, float gamma) { | |
mat3 alphaTransform = rotationMatrix(alpha, vec3(0.0, 1.0, 0.0)); | |
mat3 betaTransform = rotationMatrix(beta, vec3(1.0, 0.0, 0.0)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
An example of having a function being called regularly | |
while still processing user input | |
''' | |
import threading | |
# the regular event | |
timer = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import scipy.sparse as sparse | |
import scipy.sparse.linalg | |
xs = [25.0, 50.0, 60.0] | |
ys = [ 1.0, -1.0, 0.3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup as bs | |
import urllib.request as request | |
import urllib.parse as parse | |
import pprint | |
# Selects sections of html that we are interested in | |
def prepare(html): | |
soup = bs(html, 'html.parser') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 -i | |
# Hello there! | |
# The following line of code creates a mystery object which behaves in really weird ways. | |
# Have fun trying to figure it out. | |
# :Dom | |
# | |
# PS: This concept came from a Kiwi Pycon 2015 talk. | |
mystery = next(filter(lambda _:'.'in repr([_])and not(list!= type(_) or _),['%s'%{}]+__import__('gc').get_objects())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# returns the shortest path (measured in the number of edges) from start-->goal. | |
# if no path exists None is returned | |
def unweightedDijkstra(graph, start, goal): | |
if goal is start: # special case | |
return (start,) | |
q = [(start,)] # q is a queue of paths (tuples of nodes) | |
visited = set() | |
while q: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def powerset(list): | |
if not list: | |
yield set() | |
return | |
*rest, last = list | |
yield from powerset(rest) | |
for subset in powerset(rest): | |
yield subset | {last} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def enforce0to360range(angle): | |
"""Converts the given angle (degrees) into the range [0 360). | |
>>> enforce0to360range(30) | |
30.0 | |
>>> enforce0to360range(180) | |
180.0 | |
>>> enforce0to360range(360) | |
0.0 | |
>>> enforce0to360range(390.0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
The main use case of this is to replace either | |
>>> [ x * (x + 1) for x in [1,2,3] ] | |
or | |
>>> map(lambda x: x * (x + 1), [1,2,3]) | |
with | |
>>> map(X * (X + 1), [1,2,3]) #SWAG | |
You can naively think of it as 'lambda X:' without writing 'lambda X:'. |