Skip to content

Instantly share code, notes, and snippets.

Avatar
💡
A man of idea

Danilian Akhmedzianov pokatomnik

💡
A man of idea
View GitHub Profile
@pokatomnik
pokatomnik / draw.js
Created Nov 6, 2018
Draw in the another window canvas
View draw.js
function getCanvas() {
const newWindow = window.open('');
const link = newWindow.document.createElement('link');
link.rel = 'stylesheet';
link.href = 'https://fonts.googleapis.com/css?family=Poor+Story';
link.onload = function () {
const newCanvas = newWindow.document.createElement('canvas');
const newContext = newCanvas.getContext('2d');
newWindow.document.body.appendChild(newCanvas);
@pokatomnik
pokatomnik / BackgroundTask.js
Created Oct 17, 2018
Web worker async task
View BackgroundTask.js
/*
* This is a simple example of web worker
* Background task is a class which creates a new thread.
* 'fn' is a heavy CPU utilization function
* 'start' method accepts only one argument (a message for web worker)
* Restrictions:
* - fn must be a pure function. It does not have an access to any outer scope vars.
* - fn must not be native function.
* - fn must not be bound to any 'this'
*/
@pokatomnik
pokatomnik / bem.js
Created Jun 23, 2018
Bem utils for Javascript/Typescript
View bem.js
'use strict';
// Creates an array of truthy elements
const joinTruthy = (glue, ...args) => args.filter(arg => arg).join(glue);
// Simple bem function
export const bemUnbound = (blockName, elementName, options = {}) => [
joinTruthy('__', blockName, elementName),
...Object
.entries(options)
@pokatomnik
pokatomnik / Yandex_task.js
Created Feb 9, 2018
Yandex interview tasks
View Yandex_task.js
// [1, 3, 5, 7, 8, 11, 12, 13, 20] -> 1,3,5,7-8,11-13,20
function short(arr) {
var sorted = arr.sort(function (a, b) {
if (a < b) { return -1; }
else if (a > b) { return 1; }
else { return 0; }
});
function add(res, newValue) {
var last = res[res.length-1];
View ListView_layout_android.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:clickable="true"
android:focusable="true"
android:layout_weight="1"
android:background="?android:attr/selectableItemBackground">
View bracers.js
const braces = '(())';
const checkConsistance = (str) => {
const res = str
.split('')
.reduce(
(acc, current) => ({
'(': () => { ++acc['(']; return acc; },
')': () => { ++acc[')']; return acc; }
})[current](), {
@pokatomnik
pokatomnik / node-cpu.js
Created Aug 28, 2017
This very simple example demonstrates why heavy CPU tasks is really bad idea for node.js (and browser javascript VM, of course)
View node-cpu.js
function load () {
for (var i=0; i<60000; ++i) {
for (var j=60000; j>=0; --j) {
a = i*j;
}
}
}
function cpuConsume(count, cpuLoadFunc) {
var num = 1;
View checkbox-list.html
<!doctype html>
<html>
<head>
<style>
.list {
width : 250px;
}
.list table tbody tr td:first-child {
min-width: 250px;
}
View table-row-pushing.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
*, html, body {
margin: 0px;
padding: 0px;
}
table {
View date-converter.html
<!DOCTYPE html>
<html lang="ru">
<head>
<title>Format Date</title>
<meta charset="utf-8">
<style type="text/css">
input {
display : block;
}
</style>