Skip to content

Instantly share code, notes, and snippets.

View autioch's full-sized avatar

Jakub Szczepaniak autioch

  • Poznań, Poland
View GitHub Profile
@autioch
autioch / index.html
Last active September 25, 2015 21:21
Simple draggable graph on canvas using ES6
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Graphs</title>
<style type="text/css">
body {margin:0}
canvas {display:block;background:#eee}
</style>
</head>
@autioch
autioch / snow.js
Created September 26, 2015 22:20
Old school snow for the website
(function(window, document) {
/* Modification
* reuqestAnimationFrame polyfill https://gist.github.com/paulirish/1579671
* hasFocus for old Opera if (!document.hasFocus) {document.hasFocus = function() {return true}}
* Styling with stylesheet:
* .snow {
* position: absolute;
* color: #fff;
* top: 0;
@autioch
autioch / jquery.fn.template.js
Created September 27, 2015 13:17
Template for jQuery Template
/* jQuery plugin template
* Replace Plugin__Constructor with name of constructor function.
* Replace plugin__name with string name, used for namespacing events, data binding.
**/
(function(Window, Document, $, factory) {
'use strict';
var theModule = factory($, Document);
@autioch
autioch / cssrules.js
Created October 18, 2015 01:14
Longest CSS rule in the page
(function(j, w) {
w.call(document.styleSheets).forEach(function(q) {
try { /* Accessing remote domain cssRules fails. */
w.call(q.rules || q.cssRules).forEach(function(k) {
(k.selectorText || '').split(',').forEach(function(b) {
(b.length > j.length) && (j = b);
});
});
} catch (z) {}
});
@autioch
autioch / readdir.js
Created November 25, 2015 21:19
Save dir contents to file
let dirToRead = 'e:/tmp';
let outputFile = 'e:/output.js';
fs.readdir(dirToRead, function(err, data){
if (err){
return console.log(err);
}
fs.writeFile(outputFile, "[\n'"+data.join("',\n'")+"'\n]");
});
@autioch
autioch / index.html
Created November 27, 2015 22:34
Charades - JS example.
<!DOCTYPE html>
<html>
<head>
<title>Kalambury (filmy)</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<style type="text/css">
body {
font-family: Verdana;
@autioch
autioch / colorSampler.js
Last active March 15, 2016 16:07
Sampling colors from png file.
'use strict';
// npm install png-js https://github.com/devongovett/png.js
// npm install image-size https://www.npmjs.com/package/image-size
const options = process.argv.slice(2);
if (options.length < 3) {
throw 'Required arguments: filename, cell width, cell height. Optional 4th argument: row spacing.';
}
@autioch
autioch / decimalCount.js
Created April 19, 2016 13:45
Node.js test
function countRegex(value) {
var match = ('' + value).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
if (!match) {
return 0;
}
return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0));
}
function countParse(value) {
var data = parseFloat(value).toString().split('.');
/* jQuery way */
$('*')
.filter(function(){
return !!$._data( this, 'events');
})
.get()
.reduce(function(dict, el){
dict[el.className] = Object.keys($._data( el, 'events')).sort().join(', ')
return dict;
}, {});
@autioch
autioch / ellipseRow.js
Created July 29, 2016 12:01
Ellipsing rows
module.exports = function ellipseRow(el) {
var maxLines = parseInt(el.getAttribute('max-rows'), 10);
var lineHeight = parseInt(getComputedStyle(el, null).getPropertyValue('line-height'), 10);
var padding = parseInt(getComputedStyle(el, null).getPropertyValue('padding'), 10);
var maxHeight = lineHeight * maxLines + 2 * padding;
var hiddenBrandCount = 0;
while (el.offsetHeight > maxHeight) {
hiddenBrandCount++;
el.textContent = el.textContent.substring(0, el.textContent.lastIndexOf(', '));