Skip to content

Instantly share code, notes, and snippets.

Ben Frain benfrain

Block or report user

Report or block benfrain

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@benfrain
benfrain / init.vim
Last active Nov 12, 2019
neovim config
View init.vim
if &compatible
set nocompatible " Be iMproved
endif
let mapleader=","
" Required:
filetype plugin indent on
" Only set syntax highlighting once!
if !exists("g:syntax_on")
syntax enable
@benfrain
benfrain / postcss.config.js
Created Mar 18, 2019
PostCSS Config file (for Parcel)
View postcss.config.js
var colors = require("./global/css/variables");
module.exports = {
plugins: [
require("autoprefixer"),
require("postcss-simple-vars")({ variables: colors }),
require("postcss-nested"),
require("postcss-color-function"),
],
};
View tsconfig.json
{
"compilerOptions": {
"module": "ES6",
"noImplicitAny": true,
"allowJs": true,
"lib": ["ES2016"],
"target": "ES6"
}
}
@benfrain
benfrain / animateNumericValues.ts
Last active Feb 7, 2019
JS utility to animate numeric values from one value to another
View animateNumericValues.ts
/**
* [animateNumericValues interpolates from one number to another with a max of 60 integers per second]
* @param {Element} element [The DOM element that will get interpolated]
* @param {number} fromValue [the first value]
* @param {number} toValue [the final value]
* @param {number} speed [how long the animation should take in milliseconds]
* @param {delay} delay [any delay before it starts counting up]
* @param {string} appendString [optional string that gets appended to the value. E.g. "%"]
*/
function animateNumericValues({
@benfrain
benfrain / .zshrc
Last active Jan 9, 2019
zshrc file
View .zshrc
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
@benfrain
benfrain / gulp.fork.js
Last active Oct 8, 2018
Gulp forking a stream (e.g. send different files to different dests)
View gulp.fork.js
gulp.task("ts", function() {
// These would be the names of two source files for example
tsRootFiles = ["rab", "buildRab"];
tsRootFiles.forEach(tsFile => {
let stream = gulp
.src(`ts/${tsFile}.ts`)
.pipe(sourcemaps.init())
.pipe(
ts({
@benfrain
benfrain / wrap.ts
Last active Sep 10, 2018
Finds numbers and currency codes and wraps them in an element
View wrap.ts
/**
*
* @param inputString a string of text that may or may not include numbers and a currency unit
* @returns a string of text where a number followed by a currency unit is wrapped in spans for styling
*/
function wrapUnits(inputString: string) {
let regNum = new RegExp("([0-9]+)", "gm");
let regUnit = new RegExp("(GBP|EUR)", "gm");
// It needs to match the currency unit or we are not interested
if (inputString.match(regUnit)) {
@benfrain
benfrain / ISO-639-1-language.json
Created Apr 16, 2018 — forked from jrnk/ISO-639-1-language.json
ISO 639-1 Alpha-2 codes of languages JSON
View ISO-639-1-language.json
[
{
"code": "ab",
"name": "Abkhaz"
},
{
"code": "aa",
"name": "Afar"
},
{
@benfrain
benfrain / rand.js
Created Jan 30, 2018
Random Array Picker
View rand.js
// Feed it an array and it will return you one entry from the array
function rand(array) {
return array[Math.floor(Math.random() * array.length)];
}
// Example
var sausages = [
"Lincolnshire",
"Cumberland",
"Manchester",
@benfrain
benfrain / getClosest.js
Created Jan 12, 2018
Get Closest Selector from clicked item (starts on target and works up the tree)
View getClosest.js
// Adapted from https://gomakethings.com/climbing-up-and-down-the-dom-tree-with-vanilla-javascript/
/**
* Get the closest matching element up the DOM tree.
* @private
* @param {Element} elem Starting element
* @param {String} selector Selector to match against
* @return {Boolean|Element} Returns null if not match found
*/
var getClosest = function(elem, selector) {
// Get closest match
You can’t perform that action at this time.