Skip to content

Instantly share code, notes, and snippets.

@lahmatiy
lahmatiy / 1_template_BEFORE.html
Last active Aug 29, 2015
Basis.js 1.3 features <b:isolate> and b:show in use. Example from devpanel style refactoring: https://github.com/basisjs/basisjs/commit/b17a8026684c3cd2e1a5a6fafac6b55ecefee236
View 1_template_BEFORE.html
<b:style src="./item.css"/>
<b:define name="nestedViewCount" type="bool"/>
<b:define name="satelliteName" type="bool"/>
<b:define name="namespace" type="bool"/>
<div class="basisjs-devpanel-ui-view-item">
<div class="basisjs-devpanel-ui-view-item__title" event-click="toggle" event-mouseenter="enter" event-mouseleave="leave">
<div class="basisjs-devpanel-ui-view-item__expander basisjs-devpanel-ui-view-item__expander_{nestedViewCount}"/>
<span class="basisjs-devpanel-ui-view-item__satelliteName basisjs-devpanel-ui-view-item__satelliteName_{satelliteName}">
{satelliteName}
@lahmatiy
lahmatiy / tests.js
Last active Aug 29, 2015
Closure vs Function#bind
View tests.js
//
// Closure
//
var a = []; // хранилище истансов, чтобы они не разрушались (не собирались GC)
var getClosure = function(a){ return function(b){ return fn(a, b); } };
var t = performance.now();
for (var i = 0; i < 10000; i++)
a.push(getClosure(i));
@lahmatiy
lahmatiy / wat.js
Last active Aug 29, 2015
elem.animate() as cool as not ready to use!
View wat.js
// create element with color green
var elem = document.createElement('div');
elem.style.color = 'green';
document.body.appendChild(elem); // add to document, to make getComputedStyle/animate works
console.log(getComputedStyle(elem).color); // rgb(0, 128, 0) - it's OK!
// add animation
var player = elem.animate([
{ color: 'red' },
{ color: 'blue' }
@lahmatiy
lahmatiy / _usage.js
Last active Aug 29, 2015
basis.data.ReadOnlyDataset#contains
View _usage.js
// we could create several effects for node/models and don't affect node/models
var source = new basis.data.Dataset({ items: [/* .. */]});
var modified = new basis.data.dataset.Filter({
source: source,
ruleEvents: 'rollbackUpdate',
rule: 'data.modified'
});
var customSet = new basis.data.Dataset();
var view = new basis.ui.Node({
View getRange.js
function getRange(str, start, end){
var lines = str
.split('\n')
.slice(start.line - 1, end.line);
return lines
.concat(lines.pop().substr(0, end.column))
.join('\n')
.substr(start.column - 1);
}
@lahmatiy
lahmatiy / enum.js
Last active Aug 29, 2015
Example of persistent user preferences using basis.js
View enum.js
//
// Enum class is proposed future citizen of basis.js
//
var Value = require('basis.data').Value;
var Enum = Value.subclass({
className: 'Enum',
init: function(){
@lahmatiy
lahmatiy / custom-progressbar.js
Last active Aug 29, 2015
Done on the knee progressbar
View custom-progressbar.js
var chalk = require('chalk');
var readline = require('readline');
var BAR_LENGTH = 40;
var lines = 0;
function repeatStr(str, len){
return new Array(parseInt(len) + 1).join(str);
}
function drawBarLine(fill, str){
@lahmatiy
lahmatiy / prevent-input.js
Last active Aug 29, 2015
Snippet for node.js to prevent any user input while script is working, but process ctrl+c to exit
View prevent-input.js
// doesn't work w/o this interface creation
require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
// stop process input
process.stdin.pause();
// read from stdin 10 times per second to check if ctrl+c pressed
@lahmatiy
lahmatiy / gist:5593176
Created May 16, 2013
Text that always in center and fit window size
View gist:5593176
<!doctype html>
<html>
<body>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 100 100" style="position: fixed; width: 100%; height: 100%">
<text x="0" y="81" fill="black" stroke="black" font-size="100">A!</text>
</svg>
</body>
</html>
@lahmatiy
lahmatiy / .bowerrc
Created Jun 1, 2013
Usually we store 2 files in project for bower: .bowerrc for settings & bower.json for description and dependencies. But we can use single file for both, just put everything into .bowerrc and set "json" property to ".bowerrc".
View .bowerrc
{
"json": ".bowerrc",
"directory": "lib",
"name": "my-project",
"version": "1.0.0",
"dependencies": {
"basisjs": "0.9.0"
}
}