This file contains hidden or 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, { Component, PropTypes } from 'react' | |
| class Counter extends Component { | |
| constructor(props) { | |
| super(props) | |
| this.incrementAsync = this.incrementAsync.bind(this) | |
| this.incrementIfOdd = this.incrementIfOdd.bind(this) | |
| } | |
| incrementIfOdd() { |
This file contains hidden or 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
| export default function counter(state = 0, action) { | |
| switch (action.type) { | |
| case 'INCREMENT': | |
| return state + 1 | |
| case 'DECREMENT': | |
| return state - 1 | |
| default: | |
| return state | |
| } | |
| } |
This file contains hidden or 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 Counter where | |
| import Html exposing (..) | |
| import Html.Attributes exposing (style) | |
| import Html.Events exposing (onClick) | |
| -- MODEL | |
| type alias Model = Int |
This file contains hidden or 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
| -- MODEL | |
| type alias Model = { ... } | |
| -- UPDATE | |
| type Action = Reset | ... | |
| update : Action -> Model -> Model |
This file contains hidden or 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
| def my_controller_method | |
| ... | |
| respond_to do |format| | |
| format.js{ | |
| render :template => 'create.js.erb' | |
| } | |
| end | |
| end |
This file contains hidden or 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
| # takes one or more functions as arguments | |
| sum_of_powers = ->(a, b, power_function){ | |
| power_function.(a) + power_function.(b) | |
| } | |
| power_of_2 = ->(x){ x * x } | |
| puts sum_of_powers.(3 , 2, power_of_2) |
This file contains hidden or 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
| RubyVM::InstructionSequence.compile_option = { tailcall_optimization: true, | |
| trace_instruction: false } | |
| eval<<end | |
| def factorial(n, result=1) | |
| if n==1 | |
| result | |
| else | |
| factorial(n-1, n*result) | |
| end | |
| end |
This file contains hidden or 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
| require 'active_support/all' | |
| require 'benchmark' | |
| dates = [] | |
| 5.times { | |
| dates << Time.at(rand * Time.now.to_i).utc | |
| } | |
| puts 'DESC SORT WITH COMPARATOR' | |
| puts dates.sort {|x,y| y <=> x } |
This file contains hidden or 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
| gem install pre-commit | |
| pre-commit install | |
| git config pre-commit.ruby "rvm `rvm current` do ruby" | |
| git config pre-commit.checks "[whitespace, pry, console_log, debugger, rubocop]" |
This file contains hidden or 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
| ## Execute Around | |
| def time_it(label) | |
| start_time = Time.now | |
| yield | |
| elapsed_time = Time.now - start_time | |
| puts "#{label} took #{elapsed_time} seconds" | |
| end | |
| time_it("Sleepy code") do |