This file contains 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 User extends Record { | |
posts = new Relation(this, 'wrote'); | |
//yes. we're passing object and it will be dumped into DB without a schema | |
async createPost(postParams) { | |
const tx = this.connection.transaction() | |
const post = await new Post(postParams) | |
.save(tx) | |
await this.posts.add(post, tx) |
This file contains 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 {Server} from 'http'; | |
const server = new Server(); | |
server.listen(8080); | |
server.on('request', async function (req, res) { | |
req.pause(); | |
res.statusCode = 200; | |
req.on('end', () => res.end('OK')); | |
const length = message.headers['content-length']; |
This file contains 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
/** | |
* As close as possible transfer of https://en.wikipedia.org/wiki/Fast_inverse_square_root#Overview_of_the_code | |
*/ | |
const dataView = new DataView(new ArrayBuffer(8)); | |
const intVars = new Int32Array(4); | |
const floatVars = new Float32Array(4); | |
const intConsts = new Int32Array(1); | |
const floatConsts = new Float32Array(2); |
This file contains 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
'send': function (data) { | |
var virtualDOMTree = document.createElement('html'); | |
virtualDOMTree.innerHTML = data; | |
['head', 'body'].forEach(function (tagName) { | |
var virtualRoot = virtualDOMTree.querySelector(tagName), | |
realRoot = document.querySelector(tagName); | |
if (!realRoot) { | |
document.documentElement.appendChild(realRoot = document.createElement(tagName)); | |
} | |
var diff = LCSdiff(realRoot.childNodes, virtualRoot.childNodes); |
This file contains 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 lcs(x, y) { | |
var symbols = {}, | |
r = 0, p = 0, p1, L = 0, idx, | |
m = x.length, n = y.length, | |
S = new Array(m < n ? n : m); | |
p1 = popsym(0); | |
for (i = 0; i < m; i++) { | |
p = (r === p) ? p1 : popsym(i); | |
p1 = popsym(i + 1); | |
idx = (p > p1) ? (i++, p1) : p; |
This file contains 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
require('traceur').require.makeDefault(function(filename){ | |
return filename.endsWith('traceur.js'); | |
}); | |
module.exports = require('./index.traceur.js'); |
This file contains 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
directive('preload-css-images', function(){ | |
var image_regexp = /url\(['"]?\S*['"]?\)/; | |
for (var i = 0; i < document.styleSheets.length; i++) { | |
var styleSheet = document.styleSheets[i]; | |
var rules = styleSheet.cssRules || styleSheet.rules; | |
if (rules && rules.length) | |
for (var j = 0; j < rules.length; j++) { | |
var ruleText = rules[j].cssText; | |
if (ruleText){ | |
var image_urls = image_regexp.exec(ruleText); |
This file contains 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
directive('preload-css-images', function () { | |
var image_regexp = /url\(['"]?\S*['"]?\)/; | |
for (var i = 0; i < document.styleSheets.length; i++) { | |
var styleSheet = document.styleSheets[i]; | |
var rules = styleSheet.cssRules || styleSheet.rules; | |
if (rules && rules.length) | |
for (var j = 0; j < rules.length; j++) { | |
var image_urls = image_regexp.exec(rules[j].cssText); | |
if (image_urls) for (var k = 0; k < image_urls.length; k++) { | |
document.createElement('img').src = image_urls[k] |
This file contains 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
$('body').on('submit', 'form.remote', function (e) { | |
e.preventDefault(); | |
var form = this; | |
form.xhrSend(function (responseData) { | |
form.reset(); | |
window.images.add(responseData.src) | |
}); | |
return false | |
}); |
This file contains 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 (rarDetected) { | |
function detectRar(blob, callback) { | |
var reader = new FileReader; | |
reader.readAsBinaryString(blob); | |
reader.onload = function () { | |
callback(reader.result.indexOf('Rar!') != -1) | |
} | |
} | |
function getBlob(url, callback) { |