Install HomeBrew first
brew update
brew tap caskroom/cask
brew install brew-caskIf you get the error "already installed", follow the instructions to unlink it, then install again:
| /* | |
| A Tour of Go: page 44 | |
| http://tour.golang.org/#44 | |
| Exercise: Loops and Functions | |
| As a simple way to play with functions and loops, implement the square root function using Newton's method. | |
| In this case, Newton's method is to approximate Sqrt(x) by picking a starting point z and then repeating: z - (z*z - x) / (2 * z) |
Install HomeBrew first
brew update
brew tap caskroom/cask
brew install brew-caskIf you get the error "already installed", follow the instructions to unlink it, then install again:
Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000| class Counter extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| count: 0, | |
| }; | |
| } | |
| increment = () => { | |
| this.setState(prevState => { |
| import {withRouter} from 'react-router-dom'; | |
| class App extends React.Component { | |
| constructor() { | |
| super(); | |
| this.state = {path: ''} | |
| } | |
| componentDidMount() { | |
| let pathName = this.props.location.pathname; |
| import React from 'react'; | |
| import * as My from './components/my-components.js'; | |
| export default class App extends React.Component { | |
| render() { | |
| return ( | |
| <div> | |
| <My.Foo /> | |
| <My.Bar /> |
| const { Worker, isMainThread, workerData } = require('worker_threads'); | |
| let currentVal = 0; | |
| let intervals = [100,1000, 500] | |
| function counter(id, i){ | |
| console.log("[", id, "]", i) | |
| return i; | |
| } |
| const { Worker, isMainThread, parentPort, workerData } = require('worker_threads'); | |
| const request = require("request"); | |
| if(isMainThread) { | |
| console.log("This is the main thread") | |
| let w = new Worker(__filename, {workerData: null}); | |
| w.on('message', (msg) => { //A message from the worker! | |
| console.log("First value is: ", msg.val); |
| const { Worker, isMainThread, parentPort, workerData } = require('worker_threads'); | |
| const request = require("request"); | |
| function startWorker(path, cb) { | |
| let w = new Worker(path, {workerData: null}); | |
| w.on('message', (msg) => { | |
| cb(null, msg) | |
| }) | |
| w.on('error', cb); | |
| w.on('exit', (code) => { |
| const { parentPort } = require('worker_threads'); | |
| function random(min, max) { | |
| return Math.random() * (max - min) + min | |
| } | |
| const sorter = require("./test2-worker"); | |
| const start = Date.now() | |
| let bigList = Array(1000000).fill().map( (_) => random(1,10000)) |