Skip to content

Instantly share code, notes, and snippets.

View kirpalmakanga's full-sized avatar

Kirpal Makanga kirpalmakanga

View GitHub Profile
@kirpalmakanga
kirpalmakanga / contains-html.js
Created October 10, 2018 08:54
Check if string contains html tags
export const containsHTML = (str) => /<[a-z][\s\S]*>/i.test(str);
@kirpalmakanga
kirpalmakanga / PropsRoute.js
Created September 27, 2018 14:30
React Router Route with props
import React from 'react';
import { Route } from 'react-router-native';
const renderMergedProps = (component, ...rest) => {
const finalProps = Object.assign({}, ...rest);
return React.createElement(component, finalProps);
};
const PropsRoute = ({ component, ...props }) => (
<Route
@kirpalmakanga
kirpalmakanga / basicToken.js
Last active August 23, 2018 13:35
Generate basic token
import { Buffer } from 'buffer';
const generateBasicToken = (user, pass) =>
new Buffer([user, pass].join(':')).toString('base64');
@kirpalmakanga
kirpalmakanga / compose.js
Last active July 18, 2019 20:04
Async Compose & Pipe
const asyncCompose = (…functions) => input => functions.reduceRight((chain, func) => chain.then(func), Promise.resolve(input));
const asyncPipe = (…functions) => input => functions.reduce((chain, func) => chain.then(func), Promise.resolve(input));
@kirpalmakanga
kirpalmakanga / FloatingLabelInput.js
Created July 30, 2018 13:31
Floating Label Input (React Native) (WIP)
import React, { Component } from 'react';
import { View, TextInput, Animated } from 'react-native';
import Icon from '../Icon';
export default class FloatingLabelInput extends Component {
state = {
isFocused: false
};
componentWillMount() {
@kirpalmakanga
kirpalmakanga / hexToRGBA.js
Last active October 19, 2018 12:55
hex to RGBA
const parseHex = (hex) => (startChar, endChar) =>
parseInt(hex.slice(startChar, endChar), 16);
function hexToRGBA(hex, a = 1) {
const r = parseHex(hex)(1, 3);
const g = parseHex(hex)(3, 5);
const b = parseHex(hex)(5, 7);
return `rgba(${r},${g},${b},${a})`;
}
@kirpalmakanga
kirpalmakanga / pipe.js
Last active August 22, 2018 08:16
Pipe function (sync)
const pipe = (...ops) => ops.reduce(
(a, b) => (...arg) => b(a(...arg))
)
@kirpalmakanga
kirpalmakanga / jsonSize.js
Last active January 18, 2018 14:19
Get json string size
const bytes = (s) => ~-encodeURI(s).split(/%..|./).length;
const jsonSize = (s) => bytes(JSON.stringify(s));
@kirpalmakanga
kirpalmakanga / walk.js
Created March 27, 2017 01:57
Node.js recursive directory walker (SYNC)
function walk(dirPath) {
const stats = fs.lstatSync(dirPath)
let type = mime.lookup(dirPath)
var data = []
if(stats.isFile()) {
data.push({
path: dirPath.replace(/\\/gi, '/'),
name: path.basename(dirPath),
type
@kirpalmakanga
kirpalmakanga / scanlines.scss
Created July 26, 2016 15:07
SASS Scanlines mixin
@mixin scanlines($color, $height: 1px, $angle: 0, $opacity: 0.2) {
position: relative;
&:after {
background-image: repeating-linear-gradient(to bottom, transparent 0 ,transparent $height, $color $height, $color $height * 2);
background-size: 100% $height * 2, cover;
transform-origin: 50% 50%;
transform: rotate($angle);
content: '';
opacity: $opacity;
position: absolute;