Skip to content

Instantly share code, notes, and snippets.

// ==UserScript==
// @name lepratranslate
// @author RubaXa <trash@rubaxa.org>
// @license MIT
// @version 0.0.1
// @include http://leprosorium.ru/*
// ==/UserScript==
/*global unsafeWindow*/
/**
* OOP
* @author RubaXa <trash@rubaxa.org>
*/
(function (){
/**
* Создание «родительского» метода
* @param {*} fn
* @param {*} parent
@RubaXa
RubaXa / AbsudTpl.js
Last active August 29, 2015 14:02
AbsurdTpl — JavaScript micro-micro-templating, v0.3.1
(function () { 'use strict';
var indent = 0, tags = [], close, begin, rshort = /^(img|input|hr|br)$/;
window['absurdTpl'] = function _(name, template) {
return _[name] = Function('ctx', ('var buf = "";\n' + (template || name).toString().split('\n').slice(1, -1).map(function (line, idx, lines) {
return line.replace(/\/\/.+|\/\*.*?\*\//g, '')
.replace(/~([\w+_-]+)/i, 'buf += absurdTpl["$1"]')
.replace(/^(\s*)(?:([a-z]+[0-9]*)((?:\.[a-z_-]+[\w_-]+)*)((?:\[.*?\])*)(?:\s+\|\s+(.*?))?($|;)|.)/, function (_, ind, tag, classes, attrs, html) {
begin = (indent >= ind.length) && (close = tags.splice(0, indent/ind.length).filter(isNaN)).length ? 'buf += "</' + close.join('></') + '>";\n' : '';
indent = ind.length;
!rshort.test(tag) && tags.unshift(tag || 0);
@RubaXa
RubaXa / now.js
Created July 14, 2014 10:59
Get current timestamp + offset
/**
* @desc now("+year"), now("+3 months"), now("-13 min") or now("+86400 ms")
*/
(function () {
var R_ADD = /(?:([+-]?)\s*(\d*))\s*(year|month|day|hour|min|sec|ms)/;
var _getTime = Date.now || function () { return (new Date).getTime(); },
_cache = {},
_map = {
'year': 'FullYear',
@RubaXa
RubaXa / Pilot20.draft.js
Created December 16, 2014 11:52
Pilot v2 (draft)
/**
* Pilot v2 (draft)
* - Не зависит от jQuery
* - Модульность (URL, history, Emitter)
* - Простота (один маршрут, один контроллер)
*/
var app = {
// Глобальная дата
model: {
@RubaXa
RubaXa / 0example.js
Created April 24, 2012 06:13 — forked from Raynos/0example.js
IndexedDB API made better
// jsfiddle: http://jsfiddle.net/Pj7G4/1/
var store = indexeddbStore("user")
store.put({ name: "bob" }, "bob", function (err, result) {
store.get("bob", function (err, user) {
console.log(user.name === "bob")
})
})
@RubaXa
RubaXa / gist:4084463
Created November 16, 2012 05:33
xtpl vs. fest

Fest

<?xml version="1.0"?>
<fest:template xmlns:fest="http://fest.mail.ru" context_name="json">
	<div class="elm">
		<fest:attributes>
			<fest:attribute name="id">box</fest:attribute>
			<fest:attribute name="style">color: red;</fest:attribute>
			<fest:attribute name="class"><fest:space/>js-elm</fest:attribute>
@RubaXa
RubaXa / index.html
Created November 3, 2015 10:55
#feast: Check on-{event} attributeFeast. (http://jsbench.github.io/#1e8d00ac5eaf2f2a051d) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>#feast: Check on-{event} attributeFeast.</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@RubaXa
RubaXa / index.html
Created November 3, 2015 11:01
Feast. Detect expression. (http://jsbench.github.io/#c1dd834e0f683700f44c) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Feast. Detect expression.</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@RubaXa
RubaXa / index.html
Created November 20, 2015 19:07
CSS vs. Inline style (http://jsbench.github.io/#a9283bb254143ea63d7c) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>CSS vs. Inline style</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>