Skip to content

Instantly share code, notes, and snippets.

View markmichon's full-sized avatar

Mark Michon markmichon

View GitHub Profile
@markmichon
markmichon / devto.js
Created March 9, 2020 02:04
Dev.to API client example
const fetch = require("isomorphic-unfetch");
const querystring = require("querystring");
class DevTo {
constructor(config) {
this.api_key = config.api_key;
this.basePath = "https://dev.to/api";
}
request(endpoint = "", options = {}) {
let url = this.basePath + endpoint;
@markmichon
markmichon / CircuitBreaker-configurable.js
Last active April 18, 2021 03:10
Circuit Breaker examples
class CircuitBreaker {
constructor(request, options = {}) {
const defaults = {
failureThreshold: 3,
successThreshold: 2,
timeout: 6000
}
Object.assign(this, defaults, options, {
request,
state: "CLOSED",
@markmichon
markmichon / CircuitBreaker.js
Last active July 23, 2021 21:13
Basic CircuitBreaker Node
class CircuitBreaker {
constructor(request) {
this.request = request
this.state = "CLOSED"
this.failureThreshold = 3
this.failureCount = 0
this.successThreshold = 2
this.successCount = 0
this.timeout = 6000
this.nextAttempt = Date.now()
@markmichon
markmichon / applyToKeys.js
Last active August 20, 2019 15:48
Modify values in an object recursively
function applyToKeys(obj, modify) {
let newObj = {}
for (let [key, value] of Object.entries(obj)) {
if (typeof value === 'object') {
newObj[key] = applyToKeys(obj[key], modify)
} else {
newObj[key] = modify(value)
}
}
return newObj
@markmichon
markmichon / gulpfile.js
Created July 3, 2018 16:54
Example gulpfile with browsersync and gulp-sass
const gulp = require('gulp')
const sass = require('gulp-sass')
const browserSync = require('browser-sync').create()
const reload = browserSync.reload
gulp.task('sass', ()=> {
return gulp.src('scss/main.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('css'))
.pipe(reload({stream: true}))
@markmichon
markmichon / Common-Currency.json
Created January 1, 2018 22:33 — forked from ksafranski/Common-Currency.json
Common Currency Codes in JSON
{
"USD": {
"symbol": "$",
"name": "US Dollar",
"symbol_native": "$",
"decimal_digits": 2,
"rounding": 0,
"code": "USD",
"name_plural": "US dollars"
},
@markmichon
markmichon / README.md
Created March 13, 2016 14:38 — forked from DamonOehlman/README.md
Provisioning of node + nginx designed for use with vagrant shell provisioner. No need for chef, puppet.

This is a simple shell script that is designed to provision both nginx and node on your machine. I primarily wrote it for use with Vagrant and an example Vagrantfile is included in the Gist as well.

$.ajax({
type: 'POST',
url: 'http://kyleschaeffer.com/feed/',
data: { postVar1: 'theValue1', postVar2: 'theValue2' },
beforeSend:function(){
// this is where we append a loading image
$('#ajax-panel').html('<div class="loading"><img src="/images/loading.gif" alt="Loading..." /></div>');
},
success:function(data){
// successful request; do something with the data
@markmichon
markmichon / index.html
Created May 28, 2013 19:07
A CodePen by Mark Michon. Rotated Squares
<div class="logo">
<div class="pencil"></div>
</div>
@markmichon
markmichon / metadata.html
Created May 20, 2013 15:15
Metadata element for jekyll blog
<div class="article-meta">
<ul>
<li><time>{{ page.date | date: "%m/%d/%Y" }}</time></li>
<li><a href="http://twitter.com/share?url=http://{{site.url}}{{page.url}}&amp;text={{page.title}} via @markmichon">Tweet<a/></li>
<li><a href="http://www.facebook.com/sharer.php?u=http://{{site.url}}{{ page.url }}&amp;t={{page.title}}">Share on Facebook</a></li>
<!-- <li>Reading time: {{ content | count_minutes }}</li>
</ul>
</div>