Skip to content

Instantly share code, notes, and snippets.

SETUP="
import sys
from itertools import compress
def vprimes(maximum=10**6):
maxidx = maximum//2
sieve = [True] * maxidx # 2, 3, 5, 7... might be prime
j = 0
for i in range(1, int(maxidx**0.5)+1):
def false(false):
return false(false)
@false
def false(false=𝔽𝕒𝕝𝕤𝕖):
class false:
def __bool__(self):
if 𝔽𝕒𝕝𝕤𝕖:
nonlocal false
try:
# Yes, you can have apostrophes in your identifiers.
Shellyʼs = ["balloon"]
Johnʼs = []
Johnʼs.extend(Shellyʼs.pop())
Shellyʼs
Johnʼs
@Veedrac
Veedrac / injections.py
Last active August 29, 2015 14:01
A little module to make a little thing a little easier... OK a lot easier, but whatever!
"""
A small 1-to-1 dictionary library. Shares inspiration from bidict:
https://pypi.python.org/pypi/bidict/0.1.1
Implementation similarities are mostly coincidental. The ordered variant
was an idea stolen from
https://bitbucket.org/jab/bidict/issue/1/ordereddict-integration
from timeit import Timer
from functools import partial
def add_string(n):
s = ''
for _ in range(n):
s += ' '
def add_string_in_list(n):
l = ['']
@Veedrac
Veedrac / accessor.cpp
Last active August 29, 2015 14:04
Getter-Setter vs Properties
///
/// The class to hold an object's information so that the Engine can
/// manipulate it.
///
///
///
class Object {
protected:
///
/// The object's renderable component
@Veedrac
Veedrac / mediocre_mandelbrot.py
Last active August 29, 2015 14:05
Significantly more complicated than justified, but eeking out that last 50% felt important...
import sys
import numpy
import numexpr
numexpr.set_num_threads(2)
CHUNKS = 256
def mandel_unroll_numexpr(n, z="z", c="c"):
"""
Generate a numexpr for the core mandelbrot loop (z = z ** 2 + c)
@Veedrac
Veedrac / Pandas core dump.txt
Created September 11, 2014 15:12
Pandas core dump
*** Error in `python': free(): invalid pointer: 0x00007fd64024d530 ***
======= Backtrace: =========
/usr/lib/libc.so.6(+0x73f8e)[0x7fd65c1dcf8e]
/usr/lib/libc.so.6(+0x7988e)[0x7fd65c1e288e]
/usr/lib/libc.so.6(+0x7a04b)[0x7fd65c1e304b]
/usr/lib/python3.4/site-packages/numpy/core/multiarray.cpython-34m.so(+0xc842c)[0x7fd65ad1242c]
/usr/lib/python3.4/site-packages/numexpr/interpreter.cpython-34m.so(_Z11NumExpr_runP13NumExprObjectP7_objectS2_+0xc58b)[0x7fd652d8f68b]
/usr/lib/libpython3.4m.so.1.0(PyObject_Call+0x88)[0x7fd65c797e68]
/usr/lib/libpython3.4m.so.1.0(PyEval_EvalFrameEx+0x1091)[0x7fd65c846721]
/usr/lib/libpython3.4m.so.1.0(PyEval_EvalCodeEx+0x879)[0x7fd65c84e289]
@Veedrac
Veedrac / just_some_cplusplus.cpp
Last active May 5, 2019 12:02
Speed test. Warning: Please read first comment
#include <iostream>
#include <iterator>
#include <numeric>
#include <unordered_set>
#include <vector>
int32_t some_calculations(int32_t number) {
std::vector<int32_t> a;
std::unordered_set<int32_t> s;
#include <iostream>
#include <iterator>
#include <numeric>
#include <unordered_set>
#include <vector>
int32_t some_calculations(int32_t number) {
std::vector<int32_t> a;
std::unordered_set<int32_t> s;