Skip to content

Instantly share code, notes, and snippets.

View Jabher's full-sized avatar

Vsevolod Rodionov Jabher

  • St. Petersburg, Russia
View GitHub Profile
@Jabher
Jabher / gist:10445952
Created April 11, 2014 07:12
traceur require by default
require('traceur').require.makeDefault(function(filename){
return filename.endsWith('traceur.js');
});
module.exports = require('./index.traceur.js');
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;
'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);
/**
* 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);
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'];
@Jabher
Jabher / angular resource cacher
Created April 5, 2013 11:18
Transparent caching function for AngularJS resources. Accepts factory name(string), path mask and original routes hash as arguments. Supports callbacks in functions.
function createRestFactory(name, path, r){
rest.factory(name, function($resource, $cacheFactory){
var c=$cacheFactory(name);
var res = $resource(path, {}, r);
return (function(resource, routes, cache) {
var o={};
angular.forEach(routes, function(value, key) {
o[key]=(function(r) {
var request=r;
return function(attrs) {
@Jabher
Jabher / main2.js
Last active December 16, 2015 06:19
almost-universal ajaxifier
var link_processor = function () {
var link_selector = 'a[href^="/"], a[href^="' + document.location.origin + '"]';
$('body').on('click', link_selector, function () {
var target, all_of_type, target_path;
target = $(this);
if (target.attr('href')) {
target_path = target.attr('href').replace(document.location.origin, '');
var chunks = target_path.split('.');
if ((chunks.length == 1) || (chunks.length > 1 && (chunks[chunks.length - 1] == "htm") && (chunks[chunks.length - 1] == "html"))) {
@Jabher
Jabher / cache.js
Last active December 16, 2015 11:39
Caching factory; usage syntax: cache = new CacheFactory(Math.random) cache(1)> 0.808444140246138; cache(2)> 0.9461546286474913; cache(1)> 0.808444140246138;
CacheFactory = (function () {
function compareThings() {
var names = [
arguments[0]["name"].toLowerCase(),
arguments[1]["name"].toLowerCase()
];
if (names[0] < names[1]) {
return -1;
}
if (names[0] > names[1]) {
var brightnessProperty = {
get: function () {
var canvas = document.createElement('canvas');
canvas.width = 1;
canvas.height = 1;
var context = canvas.getContext('2d');
context.drawImage(this, 0, 0, 1, 1);
var data = context.getImageData(0, 0, 1, 1).data;
return Math.floor((data[0] + data[1] + data[2]) / 3)
},
@Jabher
Jabher / application.js
Created August 30, 2013 13:12
rarjpeg detector
(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) {