Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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
/*
@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 / alert1.js
Created November 25, 2016 06:44
Script with alert(1) to test XSS
alert(1)
@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 / 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 / class.js
Last active May 7, 2018 04:12
Store state: Class vs Closure
/**
* Takes prefixes and suffixes from first occurence of those and populate them to all other values.
* Wrapper function wraps valid numbers and gets rid of NaNs.
*
* Example:
* const wrap = valueFormatter(['$10', '20', '30']);
* const label = wrap(10); // '$10'
*/
class ValueFormatter {
prefix: string = '';
function translateSelector(original){
let result = original.replace(simpleRe, (match, value) => {
return replace(match, value);
}).replace(attributeRe, (match, op, value) => {
switch (op) {
case '=':
console.log('=', match, value)
return replace(match, value);
case '^=':
console.log('^=', match, value)
import * as React from 'react';
type Store = { treasure: number };
type Presenter = { digTreasure: (store: Store, place: string) => void };
type MyCompo1Props = { store: Store, presenter: Presenter };
class MyCompo1 extends React.Component<MyCompo1Props> {
render() {
/* should be an error because `this` in `digTreasure` will be not as expected */
return <MyCompo2 onDig={this.digTreasure}/>;