This file contains 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
Collections.list(new StringTokenizer(str, ",")).stream() | |
.map(token -> (String) token) | |
.collect(Collectors.toList()); |
This file contains 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 com.google.common.collect.ImmutableSet | |
ImmutableSet.of("a", "b", "c"); | |
List<String> results = Collections.<String>emptyList(); |
This file contains 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
// given | |
Stream<Integer> infiniteStream = Stream.iterate(0, i -> i + 2); | |
// when | |
List<Integer> collect = infiniteStream | |
.limit(10) | |
.collect(Collectors.toList()); | |
// then | |
assertEquals(collect, Arrays.asList(0, 2, 4, 6, 8, 10, 12, 14, 16, 18)); |
This file contains 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
(defn rotations [xs] | |
(take (count xs) (partition (count xs) 1 (cycle xs)))) | |
(defn permutations [a-set] | |
(if (empty? a-set) | |
(list) | |
(mapcat | |
(fn [[x & xs]] (map #(cons x %) (permutations xs))) | |
(rotations a-set)))) |
This file contains 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
; This function is a great solution to the "fizzbuzz" interview question. | |
(defn fizz-buzz [n] | |
(condp (fn [a b] (zero? (mod b a))) n | |
15 "fizzbuzz" | |
3 "fizz" | |
5 "buzz" | |
n)) | |
; Output: | |
(map fizz-buzz (range 25)) |
This file contains 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
(ns try) | |
;; find the height of a tree | |
;; try> (height nil) | |
;; 0 | |
;; try> (height {:L {:R {:L {:L nil} :R nil}}}) | |
;; 4 | |
(defn height-simple [t] | |
(if (nil? t) |
This file contains 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
from scapy.all import * | |
import requests | |
import time | |
MAGIC_FORM_URL = 'http://put-your-url-here' | |
def record_poop(): | |
data = { | |
"Timestamp": time.strftime("%Y-%m-%d %H:%M"), | |
"Measurement": 'Poopy Diaper' | |
} |
This file contains 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
(defn zip [coll & more] | |
(map-indexed (fn [i e] | |
(conj (map #(nth % i) more) e)) | |
coll)) |
This file contains 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
# Added: Line#to_s, #parse4, #parse5 | |
class Line | |
attr_reader :Line | |
def initialize(text) | |
@line = text | |
end | |
This file contains 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
class Line | |
attr_reader :Line | |
def initialize(text) | |
@line = text | |
end | |
def office | |
values[2].strip |
NewerOlder