Skip to content

Instantly share code, notes, and snippets.

@madox2
madox2 / draw_lines_using_div.js
Created August 7, 2016 15:29
draw lines on html page using div elements
/**
* Creates line element on given position, with given length and angle.
*/
function createLineElement(x, y, length, angle) {
var line = document.createElement("div");
var styles = 'border: 1px solid black; '
+ 'width: ' + length + 'px; '
+ 'height: 0px; '
+ '-moz-transform: rotate(' + angle + 'rad); '
+ '-webkit-transform: rotate(' + angle + 'rad); '
@madox2
madox2 / intercept_console_log.js
Created August 7, 2016 15:34
intercept console.log method
/**
* This function extends console.log functionality with given logger.
* @param {function} logger - Custom logger
*/
function extendLog(logger) {
var original = console.log;
console.log = function() {
logger(Array.prototype.slice.call(arguments));
return original.apply(this, arguments);
}
@madox2
madox2 / retry_promise.js
Created August 7, 2016 15:35
retry promise extension
/**
* This script uses ECMAScript 2015 syntax.
* Check compatibility for your environment.
* To run it in nodejs (5.8.0) you need to enable feature flags:
* --harmony_destructuring --harmony_rest_parameters --harmony_default_parameters
*/
"use strict"
/**
@madox2
madox2 / asynchronous_tasks_sequentially.js
Created August 7, 2016 15:37
run asynchronous tasks sequentially
/**
* Returns promise which runs given callback functions in series and
* collect results in array.
*
* @param {array} promises - array of callback functions
*/
function promiseAllSeq(promises) {
var data = [];
return promises.reduce((p, fn) => p.then(fn).then(i => (data.push(i), data)), Promise.resolve());
@madox2
madox2 / intercept_module.js
Last active August 10, 2016 20:28
intercepting module in node
const M = require('module')
const _load = M._load;
M._load = function(request, ...rest) {
const _module = _load(request, ...rest)
if (request === './module1.js') {
return function(...args) {
console.log(`intercepting ${request}`)
_module(...args)
}
@madox2
madox2 / windows-1250_to_utf-8.py
Created August 26, 2016 18:56
Could be useful when encoding subtitles
#!/usr/bin/python
import sys
import urllib
source_enc = 'windows-1250'
target_enc = 'utf-8'
print '============================================='
print '=== conversion from windows-1250 to utf-8 ==='
print '============================================='
import React, { Component } from 'react'
import { theme, Text, View, withStyles } from 'react-native-themeable'
const redTheme = withStyles([
{
$type: Text,
color: 'white',
fontSize: 26,
}, {
$type: View,
@madox2
madox2 / vim_eslint_fix.vim
Created October 12, 2016 16:22
Function which runs eslint --fix and saves the buffer. It is mapped to :W command
function ESLintFix()
write
silent execute "!./node_modules/.bin/eslint --fix %"
edit! %
redraw!
endfunction
command W call ESLintFix()
@madox2
madox2 / git_lg_alias
Created November 9, 2016 22:40
git lg alias
git config --global alias.lg "log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all"
@madox2
madox2 / snippets.js
Created August 8, 2017 18:46
Snippets to prettify
const a = {b: 1, c: 2}
cost Component = () => (
<div prop={1}
other={2} />
)
import { hahahahahahaha, heheheheheheh, huhuhuhuhuhu, hihihihihihi, hohohohoho } from 'react-hahahaha-heheheh-huhuhu'
function foo(