Skip to content

Instantly share code, notes, and snippets.

View sjcobb's full-sized avatar

Steven Cobb sjcobb

View GitHub Profile
@sjcobb
sjcobb / webpack.config.js
Created May 30, 2017 21:35 — forked from learncodeacademy/webpack.config.js
Sample Basic Webpack Config
var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
module.exports = {
context: __dirname,
devtool: debug ? "inline-sourcemap" : null,
entry: "./js/scripts.js",
output: {
path: __dirname + "/js",
filename: "scripts.min.js"
@sjcobb
sjcobb / promise_monad.md
Created June 21, 2017 14:01 — forked from VictorTaelin/promise_monad.md
async/await is just the do-notation for the Promise monad

async/await is just the do-notation of the Promise monad

CertSimple just wrote a blog post arguing ES2017's async/await was the best thing to happen with JavaScript. I wholeheartedly agree.

In short, one of the (few?) good things about JavaScript used to be how well it handled asynchronous requests. This was mostly thanks to its Scheme-inherited implementation of functions and closures. That, though, was also one of its worst faults, because it led to the "callback hell", an seemingly unavoidable pattern that made highly asynchronous JS code almost unreadable. Many solutions attempted to solve that, but most failed. Promises almost did it, but failed too. Finally, async/await is here and, combined with Promises, it solves the problem for good. On this post, I'll explain why that is the case and trace a link between promises, async/await, the do-notation and monads.

First, let's illustrate the 3 styles by implementing

@sjcobb
sjcobb / recursion-best-practices
Last active June 21, 2017 14:46
Recursion examples and best practices.
NOTES:
https://www.sitepoint.com/recursion-functional-javascript
- One reason that recursion is favored in functional programming languages is that it allows for the construction of code that doesn’t require setting and maintaining state with local variables. Recursive functions are also naturally easy to test because they are easy to write in a pure manner, with a specific and consistent return value for any given input, and no side effects on external variable states.
- Most effective for solving problems involving iterative branching, such as fractal math, sorting, or traversing the nodes of complex or non-linear data structures.
- Tail call optimization: Problem with JS is no standard way to prevent recursive functions from stacking up on themselves indefinitely, and eating away at memory. JS recursive functions need to keep track of where they were called from each time, so they can resume at the correct point. This is called tail call optimization in Haskell and Scheme, which isn't fully implemented in
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Countries CRUD</title>
<style>
input[type='submit'], button, [aria-label]{
cursor: pointer;
}
#spoiler{
https://lichess.org/insights/Assios/acpl/variant
-Analytics for studying past chess games, custom filtering and sorting
https://www.cinesift.com
-Movie database site that combines Rotten Tomatoes, IMDb, Letterboxd and Metacritic scores, with Netflix and Amazon Prime availability
http://almossawi.com/aframe-d3-visualization/demo/
-D3 visualization using A-Frame (Three.js entity-component-system framework)
https://s3-us-west-2.amazonaws.com/s.cdpn.io/212131/fitbit-dashboard.png
https://css-tricks.com/visual-regression-testing-with-phantomcss/
//function that will fill out the WordPress login form as soon as we spin up our Casper instance
casper.start('http://default.wordpress.dev/wp-admin/', function() {
this.fill('form#loginform', {
'log': 'admin',
'pwd': 'password'
}, true);
this.click('#wp-submit');
const Application = (() => {
const privateVariable = 'Private content'
const link = document.querySelector('.link')
const _private = {
cache: () => (this.link = document.querySelector('.link'))
bind: () => this.link.addEventListener('click', this.shoshowContentwVariableContent, false),
showContent: () => console.log(privateVariable)
}
@sjcobb
sjcobb / paragraph--carousel.html.twig
Created August 7, 2017 16:54 — forked from thejimbirch/paragraph--carousel.html.twig
Drupal 8 Template for Bootstrap Paragraphs customized for Carousel.
@sjcobb
sjcobb / pg-pong.py
Created August 27, 2017 23:20 — forked from karpathy/pg-pong.py
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward