Skip to content

Instantly share code, notes, and snippets.

View relaxedtomato's full-sized avatar

Ram relaxedtomato

View GitHub Profile
{
"window.zoomLevel": 0,
"editor.minimap.enabled": false,
"editor.tabSize": 2,
"workbench.settings.editor": "json",
"eslint.validate": [
"javascript",
"javascriptreact",
{
"language": "typescript",
@relaxedtomato
relaxedtomato / js-betting-game.html
Last active July 25, 2016 22:37 — forked from Leejojo/js-betting-game
js-betting-game
<!DOCTYPE html>
<html>
<head>
<script src="jquery-3.1.0.js"></script>
</head>
<body>
<h1>Place Your Bets!</h1>
<!--RB: You can remove this extra space, lint takes care of this, http://eslint.org/-->
@relaxedtomato
relaxedtomato / CombineReducers.md
Created June 28, 2016 02:01
Combine Reducers
import { combineReducers } from 'redux'

function todos(state = [], action) {
  switch (action.type) {
    case ADD_TODO:
      return [
        ...state,
 {
const initialState = {
  visibilityFilter: VisibilityFilters.SHOW_ALL,
  todos: []
}

function todoApp(state = initialState, action) {
  switch (action.type) {
    case SET_VISIBILITY_FILTER:
 return Object.assign({}, state, {

The classic example of a reducer is doing a sum:

const result = [1,2,3].reduce((acc,value) => acc+value, 0);
// result is 6
console.log(result);

jsbin

However, the result of the reducer does not need to be the same type of the items in the collection. For example:

var game = {
userAmount: 100,
bet: null,
number: null,
guess: null,
getBetAmount: function() {
//RB: Question - what does 'this' refer to? Do look up the different rules for 'this' (we can discuss further next time).
//RB: The approach to using this is not wrong, however, you can also just refer to globally defined variables (to reduce writing 'this')
@relaxedtomato
relaxedtomato / candidates.rb
Last active April 29, 2016 00:46 — forked from joshuastr/candidates.rb
Candidates
require 'active_support/all'
@candidates = [
{
id: 5,
years_of_experience: 4,
github_points: 293,
languages: ['C', 'Ruby', 'Python', 'Clojure'],
date_applied: 5.days.ago.to_date,
age: 26
@relaxedtomato
relaxedtomato / css
Created April 8, 2016 18:00
flexbox
.parent {
width: 100%;
height: 350px;
outline: 1px solid black;
display: flex;
flex-direction: row;
justify-content: space-around;
/* align-items: baseline; */
/* flex-wrap: wrap-reverse; */
flex-flow: row nowrap;
@values = [
[1000, 'M'],
[500, 'D'],
[100, 'C'],
[50, 'L'],
[10, 'X'],
[5, 'V'],
[1, 'I']
]
@relaxedtomato
relaxedtomato / gist:cb36d40c485c61fbb8f8
Last active December 4, 2015 17:29
Error Handling
rp(options)
.then(function ($) {
var titles = $('div > div > div.title.align-top > a');
var urls = titles.map(function (index, div) { // collecting urls
return $(div).attr('href')
})
var requests = urls.map(function (index, url) { // creating promises from requests on urls
return rp(root + url) // .then(turnIntoInstances);
})