Skip to content

Instantly share code, notes, and snippets.

View simon-tiger's full-sized avatar

Simon Tiger simon-tiger

View GitHub Profile
Array.prototype.choice = function() {
var i = floor(random(this.length));
return this[i];
}
var paragraphs = [];
function process(word) {
var text = textinput.value();
var words = splitTokens(text, ' .,:;!@#$%&*()\n');
WEBGL // p5 WEBGL rendering mode.
createCanvas(w, h, renderer) // Creates a 3D canvas (if renderer is WEBGL).
// Primitives
plane(width, height) // Creates a plane in 3D space. Equivalent to rect() in the default rendering mode.
plane(width, height, detailX, detailY) // Creates a plane in 3D space with the number of triangle subdivisions specified.
box(width) // Creates a cube in 3D space.
box(width, height, depth) // Creates a cuboid in 3D space.
box(width, height, depth, detailX, detailY) // Creates a cuboid in 3D space with triangle subdivisions.
sphere(radius) // Creates a sphere in 3D space.
& (bitwise and)
| (bitwise or)
^ (bitwise xor)
~ (bitwise not)
<< (zero-fill bitshift left)
>> (signed bitshift right)
>>> (zero-fill bitshift right)
Polar:
- r = 1 - sin(t) (cardioid)
- r = (sin(t) sqrt(|cos(t)|)) / (sin(t) + 7/5) - 2 sin(t) + 2
Cartesian:
- (x^2 + y^2 - 1)^3 - x^2 y^3 = 0
- (y - 2(|x| + x^2 - 6) / 3(|x| + x^2 + 2))^2 + x^2 = 36
- x^2 + (y - cubert(x^2))^2 = 1
- glued curve
- x: -2 to 2
'''
This is the code for level 1 of my series Sorting Algorithms.
The Quicksort code I wrote myself. For the rest, I used these resources:
http://www.zaxrosenberg.com/must-know-sorting-algorithms-in-python/
https://brilliant.org/wiki/sorting-algorithms/
https://medium.com/@george.seif94/a-tour-of-the-top-5-sorting-algorithms-with-python-code-43ea9aa02889
'''
# Bubble Sort
def bubble_sort(L):
class Stack:
def __init__(self):
self.data = []
def push(self, i):
self.data.append(i)
def peek(self):
return self.data[-1]
'''
This is the code for level 2 of my series Sorting Algorithms.
More algorithms will come later.
The heapsort code comes from these resources:
https://brilliant.org/wiki/heap-sort/
http://www.zaxrosenberg.com/must-know-sorting-algorithms-in-python/
The rest I wrote myself.
'''
'''Shell Sort'''
### PROOF THAT YOU CANT PROVE EVERYTHING ###
# You can easily turn every statement into a program. If the program stops, or "halts", then the statement is true, and if it never stops, or "loops", the statement is false.
# Like, for example, the following program corresponds to the statement: "There's at least one even number that cannot be expressed as the sum of two primes" (this is the negation of the so-called "Goldbach Conjecture"):
def example(): # (assumes a get_primes function, but you get the idea)
n = 4
while True:
primes = get_primes(n)
found = False
$red: #FF0000
$green: #00FF00
$blue: #0000FF
$black: #000000
$white: #FFFFFF
$gray: #808080
$cyan: #00FFFF
$magenta: #FF00FF
$yellow: #FFFF00
$brown: #996633
// First you have to install NeDB. For this, you can just use `npm install nedb`.
// To create a database, do this:
const Datastore = require("nedb");
const db = new Datastore("database.db");
// Then, to query it, do this:
db.find({ property: requiredValue }, (err, results) => {
// results will hold the result
});