Skip to content

Instantly share code, notes, and snippets.

View orend's full-sized avatar

Oren Dobzinski orend

View GitHub Profile
Collections.list(new StringTokenizer(str, ",")).stream()
.map(token -> (String) token)
.collect(Collectors.toList());
import com.google.common.collect.ImmutableSet
ImmutableSet.of("a", "b", "c");
List<String> results = Collections.<String>emptyList();
@orend
orend / Streams.java
Last active September 27, 2019 14:11
// 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));
(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 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))
(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)
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'
}
(defn zip [coll & more]
(map-indexed (fn [i e]
(conj (map #(nth % i) more) e))
coll))
@orend
orend / functional.rb
Last active August 8, 2023 05:52
further refactoring to "Using a Ruby Class To Write Functional Code" - http://patshaughnessy.net/2014/4/8/using-a-ruby-class-to-write-functional-code
# Added: Line#to_s, #parse4, #parse5
class Line
attr_reader :Line
def initialize(text)
@line = text
end
@orend
orend / functional ruby
Created April 8, 2014 14:38
further refactoring to "Using a Ruby Class To Write Functional Code" : refactoring http://patshaughnessy.net/2014/4/8/using-a-ruby-class-to-write-functional-code
class Line
attr_reader :Line
def initialize(text)
@line = text
end
def office
values[2].strip