This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Complex | |
| constructor: (re=0, im=0) -> | |
| if not(this instanceof Complex) | |
| return new Complex re, im | |
| this.re = re | |
| this.im = im | |
| conjugate: (other) -> | |
| new Complex @re, -@im | |
| add: (other) -> | |
| [re, im] = [@re + other.re, @im + other.im] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| from flask import Flask | |
| app = Flask(__name__) | |
| @app.route('/') | |
| def index(): | |
| return ''' | |
| <!doctype html> | |
| <body> | |
| <head> | |
| <title>DOMContentLoaded</title> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| javascript: | |
| var a = [ | |
| prompt('title'), | |
| "document.getElementById('h').addEventListener('DOMCharacterDataModified', function (s) { document.title = s.newValue; })" | |
| ]; | |
| var t = 'data:text/html;charset=utf-8,<!doctype html><meta charset="utf-8"><title>$1</title><h1 id="h" contenteditable>$1</h1><script>$2</script>'; | |
| location.href = t.replace(/[$]\d+/g, function (s) { return a[parseInt(s.slice(1), 10) - 1]; }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Array.prototype.reduce.call(document.querySelectorAll('.narrow li code'), function (p, c) { | |
| var s = c.childNodes[0].nodeValue; | |
| if (!(s in p)) | |
| p[s] = 0; | |
| p[s]++; return p; | |
| }, {}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| n = int(1e6) | |
| def f(x): | |
| l = 0 | |
| while x != 0: | |
| l += 1 | |
| x >>= 1 | |
| return l | |
| f(n) # 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| > debug | |
| < function debug(fn) { [Command Line API] } | |
| */ | |
| function f(x) { | |
| return x * 2; | |
| } | |
| function g(x) { | |
| return Math.pow(f(x), 2); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>マンデルブロ集合。</title> | |
| <style> | |
| canvas { | |
| display: block; | |
| } | |
| </style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Array.prototype.forEach.call(document.querySelectorAll('a'), function (a) { | |
| a.href = a.href.replace(/(sm\d+)\?.+/, '$1'); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function () { | |
| if (!(String.prototype.repeat)) { | |
| String.prototype.repeat = function (n) { | |
| if (n < 0) throw RangeError('Invalid repeat count'); | |
| return Array(n + 1).join(this); | |
| }; | |
| } | |
| function zfill(s, n) { | |
| if (s.length >= n) return s; | |
| return ('0'.repeat(n) + s).slice(-n); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| b = /b/ | |
| ##### | |
| /a#{b.source}c/.source # => 'a#{b.source}c' | |
| ///a#{b.source}c///.source # => 'abc' |