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
| git init . | |
| git add . | |
| git commit -m "Initial commit" | |
| git remote add origin [email protected]:myproject.git | |
| git push origin master |
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
| //simple class | |
| class Person | |
| //inheritance | |
| class Sarah extends Person | |
| //class with constructor arguments | |
| class Jet(wingspan: Int) | |
| //class with constructor argument that maps to public readonly property |
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
| #simple class | |
| class Person | |
| end | |
| #inheritance | |
| class Sarah < Person | |
| end | |
| #class with constructor arguments | |
| class Jet |
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
| trait Searchable { | |
| def search(query: SearchQuery): Seq[SearchResults] | |
| } | |
| trait PaginationWithNominalType { | |
| this: Searchable => | |
| def page(query: SearchQuery, pageSize: Int, pageNum: Int) = { | |
| search(query).grouped(pageSize).toList(pageNum) | |
| } | |
| } |
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 Pagination | |
| def page(params, page_size, page_num) | |
| search(params).in_groups_of(page_size)[page_num] | |
| 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
| //creating collections of specific types | |
| val intArray = Array(1,2,3,4) | |
| val intLinkedList = List(4,5,6,7) | |
| val indexedSequenceOfStrings = IndexedSeq("one", "two", "three") | |
| //filtering items in a collection | |
| val evens = List(1,2,3,4,5,6,7).filter(_ % 2 == 0) | |
| //mapping | |
| List("hi", "my", "name", "is", "slim", "shady").map(_.toUpperCase) |
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 'cgi' | |
| require 'digest/md5' | |
| require 'net/https' | |
| require 'uri' | |
| module Jekyll | |
| class GistTag < Liquid::Tag | |
| def initialize(tag_name, text, token) | |
| super | |
| @text = text |
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
| #creating a collection. | |
| ints = [1,2,3,4,5,6] | |
| #filtering items in a collection | |
| evens = [1,2,3,4,5,6,7].select { |i| i % 2 == 0 } | |
| #mapping | |
| ["hi", "my", "name", "is", "slim", "shady"].map { |s| s.upcase } | |
| #slightly more involved mapping |
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
| #create a literal hash | |
| cars = {'james' => 'BMW', 'ike' => 'Infiniti', 'stephen' => 'Buick'} | |
| #create a hash from an array | |
| cars = Hash[*['james', 'BMW', 'ike', 'Infiniti', 'stephen', 'Buick']] | |
| #mapping over a hash | |
| #transform all string keys to symbols (interned strings) | |
| Hash[{'name' => 'James', 'job' => 'consultant', 'age' => 28}.flat_map do |(k,v)| | |
| [k.to_sym, v] |
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
| //create a map | |
| val cars = Map("james" -> "BMW", "ike" -> "Infiniti", "stephen" -> "Buick") | |
| //create a map from an Array | |
| //Scala does not provide a convenience method to do this... :( | |
| val carArray = Array("james", "BMW", "ike", "Infiniti", "stephen", "Buick") | |
| val cars = carArray.grouped(2).toList.map(c => (c.head,c.last)).toMap | |
| //mapping over a map | |
| //transform all string keys to symbols (interned strings) |