Skip to content

Instantly share code, notes, and snippets.

View rippinrobr's full-sized avatar

Rob Rowe rippinrobr

View GitHub Profile
@rippinrobr
rippinrobr / Conspiracies.elm
Last active July 18, 2018 22:30
The init function - creates the model with default values and uses it as part of the command that retrieves the categores
-- init does what you might think it does, it initializes the applicaiton.
-- In this app, I need to fetch the list of tags when the page loads so
-- the user has some navigation to work with so I make the call to the
-- httpCommand function.
init : ( Model, Cmd Msg )
init =
let model = { categories = []
, errorMsg = Nothing
, selectedTag = "All"
, summaries = []
@rippinrobr
rippinrobr / Conspiracies.elm
Created June 14, 2018 16:10
the main and update functions
update msg model =
if msg.operation == "SELECT_TAG" then
{ model | selectedTag = msg.data }
else
model
main =
Html.beginnerProgram
{ model = initialModel
, view = view
@rippinrobr
rippinrobr / Conspiracies.elm
Created June 14, 2018 14:34
the viewTag function, creates a clickable div for the navigation menu
viewTag selectedTag tag =
div
[ classList [ ("tag",True), ( "selected", selectedTag == tag ) ]
, onClick { operation = "SELECT_TAG", data = tag }
]
[text tag]
@rippinrobr
rippinrobr / Conspiracies.elm
Last active June 14, 2018 14:20
My initialModel
initialModel =
{ tags = ["All"
, "9/11"
, "Deep State"
, "New World Order"
, "UFO"
, "Untagged"]
, selectedTag = "All"}
@rippinrobr
rippinrobr / view.elm
Last active June 11, 2018 12:50
Here's what the view looks like with the layout in place
view model =
div [ class "container-fluid" ]
[ div [ class "row" ]
[
div [ class "col-md-2 d-none d-md-block bg-light sidebar"]
[text "This is where the nav will go"]
,div [ class "col-md-9 ml-sm-auto col-lg-10 px-4" ]
[ div [ class "content-heading" ] [ h2 [] [ text "Selected Tag"]]
, div [] [ text "this is where the summaries will be displayed"]
]
@rippinrobr
rippinrobr / helloworld2.elm
Created June 10, 2018 17:56
A hello world with some HTML included. The HTML below the elm code is what the output looks like
module Helloworld2 exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
view =
div [ class "container-fluid" ]
[ div [ class "row"]
[ text "Do you know about Area 52? BTW, I'm now in a child div!"]]
@rippinrobr
rippinrobr / Helloworld.elm
Created June 10, 2018 16:42
The most basic version of a hello world program in Elm
module Conspiracies exposing (..)
import Html exposing (..)
main =
text "Do you know about Area 52?"
@rippinrobr
rippinrobr / hello-world.html
Created June 10, 2018 16:39
The hello-world.html body
<body >
<div id="elm-area"></div>
<script src="helloworld.js"></script>
<script>
Elm.Conspiracies.embed(document.getElementById("elm-area"));
</script>
</body>
@rippinrobr
rippinrobr / build.log
Created May 30, 2018 20:26
output of build after the code re-organization
cargo build
Compiling conspiracies v0.0.1 (file:///<path to your code>/conspiracies_api)
error[E0412]: cannot find type `WikiPage` in this scope
--> src/main.rs:56:46
|
56 | fn get_page(self, title: String) -> Result<WikiPage, wikipedia::Error> {
| ^^^^^^^^ not found in this scope
error[E0422]: cannot find struct, variant or union type `WikiPage` in this scope
--> src/main.rs:69:16
@rippinrobr
rippinrobr / main.rs
Created May 28, 2018 14:08
setting up the logger middleware
fn main() {
std::env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
...setting up the actix system...
// Start http server
HttpServer::new(move || {
App::with_state(State{db: addr.clone()})
.middleware(Logger::default())