Skip to content

Instantly share code, notes, and snippets.

@learncodeacademy
learncodeacademy / async.md
Last active August 29, 2015 14:05
Async Generator Tests

###Doing Express.js Async With Generators###

Using Co library, run generators as responses by wrapping Co and adding an extra function to handle errors

  • Because Co always runs the last argument as a callback...so it would always runs next() by default
  • This function only runs next if there's an error
//assign this to the Co module somewhere in application bootstrapping, 
//so you can do var ce = require('co').coExpress in each router file
co.coExpress = (generator) => {
  return (...args) => {
@learncodeacademy
learncodeacademy / keymap.c
Created October 10, 2016 14:39
Ergodox EZ Keymap - layer 2: mouse - layer3: arrows
#include "ergodox_ez.h"
#include "debug.h"
#include "action_layer.h"
#define BASE 0 // default layer
#define MDIA 1 // mouse/media keys
#define ARROW 2 // arrow keys
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Keymap 0: Basic layer
@learncodeacademy
learncodeacademy / Dockerfile
Created March 27, 2015 02:20
Node Dockerfile
FROM node:0.12.0
# use changes to package.json to force Docker not to use the cache
# when we change our application's nodejs dependencies:
ADD package.json /tmp/package.json
RUN cd /tmp && mkdir data && npm install --production --unsafe-perm
RUN mkdir -p /app && cp -a /tmp/node_modules /app/ && cp -a /tmp/data /app/
# From here we load our application's code in, therefore the previous docker
# "layer" thats been cached will be used if possible

##The Good, The Bad, & The Ugly Ways of handling Async Operations With Javascript## #####Callbacks < Promises < Generators#####


###An Example: 5 in-sequence Async Operations### (also see parallel-sequence example: https://gist.github.com/willrstern/af3a3308fc5864cf48f8)
###The Ugly Way: Callbacks### After each function takes place, handle any errors & do the next thing - It's easy to walk through the code and understand what's going on...but it's ugly as sin
@learncodeacademy
learncodeacademy / .drone.yml
Created June 28, 2017 16:28
Rancher Drone CD Pipeline Setup
pipeline:
slack:
image: plugins/slack
webhook: <your slack webhook url>
channel: deployments
username: drone
template: "<{{build.link}}|Deployment #{{build.number}} started> on <http://github.com/{{repo.owner}}/{{repo.name}}/tree/{{build.branch}}|{{repo.name}}:{{build.branch}}> by {{build.author}}"
when:
branch: [ master, staging ]
build:
@learncodeacademy
learncodeacademy / gist:5f84705f2229f14d758d
Last active February 24, 2021 14:48
Getting Started with Vagrant, SSH & Linux Server Administration
@learncodeacademy
learncodeacademy / flightplan-html.md
Last active February 26, 2021 22:07
Deploy HTML site with Flightplan

###Prerequesites

Install flightplan globally

npm install -g flightplan

Install flightplan in your project folder

@learncodeacademy
learncodeacademy / README.md
Last active June 17, 2021 15:43
Running a High Availability Service on CoreOS using Docker, Fleet, Flannel, Etcd, Confd & Nginx

Running a High Availability Service on CoreOS using Docker, Fleet, Flannel, Etcd, Confd & Nginx

Tools used:

  • coreos: server machine clustering via a shared cloud-config.yml
  • etcd: key value store for service registration and discovery
  • fleet: scheduling/failover of docker containers across coreos cluster
  • flannel: Gives each docker container a unique ip that allows you to access the internal port (i.e. port 80 not 32679)
  • confd: watch etcd for nodes arriving/leaving - template nginx configuration files / reload nginx on change
@learncodeacademy
learncodeacademy / gist:8acf7e3a2c4c33100f04c6715c662a01
Created June 11, 2018 14:23
Training a Neural Network - Enhanced Console Output From Brain.js
Start Training!...Here's the data, we'll do 2 iterations:
[ { input: [ 0, 1 ], output: [ 1, 0 ] },
{ input: [ 1, 1 ], output: [ 1, 1 ] } ]
======== TRAINING ITERATION 1 =========
--------- Run input set 0: 0,1 ----------
-> Layer 2 has 3 nodes
START NODE: 0
-> bias for node 0: 0.13861538469791412
-> weights for node 0:
-> input value: 0, weight: -0.03485306352376938

##Example Task: Make 2 parallel (simultaneous) async calls, then one async call when they've resolved##

##The Good Way: Promises##

//with bluebird library
var parallelCalls = [
  getUrl('/api/profile'),
  getUrl('/api/accounts')
];
//spread is like .then(), except it apply()s the array of responses as individual arguments