Skip to content

Instantly share code, notes, and snippets.

@hsavit1
hsavit1 / makemake.pl
Created April 2, 2016 21:56 — forked from roop/makemake.pl
Script to create a Makefile to build your Swift project
#!/usr/bin/perl -w
use strict;
# Makefile generator for quick compilation of Swift projects
# By: Roopesh Chander
# Thanks: Andy Matuschak
# Works only for swift-only projects.
# Usage:
# > perl makemake.pl
# > make
@hsavit1
hsavit1 / Makefile
Created April 2, 2016 21:55 — forked from zachwhaley/Makefile
Simple C++ Makefile
CXXFLAGS = -g -Wall -Werror -std=c++11
LDLIBS =
PRGM = project
SRCS := $(wildcard *.cpp)
OBJS := $(SRCS:.cpp=.o)
DEPS := $(OBJS:.o=.d)
.PHONY: all clean
protocol LensType {
typealias Whole
typealias Part
var get: Whole -> Part { get }
var set: (Part, Whole) -> Whole { get }
}
struct Lens <A, B> : LensType {
typealias Whole = A
@hsavit1
hsavit1 / lens-functorial.swift
Created January 17, 2016 23:42 — forked from mbrandonw/lens-functorial.swift
Making `Lens<Whole, Part>` into a functor
struct Lens<A, B> {
let get: A -> B
let set: (B, A) -> A
func map <C> (f: B -> C) -> Lens<A, C> {
return Lens(
get: { f(get($0)) },
set: { set(f($0), $1) }
)
}
@hsavit1
hsavit1 / Focus.md
Created January 9, 2016 07:37 — forked from evancz/Focus.md
Potential outline of a simple and useful lens library for Elm

Focus

A Focus is a way to work with particular parts of a large chunk of data. On the most basic level, it lets you get and set fields of a record in a simple and composable way. This means you could avoid writing special record update syntax and use something that composes much more elegantly.

This API is inspired by the concept of Bidirectional Lenses as described by Nate Foster and seen in a modified form in Haskell as "lenses" and in ClojureScript as "cursors". My personal opinions and understanding comes from this talk by Simon Peyton Jones, discussions with @seliopou, and a basic understanding of Nate Foster's PhD thesis on bidirectional lenses. I chose the name "Focus" for this outline because it is sort of like a lens that only lets you see in one direction.

Here's the pseudocode that describes the basic API:

modul
@hsavit1
hsavit1 / Architecture.md
Created January 9, 2016 07:37 — forked from evancz/Architecture.md
Ideas and guidelines for architecting larger applications in Elm to be modular and extensible

Architecture in Elm

This document is a collection of concepts and strategies to make large Elm projects modular and extensible.

We will start by thinking about the structure of signals in our program. Broadly speaking, your application state should live in one big foldp. You will probably merge a bunch of input signals into a single stream of updates. This sounds a bit crazy at first, but it is in the same ballpark as Om or Facebook's Flux. There are a couple major benefits to having a centralized home for your application state:

  1. There is a single source of truth. Traditional approaches force you to write a decent amount of custom and error prone code to synchronize state between many different stateful components. (The state of this widget needs to be synced with the application state, which needs to be synced with some other widget, etc.) By placing all of your state in one location, you eliminate an entire class of bugs in which two components get into inconsistent states. We also think yo
@hsavit1
hsavit1 / Haskell-Style-Guide.md
Created January 9, 2016 07:35 — forked from evancz/Haskell-Style-Guide.md
A style guide for Elm tools

Haskell Style Guide for Elm

Goal: a consistent style throughout all Elm projects that is easy to read and produces clean diffs to make debugging easier. This means valuing regularity and simplicity over cleverness.

Line Length

Keep it under 80 characters. Going over is not the end of the world, but consider refactoring before you decide a line really must be longer.

Variables

@hsavit1
hsavit1 / Ports.js
Created January 9, 2016 06:38 — forked from evancz/Ports.js
Example usage of Elm "ports" that uses signals, non-signals, records, and tuples. Build the Elm code with "elm --only-js Shanghai.elm" and include all of the JS in the HTML document.
// initialize the Shanghai component which keeps track of
// shipping data in and out of the Port of Shanghai.
var shanghai = Elm.worker(Elm.Shanghai, {
coordinates:[0,0],
incomingShip: { name:"", capacity:0 },
outgoingShip: ""
});
function logger(x) { console.log(x) }
/*
Erica Sadun, http://ericasadun.com
Collections, Sequences, and Strides
Heavily curated. I'm kicking myself for not keeping
better notes.
When in doubt I may have attributed stuff with
public func projectFunctionToCoordinateSystem(function f: FunctionType) -> (p0: CGPoint, p1: CGPoint) -> (x: CGFloat) -> CGPoint {
return { p0, p1 in
return { x in
let (dx, dy) = (p1.x - p0.x, p1.y - p0.y)
let (magnitude, theta) = (hypot(dy, dx), atan2(dy, dx)) // Thanks loooop
var outPoint = CGPoint(x: x * magnitude, y: f(x) * magnitude)
outPoint = CGPointApplyAffineTransform(outPoint, CGAffineTransformMakeRotation(theta))
outPoint = CGPointApplyAffineTransform(outPoint, CGAffineTransformMakeTranslation(p0.x, p0.y))
return CGPoint(x: outPoint.x, y: outPoint.y)
}