Skip to content

Instantly share code, notes, and snippets.

@williamstein
williamstein / gist:5d1f5f77614c9a48d5adc9c2078647a8
Created September 28, 2022 21:57
converting local file imports
#!/usr/bin/env node
import * as fs from 'fs';
import * as path from 'path';
// https://gist.github.com/lovasoa/8691344
async function* walk(dir) {
for await (const d of await fs.promises.opendir(dir)) {
const entry = path.join(dir, d.name);
if (d.isDirectory()) {
@williamstein
williamstein / demo.py
Created October 26, 2020 20:24
demo.py
def f(n):
print("hello ", n, "!")
@williamstein
williamstein / OrbitControls.js
Created September 18, 2014 17:30
Modification of THREE.js http://threejs.org/examples/js/controls/OrbitControls.js, but so that holding alt or command enables pan and holding shift or control enables zoom. This is for people like Mac users that have only one mouse button, but still want to pan using the mouse. I use this in SageMathCloud, where I can't enable the OrbitControls …
/**
* @author qiao / https://github.com/qiao
* @author mrdoob / http://mrdoob.com
* @author alteredq / http://alteredqualia.com/
* @author WestLangley / http://github.com/WestLangley
* @author erich666 / http://erichaines.com
*/
/*global THREE, console */
// This set of controls performs orbiting, dollying (zooming), and panning. It maintains
#!/usr/bin/env python
######################################################################
# Copyright (c) 2013, William Stein, Ondrej Certik, All rights reserved.
# 2-clause BSD.
######################################################################
import json, os, random, BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
https://news.ycombinator.com/reply?id=13613909&goto=item%3Fid%3D13610146%2313613909
---
smc=# explain SELECT * FROM file_use WHERE project_id = any(select project_id from projects where users ? '25e2cae4-05c7-4c28-ae22-1e6d3d2e8bb3') ORDER
BY last_edited DESC limit 100;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.85..8198.07 rows=100 width=242)
-> Nested Loop Semi Join (cost=0.85..1736663.69 rows=21186 width=242)
httpProxy = require('http-proxy')
init_http_proxy_server = () =>
_remember_me_check_for_write_access_to_project = (opts) ->
opts = defaults opts,
project_id : required
remember_me : required
cb : required # cb(err, has_access)
account_id = undefined
@williamstein
williamstein / smcarch56
Last active January 2, 2016 05:59
SageMath Cloud backend architecture talk at Sage Days 56
# SageMath Cloud backend architecture talk at Sage Days 56
## Guiding principles
- A place for everybody to use *all* math-related software easily, especially (but not only!) open source
- High availability: automatically survive failure of any proper subset of datacenters
- Make it very hard to permanently lose work:
- everything has synchronization
@williamstein
williamstein / gist:7386062
Created November 9, 2013 14:30
Making a 3d animation in the Sagemath Cloud http://youtu.be/lhirRHCW1q0
%time
filename_pattern = '/tmp/plt-%04d.png'
@parallel
def frame(n, filename):
t = Tachyon(xres=800,yres=800, camera_center=(2,5,2), look_at=(2.5,0,0), antialiasing=True)
t.light((0,0,100), 1, (1,1,1))
t.texture('r', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0))
for i in range(n):
@williamstein
williamstein / cloud-ipython.coffee
Created October 12, 2013 22:17
This is the code I wrote as part of https://cloud.sagemath.com in order to integrate IPython notebooks into my existing document synchronization infrastructure. It's CoffeeScript code that isn't meant to be run-able (I just copied it out of a bigger file). I just thought there could be some value in making this available under a BSD license, sin…
###############################################################################
# Copyright (c) 2013, William Stein
# All rights reserved.
#
# 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.
# 2. Redistributions in binary form must reproduce the above copyright notice,
@williamstein
williamstein / tofile cell decorator
Created September 19, 2013 22:01
Load this then put "%default_mode tofile" in a cloud.sagemath worksheet.
def tofile(s):
maxout=500
import uuid
filename = str(uuid.uuid4()) +'.log'
o = open(filename,'w')
stdout = sys.stdout
class Stdout:
def __init__(self):
self.t = 0