This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// is Just(..) a monad? Well, it's a monad constructor. | |
// Its instances are certainly monads. | |
function Just(v) { | |
return { map, chain, ap }; | |
function map(fn) { | |
return Just(fn(v)); | |
} | |
function chain(fn) { | |
return fn(v); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A very simple wrapper that provides redux-like functionality using RxJS observables | |
// Redux is basically just an observable(subject), except that it's not generic enough to be used like one. | |
// By using RxJS observables, you can solve many of the problems that redux has, such as asynchronous effects, | |
// in a very simple way. Since it's using an observable, it's easy to combine and compose the store with other streams | |
// like events or ajax calls. | |
// This simple wrapper provides the same functionality as redux at only 23 lines of code | |
const createStore = function(name, reducer, initialState) { | |
const storeName = 'store:'+ name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Probability do | |
def bias_probability(weights) do | |
# Initialization | |
# does the probability exist in memory? | |
current_probability = try do | |
[weights: cached_probs] = :ets.lookup(:weight_probability, :weights) | |
cached_probs | |
rescue | |
ArgumentError -> cache(weights) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Helper fns */ | |
function mapValues(obj, fn) { | |
return Object.keys(obj).reduce((result, key) => { | |
result[key] = fn(obj[key], key); | |
return result; | |
}, {}); | |
} | |
function pick(obj, fn) { | |
return Object.keys(obj).reduce((result, key) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lean generator (add --api flag to skip javascript) | |
# TODO: configured with graphiql for dev mode in --api mode? | |
rails new web-app-name --database="postgresql" --skip-action-mailer --skip-action-mailbox --skip-action-text --skip-active-storage --skip-action-cable --skip | |
-javascript --skip-webpack-install | |
# (full app with react + postgres ) | |
rails new rails-react-graphql -T -d=postgresql --webpack=react |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"presets": [ | |
"@babel/preset-env", "@babel/preset-react" | |
], | |
"plugins": [ | |
"@babel/plugin-proposal-class-properties", | |
"@babel/plugin-proposal-object-rest-spread" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Fibonacci do | |
def generate(limit) do | |
# Create infinite fibonacci stream | |
Stream.unfold({0, 1}, fn | |
{x, y} -> {x, {y, (x + y)}} | |
end) | |
|> Enum.take(limit) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. catb.org/esr/faqs/hacker-howto.html | |
2. http://norvig.com/21-days.html | |
3. http://www.paulgraham.com/gh.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://slatestarcodex.com/2016/02/20/writing-advice/ |
OlderNewer