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 / vmrss
Last active May 8, 2023 15:30
Bash implementation of the vmrss linux util
#!/usr/bin/env bash
if [[ "${1}" == "" ]]; then
echo "must provide a process"
exit 1
fi
while :
do
ps -o rss "${1}" | tail -1 | numfmt --to=si
@mikemcbride
mikemcbride / _get.js
Created November 14, 2019 14:22
Like _get from lodash but with zero dependencies
const _get = function(object, path, defaultVal) {
const _path = Array.isArray(path)
? path
: path.split('.').filter(i => i.length)
if (!_path.length || object === undefined) {
return object === undefined ? defaultVal : object
}
return _get(object[_path.shift()], _path, defaultVal)
@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)
@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 / 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 / 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 / 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 / .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',
# 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 ->
/* hot pink from HTML5 boilerplate */
.hotpink {
color: #fe57a1;
}