Skip to content

Instantly share code, notes, and snippets.

scottdomes@scottdomes-ThinkPad:~/WebDev/RubyTest$ pry
[1] pry(main)> def say_hi(name)
[1] pry(main)*
[1] pry(main)* "Hi, #{name}."
[1] pry(main)* end
=> nil
[2] pry(main)> say_hi("Scott")
=> "Hi, Scott."
[3] pry(main)> Time.now
=> 2016-03-01 11:00:06 -0800
@scottdomes
scottdomes / max.rb
Last active March 1, 2016 19:35 — forked from davidvandusen/max.rb
# Find the maximum
def maximum(arr)
arr.inject { |x, max| x > max ? x : max }
end
# expect it to return 42 below
result = maximum([2, 42, 22, 02])
puts "max of 2, 42, 22, 02 is: #{result}"
# expect it to return nil when empty array is passed in
def determine_free_bottles (investment)
process_purchase(investment)
begin
find_bottles(@caps, @empty_bottles)
end while @empty_bottles > 1 || @caps > 3
print_result
end
var net = require('net');
var server = net.createServer(function(socket) {
var date = printTime();
socket.end(date);
});
function zeroFill(i) {
return (i < 10 ? '0' : '') + i;
}
@scottdomes
scottdomes / game.js
Last active April 11, 2016 20:10
Node betting game
var color = require('colors');
var fs = require('fs');
var player1 = {
cash: 50,
wins: 0
};
var player2 = {
cash: 50,
wins: 0
};
@scottdomes
scottdomes / App.js
Last active December 20, 2016 00:39
import React, { Component } from 'react'
import './App.css'
import ListItem from './ListItem'
function arrayGenerator(length) {
return Array.apply(null, { length: length }).map(Number.call, Number)
}
class App extends Component {
constructor(props) {
componentDidUpdate() {
Perf.stop()
Perf.printInclusive()
Perf.printWasted()
}
resetMultiplier() {
Perf.start()
this.setState({ multiplier: 2 })
}
import React, { Component } from 'react'
export default class ListItem extends Component {
shouldComponentUpdate(nextProps, nextState) {
return nextProps.text !== this.props.text
}
render() {
let { text } = this.props
return <li>{text}</li>
componentWillMount() {
window.performance.mark('App')
}
componentDidMount() {
console.log(window.performance.now('App'))
}
@scottdomes
scottdomes / ClassComponent.js
Last active September 28, 2018 18:02
React Component Best Practices: Class Component
import React, { Component } from 'react'
import { observer } from 'mobx-react'
import { string, object } from 'prop-types'
// Separate local imports from dependencies
import ExpandableForm from './ExpandableForm'
import './styles/ProfileContainer.css'
// Use decorators if needed
@observer
export default class ProfileContainer extends Component {