Skip to content

Instantly share code, notes, and snippets.

View pokatomnik's full-sized avatar
💡
A man of idea

Danilian Akhmedzianov pokatomnik

💡
A man of idea
View GitHub Profile
@pokatomnik
pokatomnik / draw.js
Created November 6, 2018 21:20
Draw in the another window canvas
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 October 17, 2018 23:48
Web worker async task
/*
* 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 June 23, 2018 23:24
Bem utils for Javascript/Typescript
'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 February 9, 2018 23:35
Yandex interview tasks
// [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];
<?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">
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 August 28, 2017 01:15
This very simple example demonstrates why heavy CPU tasks is really bad idea for node.js (and browser javascript VM, of course)
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;
<!doctype html>
<html>
<head>
<style>
.list {
width : 250px;
}
.list table tbody tr td:first-child {
min-width: 250px;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
*, html, body {
margin: 0px;
padding: 0px;
}
table {
<!DOCTYPE html>
<html lang="ru">
<head>
<title>Format Date</title>
<meta charset="utf-8">
<style type="text/css">
input {
display : block;
}
</style>