Skip to content

Instantly share code, notes, and snippets.

View michaelwclark's full-sized avatar

Michael W Clark michaelwclark

  • @LendersCooperative.com
  • Des Moines
View GitHub Profile
@michaelwclark
michaelwclark / asyncDestructure.js
Last active April 6, 2018 17:14
Example code for destructure async errors and body for API calls.
import request from 'superagent-bluebird-promise'
const ad = async promise => {
const [err,resp] = await promise.then(x=>[{},x]).catch(x=>[x, {}])
const [{message},{body}] = [err, resp]
return [message, body]
}
async function handlesSuccess(){
const [errorMessage, requestBody] = await ad(request.get('https://jsonplaceholder.typicode.com/posts/1').promise())
@michaelwclark
michaelwclark / rotate2dArray.js
Created March 29, 2018 21:36
Rotate 2D Array
export default const rotate2dArray = array => {
const resultLength = array[0].length
const resultArray = Array(resultLength).fill([])
return resultArray.map((x, widthIndex) =>
array.map(innerArray => innerArray[widthIndex])
)
}
043f000e1bdc9b7c8782e8813c9c97310a02f056f26caf1e79e7138dcf84adcb673a67751ce91d61b2d79e42a48c816fc5b6579e84bf6edcd8ed438beb0a7ff9de;Sheing
@michaelwclark
michaelwclark / app.js
Last active January 2, 2018 20:52
testing pattern
import makeGetUser from './github'
import request from './request'
const getUser = makeGetUser({request})
getUser('michaelwclark')
.then(console.log)
@michaelwclark
michaelwclark / killPort.zsh
Created April 5, 2017 16:07
OSX El Capitan+ Kill process listening on port.
function killPort(){
lsof -i tcp:$1 | awk '{print $2}' | grep -v 'PID' | xargs kill
}
@michaelwclark
michaelwclark / WeekendTrip.js
Created March 19, 2017 23:06
This snippit can be run in your JS console in your browser. The output will be the weekend trip destination idea.
options = ['St Louis', 'KC', 'Omaha', 'Minneappolis','Branson', 'Nashville', 'Indy'];
votes = [0,0,0,0,0,0,0]
for(count = 0; count < 10; count++){
let idx = Math.floor(Math.random() * options.length)
votes[idx]++
}
document.open();
document.close();
document.write('Winner: ' + options[votes.indexOf(Math.max(...votes))])
@michaelwclark
michaelwclark / ThreeCol.html
Created October 6, 2015 19:46
Short Example of three col alignment.
<html>
<style type="text/css">
.container{width:400px;}
.container .element {width:33%; float:left;}
.blue {background:blue;}
.orange {background:orange;}
.gray {background: gray;}
</style>
<div class="container">
<div class="element blue">&nbsp;</div>
@michaelwclark
michaelwclark / fast-forward-mini-cal.php
Last active October 5, 2015 16:42 — forked from barryhughes/fast-forward-mini-cal.php
Revision for 'fast forward the calendar widget' code
<?php
/**
* Tries to force the minicalendar widget to show the month of the next upcoming event by default, rather
* than simply showing the current month (which might be empty).
*/
class Tribe_Advance_Minical
{
protected $target_date = false;
/**
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://npmjs.org/install.sh | sh
@michaelwclark
michaelwclark / default_syntax.py
Created December 4, 2012 17:28
Sets current project to updae default syntax for new files or unknown filetypes.
import sublime, sublime_plugin
class DefaultSyntaxCommand(sublime_plugin.EventListener):
def on_new(self, view):
view.set_syntax_file('Packages/Ruby/Ruby.tmLanguage')