Skip to content

Instantly share code, notes, and snippets.

@gagern
gagern / exact_code.sage
Last active August 29, 2015 13:56
Minimum eccentricity of ellipses around another ellipse
# Exact computation to solve http://math.stackexchange.com/q/688861/35416,
# heavily inspired by https://groups.google.com/d/msg/sci.math/LYtIdRhk2ac/mQtEBcgCjZkJ
def printPoly(name, poly):
print(name + ":")
print(poly.denominator()*poly)
print("")
# a and b are the alpha and beta from http://math.stackexchange.com/a/698656/35416.
# We use approximate values to choose the right alternatives in some situations.
@gagern
gagern / eclp.py
Created April 23, 2014 08:02
Print ECL data structures in GDB
from __future__ import with_statement
import gdb
class EclUtil(object):
def __init__(self, *args, **kwargs):
super(EclUtil, self).__init__(*args, **kwargs)
self.cl_object = gdb.lookup_type("cl_object").strip_typedefs()
self.cl_objectp = self.cl_object.pointer()
#!/usr/bin/python3
# (c) Martin von Gagern 2014
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
@gagern
gagern / mmap.diff
Created May 2, 2014 20:21
Python using mmap vs. read
fstat(3, {st_mode=S_IFREG|0644, st_size=164, ...}) = 0
lseek(3, 0, SEEK_CUR) = 0
+lseek(3, 0, SEEK_CUR) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=164, ...}) = 0
-dup(3) = 4
-mmap(NULL, 164, PROT_READ, MAP_SHARED, 3, 0) = 0x...
-open("so23434490out.txt", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 5
-fstat(5, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
-ioctl(5, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x...) = -1 ENOTTY (Inappropriate ioctl for device)
-fstat(5, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
@gagern
gagern / mx779275.txt
Created May 3, 2014 08:52
Finding singularities for Math SE 779275
sage: # http://math.stackexchange.com/a/779318/35416
sage: P1.<x,y,z,w> = QQ[]
sage: p = x^3+y^3+z^3+w*x*y*z
sage: px, py, pz = [P1(p.polynomial(v).differentiate()) for v in [x, y, z]]
sage: px
y*z*w + 3*x^2
sage: pxy = px.resultant(py, x)
sage: pxz = px.resultant(pz, x)
sage: pxyz = pxy.resultant(pxz, y)
sage: f = pxyz.factor()
def rotmat(a, t=(0,0,1), l=False):
# Rotate by a degrees, then shift origin to point t.
# If l=True then transform lines not points.
x, y, z = t
q = QQ(a/360)
w = QQbar.zeta(q.denominator())^(q.numerator())
c = AA(z*w.real())
s = AA(z*w.imag())
m = matrix(AA, [[c, -s, x], [s, c, y], [0, 0, z]])
if l:
@gagern
gagern / MX914152b.cc
Last active May 12, 2016 10:45
Mark rational points on a sphere
// http://math.stackexchange.com/a/914871/35416
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
@gagern
gagern / terms.txt
Created December 8, 2014 14:39
Math SE 1055320
# Terms for http://math.stackexchange.com/a/1057500/35416
+ 16 z1^2 u2^2 ar^4
+ 32 z1^2 u2 v2 ar^4
+ 16 z1^2 v2^2 ar^4
+ 32 z1^2 u2^2 ar^2 ai^2
+ 64 z1^2 u2 v2 ar^2 ai^2
+ 32 z1^2 v2^2 ar^2 ai^2
+ 16 z1^2 u2^2 ai^4
+ 32 z1^2 u2 v2 ai^4
@gagern
gagern / InaccessibleSymbols.js
Last active August 29, 2015 14:24
Identifying inaccessible symbols for KaTeX
var fs = require("fs");
var symbols = require("./src/symbols");
var todo = 0;
var files = fs.readdirSync("static/fonts");
files.forEach(function(file) {
if (file.substr(file.length - 4) !== ".ttx")
return;
++todo;
fs.readFile("static/fonts/" + file, "utf-8", doTTX.bind(null, file));
@gagern
gagern / ParserCallGraph.js
Created July 7, 2015 17:38
Call graph for the KaTeX Parser
"use strict";
var fs = require("fs");
var src = fs.readFileSync("src/Parser.js", "utf-8");
var match;
var defined = {};
var callers = {};
var curMethod = "TOP";
var re = /Parser\.prototype\.([A-Za-z0-9_]+)|this\.([A-Za-z0-9_]+)/g;