Skip to content

Instantly share code, notes, and snippets.

View Semigradsky's full-sized avatar
😉

Dmitry Semigradsky Semigradsky

😉
View GitHub Profile
// функция, над которой будем издеваться
var add = function() {
return [].reduce.call(arguments, function(a,b) { return a+b; }, 0);
};
var part = function(fn, a) {
return function() {
var args = a.slice(), j = 0;
for (var i = 0; i < args.length; i++) {
if (args[i] === part.none) {
@Semigradsky
Semigradsky / fakepath.md
Last active August 29, 2015 14:22
fakepath

See about this

For historical reasons, the value IDL attribute prefixes the file name with the string "C:\fakepath". Some legacy user agents actually included the full path (which was a security vulnerability). As a result of this, obtaining the file name from the value IDL attribute in a backwards-compatible way is non-trivial. The following function extracts the file name in a suitably compatible manner:

function extractFilename(path) { if (path.substr(0, 12) == "C:\fakepath\") return path.substr(12); // modern browser var x; x = path.lastIndexOf('/');

@Semigradsky
Semigradsky / curry.js
Created September 18, 2015 09:51
Curry
export default function () {
'use strict';
var args = Array.prototype.slice.call(arguments),
fn = args.shift();
return function () {
fn.apply(null, args.concat(Array.prototype.slice.call(arguments)));
};
}
{
"AB": "Abkhazia",
"AD": "Andorra",
"AE": "United Arab Emirates",
"AF": "Afghanistan",
"AG": "Antigua and Barbuda",
"AI": "Anguilla",
"AL": "Albania",
"AM": "Armenia",
"AO": "Angola",
function template(str, obj) {
return str.replace(/\{(\w+)\}/g, (_, x) => {
const value = obj[x];
return Array.isArray(value) ? value.join(', ') : value;
});
}
/*
* Repeating the background mostly makes sense in the <body>. Otherwise, people
* usually want the image and preferably its center (not the top-right corner)
*/
*:not(body) {
background-repeat: no-repeat;
background-position: 50%;
background-size: cover;
}
// Manually simulating an apply() for constructors
var arr = [2011, 11, 24];
new (Function.prototype.bind.apply(
Date, [null].concat(arr)))
// Switching over an object’s constructor
try {
@Semigradsky
Semigradsky / Collection.js
Created March 26, 2017 10:54
cancellable async
function Collection(options) {
this.index = options.index || 'id';
this.format = options.format;
this.data = [];
this.indexes = {};
this.asyncTasks = new AsyncTasks();
}
var model = new Collection({
format: () => ({})
@Semigradsky
Semigradsky / index.md
Created May 6, 2017 08:38
truncate.js-tests
  truncate.js
    ✓ truncates nothing when content fits (52ms)
    1) truncate correctly with default options
    ✓ truncate correctly word with no space
    2) truncate correctly white space
    3) truncate correctly when container has no margin or padding
    4) truncate correctly when container has margin
    5) truncate correctly when container has padding
    6) truncate correctly when container has margin and padding

Вспомогательные функции:

function fac(x) {
  return x === 1 ? 1 : x*fac(x-1);
}

Практические аспекты обращения с деревьями

Число возможных топология для дерева.