Skip to content

Instantly share code, notes, and snippets.

@danyx23
danyx23 / index.js
Created April 10, 2015 15:12
requirebin sketch
var h = require('virtual-dom/h');
var diff = require('virtual-dom/diff');
var patch = require('virtual-dom/patch');
var createElement = require('virtual-dom/create-element');
// 1: Create a function that declares what the DOM should look like
function render(value) {
return h('input', {
className: "form-control",
type: "range",
@danyx23
danyx23 / index.js
Created April 11, 2015 13:30
requirebin sketch
var h = require('virtual-dom/h');
var diff = require('virtual-dom/diff');
var patch = require('virtual-dom/patch');
var createElement = require('virtual-dom/create-element');
// 1: Create a function that declares what the DOM should look like
function render(value) {
return h('input', {
attributes: {
class: "form-control",
@danyx23
danyx23 / mediaAsset-model-draft.js
Last active August 29, 2015 14:20
Cycle model draft (not working) for more complex objects
// This doesn't work, it's just a draft while thinking how best to model collections of non-trivial objects
const model = (function () {
const mediaAsset$ = createStream(droppedFiles$.filter(droppedFile => droppedFile.type.match('image.*'))
.map (droppedfile => {
const reader = new FileReader();
const asset = {
id = cuid(),
name = droppedfile.name,
imageLoadSucceeded$ = Rx.Observable.fromEvent(reader.onload).map(_ => reader.result),
@danyx23
danyx23 / Main.elm
Last active January 16, 2016 13:06
Dealing with ports as part of the Elm Architecture
type PortAction
= StartAudioPlayback AudioPlaybackMessage
| StopAudioPlayback
| DecodeAudioData AudioRawDataMessage
| NoopPortAction
update : Action -> Model -> (Model, Effects Action, PortAction)
app : App Model MainActions.PortAction
app =
module CustomStartApp where
import Debug
import Html exposing (Html)
import Signal exposing (Address)
import Automaton exposing ((>>>))
type alias Config model action =
{ model : model
, view : Address action -> model -> Html
module PortsExample where
import Html exposing (div, button, text)
import Html.Events exposing (onClick)
import Signal exposing (Mailbox, mailbox, send)
import StartApp
import Effects
type alias Model = String
import Html exposing (div, button, text)
import Html.Events exposing (onClick)
import Signal exposing (Mailbox, mailbox, send)
import StartApp.Simple as StartApp
main =
StartApp.start { model = model, view = view, update = update }
model = "hi"
@danyx23
danyx23 / GeneDriveSimulation.elm
Last active January 24, 2017 14:02
A very simple model to show how long it would take for a population of wild type mosquitos to be taken over by mutants carrying a CRISPR/CAS9 modification in their genome. This is not a proper way to model this problem :).
import Html exposing (text, div)
import String exposing (padLeft)
-- You can paste this code into http://elm-lang.org/try to have it evaluated
gen0WildTypeFemales = 2000000000.0
gen0WildTypeMales = 2000000000.0
gen0MutantFemals = 100.0
gen0MutantMales = 100.0
femaleMatingSuccessFactor = 0.2
@danyx23
danyx23 / elm-package.json
Last active December 22, 2017 17:52
Simple example of using Ports in Elm
{
"version": "1.0.0",
"summary": "helpful summary of your project, less than 80 characters",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"."
],
"exposed-modules": [],
"dependencies": {
@danyx23
danyx23 / CustomStartApp.elm
Created February 24, 2016 20:48
Use ports with customized StartApp and "PortActions"
module CustomStartApp (start, App, Config) where
import Html exposing (Html)
import Effects exposing (Effects, Never)
import Task
type alias Config model action portAction =
{ init : ( model, Effects action, portAction )
, update : action -> model -> ( model, Effects action, Maybe portAction )