Skip to content

Instantly share code, notes, and snippets.

View rohozhnikoff's full-sized avatar

Murad R. rohozhnikoff

  • Kyiv, Ukraine
View GitHub Profile
@rohozhnikoff
rohozhnikoff / styler.js
Last active August 12, 2016 17:10
[react-native] style creator
import { Platform, StyleSheet } from 'react-native';
function prepareStyles(stylesheet) {
return StyleSheet.create(
mapValues(
stylesheet,
function wrapPlatformSpecificRules(rules) {
rules['ios'] && rules['ios'] = Platform.select({'ios': rules['ios']});
rules['android'] && rules['android'] = Platform.select({'android': rules['android']})
return rules;
@rohozhnikoff
rohozhnikoff / storage.js
Last active August 31, 2018 08:23
[react-native] wrapped AsyncStorage with JSON support
import { AsyncStorage } from 'react-native';
const JSONAsyncStorage = Object.assign({}, AsyncStorage, {
getItem() {
return AsyncStorage.getItem.apply(null, arguments).then((res) => JSON.parse(res));
},
setItem(key, value) {
return AsyncStorage.setItem(key, JSON.stringify(value))
}
});
@rohozhnikoff
rohozhnikoff / perfetta.jsx
Last active July 21, 2016 16:13
[react-native] Pixel-perfect component
/* todo:
* make the opacity-management buttons (remove from props)
* inside block (not only root)
* wrap block
* scrollable !
* */
import React, { Component, PropTypes } from 'react';
import {
Text, View, StyleSheet, TouchableOpacity, Image, Dimensions
@rohozhnikoff
rohozhnikoff / assignAt.js
Last active February 11, 2016 11:15
better assign for redux reducers
import {isString, assign, reduce, map, keys, isPlainObject, isNull} from 'lodash';
export const isKeyValue = function isKeyValue(h) {
return isPlainObject(h) && !isNull(h)
};
export const assignAt = function assignAt(hash, path, newValue) {
if (isKeyValue(path)) {
return assign({}, hash,
keys(path).reduce((memo, key) => assignAt(memo, key, path[key]), hash)
@rohozhnikoff
rohozhnikoff / memux.js
Last active November 22, 2015 03:58
memux = redux + memoize for stream-like flow
/**
* {key: reducerFunc}, {key: initialReducerValue}
* */
function createStore(reducers, initial) {
var _handle = function () {
};
var _STATE = initial || {},
_reducersNames = Object.keys(reducers);
return {
@rohozhnikoff
rohozhnikoff / jquery-to-react.jsx
Last active November 6, 2015 19:15
jquery-to-react quick concept
/* генерим react-компоненты из под серверных шаблонов */
var ReactDOM = require('react-dom');
var React = require('react');
const findAndRender = (function () {
const options = {
className: 'jr',
classNameActivated: 'jr-activated'
@rohozhnikoff
rohozhnikoff / webworker-as-promise.js
Last active August 29, 2015 14:27
web worker as a promise
// Usage
var workerFibo = createPromiseWorker(function(x){
return (function fibo(n){
if (n > 1) {
return fibo(n - 1) + fibo(n - 2);
} else {
return 1;
}
})(x)
});
@rohozhnikoff
rohozhnikoff / page-rank.coffee
Created June 27, 2015 18:45
базовый алгоритм для пересчета перетеканий внутреннего page-rank
_ = require('lodash')
raw = {
main: {
pr: 1
in: {}
out: [
'login'
'tabs'
]
var logs = []
var logger = function (moduleName, eventName, data) {
logs.push({
'module': moduleName,
'event': eventName,
'data': data
});
};
@rohozhnikoff
rohozhnikoff / loadPropsMixin.js
Created May 24, 2015 16:22
concept to load data before render, in react
React.createComponent({
mixins: [
loadPropsMixin
],
loadProps: {
users: api.get('/users')
},
})