Skip to content

Instantly share code, notes, and snippets.

View finom's full-sized avatar
🇺🇦
Slava Ukraini!

Andrii Gubanov finom

🇺🇦
Slava Ukraini!
View GitHub Profile
@finom
finom / addeventlistener.js
Created August 22, 2014 13:32
Simple addEventListener polyfill for IE8
( function( win, doc, s_add, s_rem ) {
if( doc[s_add] ) return;
Element.prototype[ s_add ] = win[ s_add ] = doc[ s_add ] = function( on, fn, self ) {
return (self = this).attachEvent( 'on' + on, function(e){
var e = e || win.event;
e.target = e.target || e.srcElement;
e.preventDefault = e.preventDefault || function(){e.returnValue = false};
e.stopPropagation = e.stopPropagation || function(){e.cancelBubble = true};
e.which = e.button ? ( e.button === 2 ? 3 : e.button === 4 ? 2 : e.button ) : e.keyCode;
fn.call(self, e);
@finom
finom / Hello World.html
Last active December 1, 2015 13:36
Matreshka.js: From simple to simple
<!DOCTYPE html>
<html>
<head>
<title>My first application on the base of Matreshka</title>
</head>
<body>
<input type="text" class="my-input">
<div class="my-output"></div>
<script src="http://cdn.jsdelivr.net/matreshka/latest/matreshka.min.js"></script>
<script src="js/app.js"></script>
@finom
finom / Hello World.js
Created December 1, 2015 13:37
Matreshka.js: From simple to simple
var Application = Class({
'extends': Matreshka,
constructor: function() {
// bind x property to the text field
this.bindNode( 'x', '.my-input' );
// bind x property and block to my-output class
this.bindNode( 'x', '.my-output', {
setValue: function( v ) {
@finom
finom / data.js
Created December 1, 2015 14:28
Matreshka.js: From simple to simple
var data = [{
name: 'Ida T. Heath',
email: 'ida@dayrep.com',
phone: '507-879-9766'
}, {
name: 'Robert C. Burkhardt',
email: 'rburkhardt@teleworm.us',
phone: '321-252-5698'
}, {
name: 'Gerald S. Reaves',
@finom
finom / orderby.js
Last active September 5, 2017 05:15
Orderby JavaScript function
var orderBy = function(arr, keys, orders) {
var defaultOrder = 'asc',
newArr,
length,
i,
commonOrder;
if ('length' in arr && typeof arr == 'object') {
if (!(orders instanceof Array)) {
@finom
finom / getUniqueNumber.js
Created April 18, 2017 19:04
Get unique number
// Some math based on https://en.wikipedia.org/wiki/Discrete_logarithm
// The function fastModularExponentiation allow to generate
// pseudo-random unique number from 0 to prime - 1.
// In other words every gotten number is converted to another number and returned numbers are unique
// Warning! When number arg is more than prime then returned numbers are going to be repeated
// thus for biggrer numbers we'll need to choose bigger prime number.
// The implementation if fastModularExponentiation is taken there https://gist.github.com/krzkaczor/0bdba0ee9555659ae5fe
// Primitive root calc: http://www.bluetulip.org/2014/programs/primitive.html
@finom
finom / r.js
Created April 20, 2017 17:08
DOM-ready in 81 ASCII chars; can you do smaller?
r=(f,d=document)=>d.readyState[0]=='l'?d.addEventListener('DOMContentLoad',f):f()
@finom
finom / postCSSImportLoadJSHook.js
Created March 4, 2018 19:17
The function enhances postcss import plugin allowing CSS files to @import JS files
const readCache = require('read-cache');
const fs = require('fs');
const { NodeVM, VMScript } = require('vm2');
const optional = require('optional');
/*
The function enhances postcss import plugin allowing CSS files to @import JS files
which, in their turn, import a valid PostCSS string.
Example code:
@finom
finom / NiceGradient.js
Last active April 22, 2020 20:49
Nice looking iOS-like linear gradients preset for react native based on https://www.behance.net/gallery/62158409/Gradients-Color-Style
/*
Usage:
<NiceGradient index={9} style={StyleSheet.absoluteFill} />
Where index is an index from gradients array (0...14) based on https://www.behance.net/gallery/62158409/Gradients-Color-Style
*/
import React from 'react';
import { LinearGradient } from 'expo-linear-gradient';
export const gradients = [
['#FF6CAB', '#7366FF'],
@finom
finom / Touchable.js
Last active December 16, 2020 17:09
[finom/react-native-touchable] A universal Touchable (React Native) which behaves like TouchableOpacity on iOS but like TouchableNativeFeedback on Android
import { TouchableOpacity, TouchableNativeFeedback, Platform } from 'react-native';
import { createElement } from 'react';
// use TouchableNativeFeedback for android and TouchableOpacity for ios
// use TouchableOpacity with activeOpacity=1 for both platforms if disabled=true
const Touchable = ({
disabled,
onPress,
...props
}) => {