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
| var a = [1, 2, 3] | |
| var b = a // b now points to the same array as a | |
| a === b // true | |
| var c = [...a] // Makes a shallow copy of the array | |
| c === a // false | |
| a.push(4) | |
| b // [1, 2, 3, 4] | |
| c // [1, 2, 3] | |
| a = null | |
| b // [1, 2, 3, 4] Still point to the same array |
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
| var user = prompt("Where you at?").toUpperCase(); | |
| var isSingle = prompt("Are you single?").match(/yes/); | |
| var isHappy = prompt("Are you happy?").match(/yes/); | |
| switch(user) { | |
| case 'HOME': | |
| console.log("it is nice to have a home"); | |
| break; | |
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
| 'use strict' | |
| // All these functions behave the same way | |
| const getHello = function (a) { | |
| if (a === true) { | |
| return 'hello' | |
| } | |
| else { | |
| return 'wow' |
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
| fizzbuzz :: Int -> String | |
| fizzbuzz x | mod x 15 == 0 = "fizzbuzz" | |
| | mod x 5 == 0 = "fizz" | |
| | mod x 3 == 0 = "buzz" | |
| | otherwise = show x | |
| printAll [] = return () | |
| printAll (x:xs) = putStrLn x >> printAll xs | |
| main = do |
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('loadenv')() | |
| const stripe = require('stripe')(process.env.STRIPE_API_KEY) | |
| var token1, token2 | |
| stripe.tokens.create({ card: { "number": '4242424242424242', "exp_month": 12, "exp_year": 2017, "cvc": '123' }}).then(x => token1 = x) | |
| stripe.tokens.create({ card: { "number": '4242424242424242', "exp_month": 1, "exp_year": 2020, "cvc": '456' }}).then(x => token2 = 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
| github-get-by-id () { | |
| curl -s https://api.github.com/user/$1 | python -m json.tool | |
| } | |
| github-get-by-username () { | |
| curl -s https://api.github.com/users/$1 | python -m json.tool | |
| } | |
| github-get-by-orgname () { | |
| curl -s https://api.github.com/orgs/$1 | python -m json.tool |
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 Data.List.Split | |
| import Data.Char | |
| import Data.Maybe | |
| import Text.Read | |
| converToFloat :: String -> Maybe Float | |
| converToFloat x = readMaybe x :: Maybe Float | |
| convertStringsToFloats :: [String] -> [Float] | |
| convertStringsToFloats x = map fromJust $ filter (not . null) $ map converToFloat 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
| var r = require('rethinkdb'); | |
| var assert = require('assert'); | |
| // Sample table names | |
| var sampleTableName1 = 'sample_table_' + Math.floor(Math.random() * 10000); | |
| var sampleTableName2 = 'sample_table_' + Math.floor(Math.random() * 10000); | |
| // Create a table using callbacks | |
| r.connect(function (err, conn) { | |
| r.db('test').tableCreate(sampleTableName1) |
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
| # Queries | |
| ## Setup | |
| Create the database in the data explorer. If you're using a shared instance of RethinkDB, name space your database name with your GitHub handle. If you're running these queries locally, you don't need to name space your database name. | |
| ``` | |
| r.dbCreate('GITHUB_HANDLE_rethinkdb_workshop') | |
| r.db('GITHUB_HANDLE_rethinkdb_workshop').tableCreate('reddit') | |
| ``` |
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
| var obj = { | |
| if: function (condition, trueStatement, falseStatement) { | |
| if (condition) return trueStatement; | |
| return falseStatment; | |
| }, | |
| in: function () { | |
| console.log('This is an `in` method'); | |
| }, | |
| arguments: function () { | |
| console.log('This is an `arguments` method'); |