Skip to content

Instantly share code, notes, and snippets.

View kirpalmakanga's full-sized avatar

Kirpal Makanga kirpalmakanga

View GitHub Profile
@kirpalmakanga
kirpalmakanga / scss
Created September 22, 2015 16:41
SCSS Font-Face Mixin
@mixin font-face($font-family, $file-path, $font-weight, $font-style) {
@font-face {
font-family: $font-family;
src: url('#{$file-path}.eot');
src: url('#{$file-path}.eot?#iefix') format('embedded-opentype'),
url('#{$file-path}.woff') format('woff'),
url('#{$file-path}.ttf') format('truetype'),
url('#{$file-path}.svg##{$font-family}') format('svg');
font-weight: $font-weight;
font-style: $font-style;
@kirpalmakanga
kirpalmakanga / mixins.scss
Last active October 20, 2015 14:49
Useful SCSS Mixins
//////* Transition *//////
@mixin transition($property: all, $duration: 0.5s, $easing: ease-out) {
transition: $property $duration $easing;
}
@mixin delay($duration: 0.5s) {
transition-delay: $duration;
}
//////* Transforms *//////
@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;
@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 / 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 / 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 / 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 / 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 / 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 / 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');