Skip to content

Instantly share code, notes, and snippets.

View readysetmark's full-sized avatar

Mark Williams readysetmark

View GitHub Profile
@readysetmark
readysetmark / mongoose-pre-validation-hook.js
Created June 1, 2018 20:24
Mongoose pre-validation hook
"use strict";
const mongoose = require('mongoose');
const thingWithNameSchema = mongoose.Schema({
name: String,
});
thingWithNameSchema.pre('validate', (next) => {
console.log(this);
console.log(this.name);
next();
@readysetmark
readysetmark / bmi.elm
Created February 6, 2016 04:41
BMI calculator in Elm
import Html exposing (Html, Attribute, div, h2, input, text)
import Html.Attributes exposing (class, type')
import Html.Events exposing (on, targetValue)
import Signal exposing (Address)
import String exposing (toLower, toInt)
import StartApp.Simple as StartApp
-- HELPERS
@readysetmark
readysetmark / num_commas_in_lines.exs
Created October 10, 2014 19:05
Elixir -> Count # of commas in lines in a file
# NOT idiomatic code.. just threw this together
# the need to unfold the stream for codepoints feels icky
# Plus not mapping counts across all lines, doing Enum.at! YUCK!
temp = File.stream!("path/to/file")
tempx = Enum.map(temp, fn line -> Stream.unfold(line, &String.next_codepoint/1) end)
tempy = Enum.map(tempx, fn line -> Enum.filter(line, fn x -> x == "," end) end)
Enum.count(Enum.at(tempy, 0))