Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mir4a's full-sized avatar
🤞

Myroslav mir4a

🤞
View GitHub Profile
@mir4a
mir4a / resize-photo.sh
Last active July 2, 2019 09:55
Resize all image files in particular directory and put them in separate directory
#!/bin/sh
while [ "$#" -gt 0 ]; do
case "$1" in
-w) width="$2"; shift 2;;
-h) height="$2"; shift 2;;
-p) filepath="$2"; shift 2;;
-m) mask="$2"; shift 2;;
--width=*) width="${1#*=}"; shift 1;;
#!/bin/sh
while [ "$#" -gt 0 ]; do
case "$1" in
-s) substr="$2"; shift 2;;
-r) replace="$2"; shift 2;;
-p) filepath="$2"; shift 2;;
--substr=*) substr="${1#*=}"; shift 1;;
--replace=*) replace="${1#*=}"; shift 1;;
@mir4a
mir4a / svg-polygon-normalizer.js
Created April 8, 2016 11:54
Normalize svg polygon coordinates relative to viewBox
// For example, if you need to "normalize" viewBox minX, minY to 0,
// like this: was viewBox="-270 265 18 32", became viewBox="0 0 18 32"
// in this case polygon points should be converted into relative to viewBox values
// <polygon points="-268.6,265.8 -268.6,270.8 -258.4,281 -268.6,291.2 -268.6,296.2 -253.4,281" />
// This function will convert those point, it accepts two 3 params: points string, minX and minY
// Use example:
// var normalizedPlygon = svgPolygonNormalizer("-268.6,265.8 -268.6,270.8 -258.4,281 -268.6,291.2 -268.6,296.2 -253.4,281", -270, 265);
// console.log(normalizedPlygon);
// > '1.40,0.80 1.40,5.80 11.60,16.00 1.40,26.20 1.40,31.20 16.60,16.00'
const fs = require('fs');
const path = require('path');
function printToHTMLColorMap() {
const header = `
<!doctype html>
<html>
<head>
<title>16 lime colors</title>
@mir4a
mir4a / getAllColors.js
Created March 24, 2016 13:09
get colors (hex, rgb, rgba) from predefined directory. Work on Node 5.9
const fs = require('fs');
const path = require('path');
const dirToParse = 'app/assets/stylesheets/nv';
const skipFile = 'app/assets/stylesheets/nv/shared/colors.scss'
const colorRegexp = /(#[A-Z\d]{3}\b|#[A-Z\d]{6}\b)|(rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?([, \.\d]+)?\))/gi;
const variableMap = new Map();
const process = require('process');
const args = processArguments(process.argv);
var colorMap = new Map();
var fileCounter = 0;
@mir4a
mir4a / FRSHBKS.js
Created February 4, 2016 17:15
Simple bookmarklet which is prints to console list of tasks was done from Freshbooks report (Time Sheets Detailed).
javascript:
var fr_pat = /#gh-(\S+): /g;
var fr_str = '';
$('.report tr').each(function(i,el) {
$td = $(el).find('.text_wrap').eq(3);fr_str += $td.text().replace(fr_pat, '- ') + '\n';
});
console.log(fr_str);
@mir4a
mir4a / ajax_requests.rb
Created September 11, 2015 16:14
Setter/getter for some particular global var and increment on each Ajax request for Capybara tests
def set_ajax_counter(global_var)
page.execute_script <<-SCRIPT
window["#{global_var}"] = 0;
$(document).on("ajaxSend", function(){
window["#{global_var}"]++;
console.log('increment ajax counter window["#{global_var}"] = ' + window["#{global_var}"]);
});
SCRIPT
end
@mir4a
mir4a / click_on_day_at_datepicker.rb
Created September 11, 2015 16:09
Datepicker helper for Capybara with RSpec tests
def click_on_day_at_datepicker(date)
d = Date.parse(date)
month = d.strftime('%b')
day = d.day
# XPath select Month switcher
xpath_month_switcher_selector = '//div[contains(@class, "datepicker-days") and not(contains(@style,"display:none"))]//th[contains(@class, "datepicker-switch")]'
find(:xpath, xpath_month_switcher_selector).click
# XPath select particular Month
xpath_particular_month_selector = "//div[contains(@class, \"datepicker-months\") and not(contains(@style,\"display:none\"))]//*[text() = \"#{month}\"]"
find(:xpath, xpath_particular_month_selector).click
@mir4a
mir4a / fs.js
Last active August 29, 2015 14:27
Skip annoying ads on fs.to
javascript:
(function (){
var iframe_wrap = document.getElementsByClassName('b-iframe-aplayer')[0],
_i = iframe_wrap.getElementsByTagName('iframe')[0],
player = _i.contentDocument.getElementById('player'),
teasers = _i.contentDocument.getElementsByClassName('b-aplayer-teasers')[0],
duration = player.duration;
teasers.style.visibility = 'hidden';
player.currentTime = duration;
@mir4a
mir4a / gist:06380fca2e839a01ad6c
Created February 19, 2015 12:37
Real hell SCSS
div#home-store-info {
@extend .hidden-xs;
@extend .col-sm-12;
@extend .col-md-12;
margin-bottom: 20px;
div.store-info-block {
background-color: rgba(255, 255, 255, 0.4);
color: #1b6a8e;
@extend .row;