Skip to content

Instantly share code, notes, and snippets.

View mikemcbride's full-sized avatar
🍪
accepting cookies

Mike McBride mikemcbride

🍪
accepting cookies
View GitHub Profile
@mikemcbride
mikemcbride / annoying CSS background animation
Created March 29, 2016 03:17
Super annoying CSS background color animation
// for fun
// add the "annoying" class to anything to give your friends a seizure.
// see it in action:
// http://codepen.io/mmcbride1007/pen/QNMWpe
.annoying {
animation: pulse .2s infinite;
}
@keyframes pulse {
@mikemcbride
mikemcbride / getObjectIndex.js
Created June 6, 2016 18:02
Get the index of an object in an array based on a property
function getObjectIndex (array, key, term) {
return array.indexOf(array.find(it => it[key] === term))
}
// Example: find the index of the object where object.foo == 'apple'
const myArray = [
{
'foo': 'foo',
'bar': 'bar',
'baz': 'baz'
/* hot pink from HTML5 boilerplate */
.hotpink {
color: #fe57a1;
}
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@mikemcbride
mikemcbride / .hyper.js
Created February 26, 2019 14:15
Cannot install plugins using `hyper i {plugin}`
module.exports = {
config: {
shell: '/usr/local/bin/fish',
updateChannel: 'canary',
fontSize: 15,
lineHeight: 1.2,
fontWeight: 'normal',
fontWeightBold: 'normal',
fontFamily: 'Fira Mono',
cursorShape: 'UNDERLINE',
@mikemcbride
mikemcbride / ScrollProgress.vue
Last active August 6, 2019 20:42
Scroll Progress indicator in Vue
<template lang="html">
<div :style="progress"></div>
</template>
<script>
export default {
name: 'ScrollProgress',
data() {
return {
scrollY: 0,
@mikemcbride
mikemcbride / convertMarkdownToAnchor.js
Created August 15, 2019 21:54
Regex to replace markdown links with their rendered HTML counterpart
// convert a string of markdown that has anchor tags into it to have the rendered anchor tags
const html = `your markdown goes here`
const r = /\[(.*)\]\((.*)\)/gmi
function linkReplacer(match, p1, p2) {
return `<a href="${p2}" target="_blank" rel="nofollow noreferrer">${p1}</a>`
}
const newHtml = html.replace(r, linkReplacer)
@mikemcbride
mikemcbride / uniq.js
Created September 18, 2019 19:06
Get unique values from an array in JS
function uniq(arr) {
let result = []
let seen = new Set()
for (let val of arr) {
if (!seen.has(val)) {
seen.add(val)
result.push(val)
}
}
@mikemcbride
mikemcbride / sortBy.js
Created September 18, 2019 19:07
Lightweight function that mostly replaces lodash's sortBy
// takes an array of objects, an array of properties to sort by,
// and optionally a case-sensitive parameter (defaults to false)
// returns an array sorted by the given properties, in order.
const sortBy = function(arr, props, sensitive = false) {
// make sure we have an array.
if (!Array.isArray(props)) {
props = [props]
}
@mikemcbride
mikemcbride / uniqBy.js
Created September 18, 2019 19:10
Like uniqBy from lodash without needing all of lodash
// unique array of objects by specific key
const uniqBy = function (arr, key) {
let seen = new Set()
return arr.filter(it => {
let val = it[key]
if (seen.has(val)) {
return false
} else {
seen.add(val)