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
import React from 'react'; | |
import globalHook from 'use-global-hook'; | |
// You'd probably want to put this and useCounter in a separate file, and only | |
// export useCounter | |
const globalCounterActions = { | |
setValue: (store, newValue) => { | |
store.setState({ value: newValue }); | |
}, | |
}; |
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
import React, { useState, useContext, createContext } from 'react'; | |
// We have to define a context object for each unique piece of shared state. | |
// Parameter is the default value - in our case we're making it an object | |
// with a value, and a function to set that value. The Provider will | |
// populate the function | |
const CounterContext = createContext({ | |
value: 0, | |
setValue: () => {}, | |
}); |
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
import React, { useState } from 'react'; | |
const ReactPropDrilling = () => { | |
const [counter, setCounter] = useState(0); | |
return ( | |
<div> | |
Main app container: | |
<CounterDisplay counter={counter} /> | |
<div> | |
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label,react/button-has-type */} |
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
module ApplicationHelper | |
def inner_helper | |
str = content_tag(:p, "inside p content tag") | |
str << "a space should be between the following words: hello" | |
str << " " | |
str << "world" | |
str << "more <span style=\"font-weight:bold;\">dirty HTML</span>" | |
str << content_tag(:div, "inside div content tag") | |
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
# Be sure to restart your server when you modify this file. | |
# Your secret key for verifying cookie session data integrity. | |
# If you change this key, all old sessions will become invalid! | |
# Make sure the secret is at least 30 characters and all random, | |
# no regular words or you'll be exposed to dictionary attacks. | |
ActionController::Base.session = { | |
:key => '_<%= app_name %>_session', | |
:secret => '<%= app_secret %>' | |
} |
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
// Don't or modify remove this, it's needed by the Lift JSON library | |
implicit val formats = net.liftweb.json.DefaultFormats | |
val rspJson = parse(rspStr) | |
// Github response is an array of objects, this will get that array | |
// as a List | |
val rspList = rspJVal.children | |
val rspRepos = for (repoJObj <- rspList) yield repoJObj.extract[Repo] |
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 github user | |
*/ | |
case class User(login: String, // login name of hte user | |
id: Int, // numeric github ID | |
avatar_url: String, // URL to their avatar pic | |
url: String) // API url to retrieve JSON of the user | |
/** | |
* A single code repo. |
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
import dispatch._ | |
import net.liftweb.json._ | |
val h = new Http | |
val req = url("https://api.github.com/users/brentsowers1/repos") | |
// Gets both the headers and response body | |
val rspStr = h(req >:+ { (headers, req) => | |
val hdrs = headers | |
req as_str |
NewerOlder