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
| // Mohli bychom se hádat, jestli tato funkce mění stav, ale referenčně transparentní rozhodně není: | |
| def f = new java.io.File("/tmp").exists | |
| // Tato funkce nemění stav, ale referenčně transparentní není: | |
| def g(x: String) = new java.io.File(x).exists | |
| object Foo{ | |
| var invocationCount: Int = 0 | |
| def h(x: Int){ |
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
| // Some plain classes with subclasses | |
| class Foo | |
| class SubFoo extends Foo | |
| class SubSubFoo extends SubFoo | |
| class SubSubSubFoo extends SubSubFoo | |
| // A generic class | |
| class Bar[T <: Foo](val foo: T) { | |
| } |
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
| // Toto odsazení je divné: | |
| case class User(nick: String, | |
| name: String, | |
| email: String) | |
| // Spíš bych použil: | |
| case class User( | |
| nick: String, | |
| name: String, |
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
| $ java -jar clojure-1.5.1.jar | |
| Clojure 1.5.1 | |
| user=> (defn plus-2-1 [n] (+ 2 n)) ; stary a nudny zpusob | |
| #'user/plus-2-1 | |
| user=> (def plus-2-2 (partial + 2)) ; partial application | |
| #'user/plus-2-2 | |
| user=> (def plus-2-3 (comp inc inc)) ; kompozice funkci | |
| #'user/plus-2-3 | |
| user=> "první měření" | |
| "první měření" |
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
| $ java -jar clojure-1.5.1.jar | |
| Clojure 1.5.1 | |
| user=> (defn plus-2 [n] (+ 2 n)) ; stary a nudny zpusob | |
| #'user/plus-2 | |
| user=> (time (dotimes [n 10000000] (plus-2 n))) | |
| "Elapsed time: 144.448077 msecs" | |
| nil | |
| user=> (time (dotimes [n 10000000] (plus-2 n))) | |
| "Elapsed time: 85.961736 msecs" | |
| nil |
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
| object NewHelloWorld extends App{ | |
| println("Hello world!") | |
| } |
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
| val key: PGPPublicKey = ... | |
| def encrypt(plaintext: String): String = { | |
| val baos = new ByteArrayOutputStream() | |
| val literalDataGenerator = new PGPLiteralDataGenerator() | |
| val comData = new PGPCompressedDataGenerator(CompressionAlgorithmTags.ZLIB) // I've also tried other compression algorithms | |
| val bytes = plaintext.getBytes("utf-8") | |
| val BufferSize = 1 << 16 | |
| import resource.managed // The "managed" method with for is just a nice replacement of try/catch/finally{x.close()} | |
| for{ |
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
| // An ugly hack for Bittorrent sync; hope to write more later | |
| // separate function for easier debugging | |
| show = function(x){console.log(["X:"+x.folders.map(function(x){return {folder: x, active_peers: x.peers.filter(function(peer){return peer.down_diff || peer.up_diff;})};}).filter(function(x){return x.active_peers.length > 0;}).map(function(x){return x.folder.name;})])} | |
| var origRequest = utWebUI.request; utWebUI.request= function(a, e, d, b){return origRequest.call(this, a, function(f){e && e(f); console.log(f.folders);}, d, b); }; |
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
| /dev/mapper/largetmp1 /tmp/large ext4 noauto,nosuid,noatime,delalloc,nobarrier,data=writeback,commit=36000 0 0 |
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
| #include <iostream> | |
| #include "json.h" | |
| using namespace std; | |
| int main() { | |
| Json::Number num(3.14159265358972); | |
| Json::String s("5.\" ' \1 0"); | |
| Json::Boolean t(true); | |
| Json::Boolean f(false); |