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
# download hugo | |
wget -O ~/Downloads/hugo_0.31.1_Linux-64bit.deb https://github.com/gohugoio/hugo/releases/download/v0.31.1/hugo_0.31.1_Linux-64bit.deb | |
# install hugo | |
sudo dpkg -i ~/Downloads/hugo_0.31.1_Linux-64bit.deb | |
# verify install | |
hugo version | |
# download & install caddy | |
curl https://getcaddy.com | bash -s personal http.git,http.minify | |
# verify install | |
caddy -version |
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
# in a new terminal (tab) | |
# export variables again (unnecessary if in the same terminal session as before) | |
export GITHUB_USERNAME=snassr | |
export GITHUB_REPONAME=myblog | |
export OS_REPOLOCATION=~/$GITHUB_REPONAME | |
# change directory to blog folder | |
cd $OS_REPOLOCATION/$GITHUB_REPONAME | |
# add a caddyfile (setup for display on port 80) | |
cat << EOF > ./CaddyFile | |
:80 { |
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
# create a digital ocean ubuntu droplet (smallest size is OK for this example) | |
# in a new terminal (tab) | |
# export server username | |
export SERVER_USERNAME=root | |
# export ip of remote server (provided by digitalocean for example) | |
export REMOTESERVER_IP=45.55.250.178 | |
# login to remote server | |
ssh $SERVER_USERNAME@$REMOTESERVER_IP | |
# export variables again (unnecessary if in the same terminal session as before) | |
export GITHUB_REPONAME=myblog |
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
# make frontend directory and change to that directory | |
mkdir -p ~/blog-goreactsockets/frontend && cd ~/blog-goreactsockets/frontend | |
# create webpack configuration file | |
echo "module.exports = { | |
entry: [ | |
'./src/index.js' | |
], | |
module: { | |
loaders: [ | |
{ |
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
<html> | |
<head> | |
<title>GoReactSockets!</title> | |
</head> | |
<body> | |
<div id="app"></div> | |
<script src="bundle.js"></script> | |
</body> | |
</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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import App from './components/App'; // component not yet created | |
// mount parent react element (App) on id app. | |
ReactDOM.render( | |
<App />, | |
document.getElementById('app') |
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 {EventEmitter} from 'events'; | |
// Socket class to construct and provide methods for WebSocket connections. | |
export default class Socket { | |
constructor(ws = new WebSocket(), ee = new EventEmitter()) { | |
this.ws = ws; | |
this.ee = ee; | |
// attach message function as event listener for incoming websocket messages. | |
ws.onmessage = this.message.bind(this); | |
// attach open function tas event listener on websocket connections. |
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 ReactDOM from 'react-dom'; | |
// import socket class | |
import Socket from '../socket'; | |
export default class App extends React.Component { | |
constructor(props) { | |
super(props); |
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
// SinglyLinkedList implements a list of items. | |
type SinglyLinkedList interface { | |
Append(val int) | |
Values() []int | |
} | |
// NewSinglyLinked list returns a new list. | |
func NewSinglyLinkedList(vals ...int) SinglyLinkedList { | |
return newList(vals...) // swap different implementation constructor here. | |
} |
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
func TestSinglyLinkedList(t *testing.T) { | |
for title, fn := range map[string]func(t *testing.T){ | |
"append item to list": testAppend, // test: append functionality | |
"return items in list": testValues, // test: values functionality | |
} { | |
t.Run(title, func(t *testing.T) { | |
fn(t) | |
}) | |
} | |
} |
OlderNewer