recursive function + case classes + pattern matching: example JSON printer (Scala -> JSON)
pattern matching in Scala SDK: PartialFunction is a Trait with def isDefinedAt(x: A): Boolean
Iterable(base class)Seq
| import Data.List | |
| main = do | |
| putStrLn $ unwords $ map show $ filter isWonderNumber [100000..10000000] | |
| isWonderNumber :: Integer -> Bool | |
| isWonderNumber x = all (== digits x) (map digits (multiples x)) | |
| multiples :: Integer -> [Integer] | |
| multiples x = map (* x) [2..6] |
| import java.util.ArrayList; | |
| import java.util.List; | |
| import static java.lang.System.out; | |
| import static java.util.stream.Collectors.toList; | |
| import static java.util.stream.Collectors.toSet; | |
| import static java.util.stream.IntStream.range; | |
| public class WonderlandNumbers { |
| query { | |
| repository(owner: "softwarevidal", name: "arthur") { | |
| pullRequests(states: [OPEN]) { | |
| totalCount | |
| } | |
| } | |
| } |
| library(rjson) | |
| library(httr) | |
| library(ggplot2) | |
| library(scales) | |
| if (interactive()) { | |
| token <- readline(prompt="Enter Strava access token: ") | |
| activities <- GET("https://www.strava.com/", path = "api/v3/activities", | |
| query = list(access_token = token, per_page = 200)) | |
| activities <- content(activities, "text") |
Notes about online course "Lean How to Learn": https://www.coursera.org/learn/learning-how-to-learn.
Goal: learn easily and get less frustrated
| // Connect *quietly* to a database with user/password authentication: | |
| mongo $host/$database --quiet --username $user --password $password | |
| // List databases: | |
| show databases | |
| // Change database: | |
| use $database | |
| // List collections for current database: | |
| show collections |
| import http.client | |
| import json | |
| import getpass | |
| import matplotlib.pyplot as plot | |
| import pandas as pd | |
| def activities(token): | |
| connection = http.client.HTTPSConnection("www.strava.com") | |
| connection.request("GET", "/api/v3/activities?access_token=" + token + "&per_page=200") | |
| response = connection.getresponse() |