Skip to content

Instantly share code, notes, and snippets.

Henry S hsavit1

Block or report user

Report or block hsavit1

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@hsavit1
hsavit1 / connect.js
Created Jun 24, 2017 — forked from gaearon/connect.js
connect.js explained
View connect.js
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (
@hsavit1
hsavit1 / upgrade.md
Created May 5, 2017 — forked from chrismccord/upgrade.md
Phoenix 1.2.x to 1.3.0 Upgrade Instructions
View upgrade.md

If you want a run-down of the 1.3 changes and the design decisions behidn those changes, check out the LonestarElixir Phoenix 1.3 keynote: https://www.youtube.com/watch?v=tMO28ar0lW8

To use the new phx.new project generator, you can install the archive with the following command:

$ mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez

Bump your phoenix dep

Phoenix v1.3.0 is a backwards compatible release with v1.2.x. To upgrade your existing 1.2.x project, simply bump your phoenix dependency in mix.exs:

@hsavit1
hsavit1 / head_tail.swift
Created Aug 7, 2016
Head and tail for Swift
View head_tail.swift
extension Array {
var match : (head: T, tail: [T])? {
return (count > 0) ? (self[0],Array(self[1..<count])) : nil
}
}
func map<A,B>(f: A -> B, arr: [A]) -> [B] {
if let (head,tail) = arr.match {
return [f(head)] + map(f, tail)
} else {
@hsavit1
hsavit1 / States-v3.md
Last active Jul 29, 2016 — forked from andymatuschak/States-v3.md
A composable pattern for pure state machines with effects (draft v3)
View States-v3.md

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen conflate side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@hsavit1
hsavit1 / genserver.ex
Created Jul 28, 2016
Genserver Implementation
View genserver.ex
defmodule Server do
def start(callback_module, state \\ nil) do
parent = self
spawn fn ->
loop(callback_module, parent, state)
end
end
def loop(callback_module, parent, state) do
receive do
@hsavit1
hsavit1 / process_msging.ex
Created Jul 28, 2016
Small example of process messaging in elixir
View process_msging.ex
defmodule Speaker do
def speak do
receive do
{:say, msg} ->
IO.puts(msg)
speak
_other ->
speak # throw away the message
end
end
@hsavit1
hsavit1 / possibly.ex
Created Jul 19, 2016 — forked from keathley/possibly.ex
Monads and Maybes in elixir
View possibly.ex
defprotocol Functor do
def fmap(data, func)
end
defprotocol Applicative do
def pure(data)
def run(wrapped_func, data)
end
defprotocol Monad do
@hsavit1
hsavit1 / YouTubePlayerViaTVJS.swift
Created Jul 6, 2016 — forked from nickv2002/YouTubePlayerViaTVJS.swift
Swift code to play YouTube videos on AppleTV tvOS via a TVJS call using XCDYouTubeKit
View YouTubePlayerViaTVJS.swift
//
// Created by Nick Vance on 12/4/15.
// Copyright © 2015 ToWatchList. All rights reserved.
//
import AVKit
import XCDYouTubeKit
import TVMLKit
class YTPlayerViewController: AVPlayerViewController, AVPlayerViewControllerDelegate {
@hsavit1
hsavit1 / bbtree.py
Created Jun 27, 2016 — forked from olomix/bbtree.py
Balanced binary tree in Python
View bbtree.py
#!/usr/bin/env python2.7
import random
import subprocess
class Node(object):
def __init__(self, key, value):
self.key = key
self.value = value
View Notifier_ExampleCode.swift
extension Selector {
static let coffeeMadeNotification = #selector(Customer.drink(_:))
}
class Customer {
@objc func drink(notification: NSNotification) {
print("Mmm... Coffee")
}
}
You can’t perform that action at this time.