Skip to content

Instantly share code, notes, and snippets.

@drzhbe
drzhbe / dom.js
Created June 6, 2017 23:11
DOM helpers
/*
What's better way to find a class match – `classes.indexOf(className)` or `for loop + return`?
*/
function hasClass(el, className) {
var classes = el.className.split(' ');
for (var i = 0; i < classes.length; i++) {
if (classes[i] === className) {
return true;
}
@drzhbe
drzhbe / collectEvents.qml
Created April 3, 2017 08:36
view events on timeline
property bool collecting: false
property var bbbbb: {
if (!collecting) {
collecting = true;
collect(branchCardBody)
}
}
function newEvent(item, eventName) {
var globalCoord = item.mapToItem(null, 0, 0);
@drzhbe
drzhbe / alert1.js
Created November 25, 2016 06:44
Script with alert(1) to test XSS
alert(1)
/*
@param {Object} node
@param {Number} spacing
*/
function traverse(node, spacing) {
console.info('NODE ::', _spacing(spacing), node)
var children = node.data;
if (!children) return
@drzhbe
drzhbe / Filters.qml
Last active December 29, 2015 09:26
Лэйаут фильтров
import QtQuick 2.3
// @TODO (salnikov): добавить минимальные отступы клеткам
Rectangle {
width: 200
height: 600
property real maxWidth: 200
property real maxWidthHalf: maxWidth / 2
@drzhbe
drzhbe / binaryClosestSearch.js
Created November 26, 2015 10:31
Binary search for closest value
/*!
Бинарный поиск ближайшего значения. Если значение за пределами списка, возвращает индекс крайнего элемента.
Возвращает индекс найденного элемента.
x >> 1 === Math.floor(x / 2)
\param type:array list
\param type:number value
\param type:function getVal функция, которая достает нужное значение из элемента списка list
@drzhbe
drzhbe / watch_qml.sh
Created April 9, 2015 08:53
on file change push it to the phone and restart the app
#!/bin/bash
# exclude ".qml.*" because QtCreator on change 'Transport.qml' creates additional file like 'Transport.qml.R12384'
cd src/v4qml
inotifywait -mre close_write --exclude '\.qml\.' --format "%w %f" . | while read dir file; do
# cut './' from the path './RegionUI/...' → 'RegionUI/...'
f="${dir:2}$file"
echo "Changed: $f"
# @TODO change 'drz' to $1
adb push "$f" "/sdcard/drz/$f"
adb shell am force-stop ru.dublgis.dgismobile
@drzhbe
drzhbe / once.js
Last active August 29, 2015 14:18
`once` for QML
/*!
\brief Если `flag` праведный, то выполнить `callback`, иначе подписаться на событие `sig`
Варианты реализации `flag`:
1. передать имя свойства (+ в любой момент времени можно проверить актуальность флага)
2. передать функтор (+ в любой момент времени можно проверить актуальность флага)
3. передать значение свойства (- узнать значение флага можно только в текущий момент времени)
Здесь используется последний, где `flag` — это буль
\param type:bool flag
\param type:Signal sig
\param type:function callback
@drzhbe
drzhbe / prgrss.js
Last active December 19, 2017 05:00
Show reading progress on scroll
(function() {
var willHide = false;
var msgBox = document.createElement('div');
msgBox.style.position = 'fixed';
msgBox.style.top = '10px';
msgBox.style.right = '10px';
msgBox.style.display = 'none';
document.body.appendChild(msgBox);
@drzhbe
drzhbe / trnslt.js
Last active January 20, 2020 03:57
Click on english word to translate it into russian. Translation will be logged into console.
/**
* <a href='http://api.yandex.ru/dictionary/'>Реализовано с помощью сервиса «API «Яндекс.Словарь»</a>
*/
(function() {
const YANDEX_DICTIONARY_KEY = 'dict.1.1.20150130T172350Z.0895b15babe24c90.431f35fa9af476be1b6d14d80f3809ab693a5970';
const DICTIONARY_URL = `https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key=${YANDEX_DICTIONARY_KEY}&lang=en-ru`
function translate(word) {
fetch(`${DICTIONARY_URL}&text=${word}`)
.then(res => res.json())