Skip to content

Instantly share code, notes, and snippets.

class Car
attr_reader :current_speed
attr_reader :brand
attr_reader :max_speed
# use hash args because then you know what parameters are what when calling
# the function.
def initialize(args = {})
@current_speed = args[:current_speed] || 0
@brand = args[:brand] || "unknown"
# Below is the controller code from a sort of "group/party game" webapp I had worked on at one point.
#
# It's from a Ruby on Rails application, which provides a lot of functionality out of the box
# So it might not look like "that much code" because Rails eliminates the need for writing a ton of boilerplate.
#
# I believe it at least demonstrates some understanding of model relationships and high level application design.
#
# information is broadcasted in real-time using websockets via ActionCable
class GamesController < ApplicationController
// This code is from a language learning web application that I've been building as a hobby project.
// The `Login` function is a React component. It displays a login form to the user if the user is not logged in.
// If they are already logged in, they are redirected to the home page.
// The form is submitted to a Rails backend, which uses the Devise gem configured in API mode.
// A JSON Web Token is returned, and the client stores it as a cookie.
// The other file in this gist, `store.js`, is a data structure which represents the front-end's global state.
import Layout from "components/layout"
import { useState } from "react"
2:08:07 PM: Executing task 'SpringbootAuthUpdatedApplication.main()'...
Download https://repo.maven.apache.org/maven2/javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.pom
Download https://repo.maven.apache.org/maven2/javax/xml/bind/jaxb-api-parent/2.3.0/jaxb-api-parent-2.3.0.pom
Download https://repo.maven.apache.org/maven2/javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar
> Task :compileJava
> Task :processResources UP-TO-DATE
> Task :classes
> Task :SpringbootAuthUpdatedApplication.main()
const UserRegistration = (props) => {
const appContext = useContext(AppContext)
const history = useHistory();
const [cookies, setCookie, removeCookie] = useCookies(['auth-token']);
const [messagesCleared, setMessagesCleared] = useState(true)
useEffect(() => {
return () => {
appContext.setStatusMessage({type: null, text: null})
appContext.setErrors(null)
const UserRegistration = (props) => {
const appContext = useContext(AppContext)
const history = useHistory();
const [cookies, setCookie, removeCookie] = useCookies(['auth-token']);
const [messagesCleared, setMessagesCleared] = useState(true)
useEffect(() => {
console.log('messagesCleared: ' + messagesCleared) // always appears false...
// doing this to avoid le infinite loopz
import React from 'react';
import './App.css';
import { BrowserRouter } from "react-router-dom"
import AppContext from "./AppContext"
import IssueBrowser from "./components/IssueBrowser"
import ErrorMessages from "./components/ErrorMessages"
import LoaderWidget from "./components/LoaderWidget"
function setupRedirect() {
<Redirect .../>
}
render() {
setupRedirect();
return (
<form>...</form>
)
}
@brlafreniere
brlafreniere / AdminPage.js
Created May 20, 2020 13:08
When I navigate from say `/admin/books` to `/admin/authors` - the page attempts to render the author tables/forms except with records from books
<Switch>
<Route path="/admin/books">
<RecordAdmin singular="book" plural="books" table={BookTable} form={BookForm} />
</Route>
<Route path="/admin/authors">
<RecordAdmin singular="author" plural="authors" table={AuthorTable} form={AuthorForm} />
</Route>
<Route path="/admin/branches">
<RecordAdmin singular="branch" plural="branches" table={BranchTable} form={BranchForm} />
</Route>
@brlafreniere
brlafreniere / gist:1c722c76352e9bd5cd38fca42a5f86ac
Last active May 20, 2020 12:39
Is each `<RecordAdmin />` element its own instance, with its own state?
<Switch>
<Route path="/admin/books">
<RecordAdmin singular="book" plural="books" table={BookTable} form={BookForm} />
</Route>
<Route path="/admin/authors">
<RecordAdmin singular="author" plural="authors" table={AuthorTable} form={AuthorForm} />
</Route>
<Route path="/admin/branches">
<RecordAdmin singular="branch" plural="branches" table={BranchTable} form={BranchForm} />
</Route>