Skip to content

Instantly share code, notes, and snippets.

View embarq's full-sized avatar
🕶️
Working hard

Li Ihor embarq

🕶️
Working hard
View GitHub Profile
@embarq
embarq / responsify-table-plugin.js
Last active June 22, 2016 01:36
Responsify existing tables on the page. Common-case: you're can't add class to table-element e.g. (in my case) when you're using SSG(Static-Site Generator) that produce *.html from *.md templates
"use strict";
let tables = document.querySelectorAll("table");
let copy = collection => Array.prototype.slice.call(collection);
tables = copy(tables);
tables.forEach(item => {
let thead = copy(item.tHead.rows[0].cells).map(item => item.textContent);
let tbody = copy(item.tBodies).forEach(
tbody => copy(tbody.rows).forEach(
row => copy(row.cells).forEach(
(cell, index) => cell.setAttribute('data-title', thead[index]))));
@embarq
embarq / app.js
Last active June 18, 2016 23:17
HTML to MD by Node
"use strict";
var fs = require('fs');
var md = require('to-markdown');
var ic = require('iconv-lite');
var src = 'docs';
var dist = 'dist';
fs.readdir(src, (err, contents) => {
@embarq
embarq / app.js
Last active June 18, 2016 23:18
Simple number base-systems converter
function convert() {
"use strict";
let initialNotation = parseInt($("#initial-notation").prop('value'));
let resultNotation = parseInt($("#result-notation").prop('value'));
let initialValue = $("#initial-value").prop('value');
let resultValue = $("#result-value");
let valueWithExcess = $("#with-excess");
let toDecimalNotation = (value, notation) =>
@embarq
embarq / importer.cs
Created June 15, 2016 18:27
JSON Import
class Program
{
static void Main(string[] args)
{
string[] files = Directory.GetFiles(@"../../", "*.json");
foreach(string filename in files)
{
Console.WriteLine("File: " + filename);
List<dynamic> data = import(filename);
foreach(dynamic subset in data)
@embarq
embarq / index.html
Last active June 17, 2016 10:19
Clearfix
<header>...</header>
<div class="clearfix">
<section>...</section>
<aside>...</aside>
</div>
<footer>...</footer>
@embarq
embarq / app.js
Created June 17, 2016 18:11
Google Sheets response formatter
function isSheetExist(sheetName) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName) != null;
}
function formResponseFilter(e) {
if (!e) throw new Error("Please go the Run menu and choose Initialize");
try {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var base = ss.getSheets()[0];
var sheet = null;
@embarq
embarq / async.cs
Created June 18, 2016 23:14
.Net async
var request = service.Spreadsheets.Get(sheet_id);
var response = request.ExecuteAsync();
response.Wait(new CancellationToken(response.IsCompleted));
Console.WriteLine("Async request complited.");
@embarq
embarq / app.js
Created June 22, 2016 00:18
Encode/Decode Gray-code
// Грея => Дополнительный
"use strict";
let rand = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
let toDecimal = (value, notation) =>
value.split('').map((char, i, arr) =>
parseInt(char) * Math.pow(notation, arr.length - (i + 1)))
.reduce((sum, current) => sum + current);
@embarq
embarq / annotated.js
Last active June 23, 2016 18:30
`Gray` to `Additional` code conversion
"use strict";
let rand = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
// Перевод двоичного числа в десятичное
// Двоичное число приходит в ф-цию в виде строки
let toDecimal = (value) =>
value.split('') // Преобразуем строку в массив символов
// Считаем по формуле - https://goo.gl/eJ8KcJ
// Доп. читай про ф-ции `map` и `reduce`:
@embarq
embarq / update-google-sheets.cs
Created June 24, 2016 18:45
Update Google Sheet according to api.v4
var valueRange = new Google.Apis.Sheets.v4.Data.ValueRange();
var values = new List<string[]>();
var range = currentSheet.Title + "!H2:H" + currentSheet.Rows.Count + 1;
foreach (var row in currentSheet)
{
string[] cell = { row.Value[lastSheetCaption] };
values.Add(cell);
}