Skip to content

Instantly share code, notes, and snippets.

View JesterXL's full-sized avatar
🔊
writing

Jesse Warden JesterXL

🔊
writing
View GitHub Profile
var aws = require('aws-sdk');
var sfn = new aws.StepFunctions();
exports.handler = function(event, context, callback) {
console.log("event:", event)
console.log("context:", context)
console.log("callback:", callback)
let StateMachineArn = event.restart.StateMachineArn;
event.restart.executionCount -= 1;
event.AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID = event.executionID
const getPartsAssemblerStream = s3 => bucket => key => uploadID => {
const parts = []
return new stream.Writable({
objectMode: true,
write(part, encoding, callback) {
if(getOr(false, 'isLast', part) === false) {
parts.push(part)
callback()
@JesterXL
JesterXL / Result.py
Last active April 26, 2020 15:45
A Result for PyMonad. It's like their Either.
# I always hated Either's name, so changed to Result becuase I like Folktale's better.
from pymonad.Monad import *
from pydash import map_, some, filter_, head, every
class Result(Monad):
"""
Represents a calculation that may either fail or succeed.
An alternative to using exceptions. 'Result' is an abstract type and should not
be instantiated directly. Instead use 'Ok' (or its alias 'Ok') and
'Error' (or its alias 'Error')
  • what is a closure?
  • what is a function declaration?
  • what is an anonymous function?
  • what is a fat arrow function?
  • what is Object Oriented Programming?
  • what is inheritance?
  • What is Object Prototype?
  • What is Object.assign?
  • What is Object.freeze?
  • What is list comprehension?
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="material-components-web-elm.min.css">
<style>
@font-face {
font-family: 'Roboto';
src: url('Roboto-ThinItalic-webfont.eot');
src: url('Roboto-ThinItalic-webfont.eot?#iefix') format('embedded-opentype'),
url('Roboto-ThinItalic-webfont.woff') format('woff'),
url('Roboto-ThinItalic-webfont.ttf') format('truetype'),
@JesterXL
JesterXL / fizzbuzz-1.js
Last active August 17, 2019 18:00
FizzBuzz solutions in JavaScript and Elm.
// JavaScript
const fizzAndOrNotBuzz = i => {
switch(true) {
case i % 15 === 0: return 'FizzBuzz'
case i % 5 === 0: return 'Buzz'
case i % 3 === 0: return 'Fizz'
default: return i
}
}
{ resource: '/test-delete-me',
path: '/test-delete-me',
httpMethod: 'GET',
headers:
{ accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.9,es;q=0.8',
'cache-control': 'max-age=0',
Host: 'o8ai4pej00.execute-api.us-east-1.amazonaws.com',
'upgrade-insecure-requests': '1',
@JesterXL
JesterXL / validations-snippet.js
Last active March 3, 2019 16:40
Example of nested Arrow functions.
'use strict'
const Validation = require('folktale/validation')
const { Success, Failure } = Validation
const {
isString,
some,
identity,
inRange,
@JesterXL
JesterXL / what-is-a-partial-application.md
Last active December 18, 2018 15:03
A quick primer on what is a partial application. (I threw this together for a friend. If you want something more thorough, then read this link: https://jesterxl.github.io/real-world-functional-programming-book/ )

Hard to understand without mastering pure functions, but ok.

tl;dr;

Partial Application is a function where some or all of the arguments are packed inside, ready to go and it's just waiting for a few more before the main function is invoked. They're like functions that have default arguments, but are pure functions with a fixed amount of parameters.

Basic Arguments

The function below pings google.com: const pingGoogle = () =&gt; fetch('http://google.com'). If it resolves, Google is there and your computer can talk to the internets. If it throws an error, your computer is probably having wireless trouble.