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
| class Array | |
| def check_all_odd | |
| self.each do |i| | |
| if i.even? | |
| return false | |
| else | |
| next | |
| end | |
| end | |
| return true |
This is a small demo of how to create a library in Rust and call it from Python (both CPython and PyPy) using the CFFI instead of ctypes.
Based on http://harkablog.com/calling-rust-from-c-and-python.html (dead) which used ctypes
CFFI is nice because:
- Reads C declarations (parses headers)
- Works in both CPython and PyPy (included with PyPy)
- Lower call overhead than
ctypes
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
| /* | |
| Iterators and all functions that operates on iterators, are lazy by default. | |
| Executes on demand. | |
| Here in we have `println` that executes the lazy expression that is `largest`. | |
| */ | |
| fn main() { | |
| let a = [5,2,3,1,5,7,3]; |
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
| import strutils, random | |
| randomize() | |
| let answer = rand(10) | |
| while true: | |
| echo "Guess the number?" | |
| let guess = parseInt(stdin.readLine) | |
| if guess < answer: | |
| echo "Less than answer" |
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
| Useful One-Line Scripts for Perl Dec 03 2013 | version 1.10 | |
| -------------------------------- ----------- ------------ | |
| Compiled by Peteris Krumins (peter@catonmat.net, @pkrumins on Twitter) | |
| http://www.catonmat.net -- good coders code, great reuse | |
| Latest version of this file is always at: | |
| http://www.catonmat.net/download/perl1line.txt |
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 '[clojure.core.async :as a]) | |
| (def xform (comp (map inc) | |
| (filter even?) | |
| (dedupe) | |
| (flatmap range) | |
| (partition-all 3) | |
| (partition-by #(< (apply + %) 7)) | |
| (flatmap flatten) | |
| (random-sample 1.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
| ; who owns the zebra | |
| ; 1 There are five houses. | |
| ; 2 The Englishman lives in the red house. | |
| ; 3 The Spaniard owns the dog. | |
| ; 4 Coffee is drunk in the green house. | |
| ; 5 The Ukrainian drinks tea. | |
| ; 6 The green house is immediately to the right of the ivory house. | |
| ; 7 The Old Gold smoker owns snails. | |
| ; 8 Kools are smoked in the yellow house. |
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
| (println "Hello") | |
| (let [x 1 | |
| y 2] | |
| (print "foo") | |
| (str 1 2 | |
| 3 4 5)) | |
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
| (defproject uncomp-1 "0.1.0-SNAPSHOT" | |
| :description "Example project showcasing uncomplicate power" | |
| :url "http://example.com/FIXME" | |
| :license {:name "Eclipse Public License" | |
| :url "http://www.eclipse.org/legal/epl-v10.html"} | |
| :dependencies [[org.clojure/clojure "1.9.0"] | |
| [uncomplicate/neanderthal "0.18.0" :exclusions [[org.jcuda/jcuda-natives] | |
| [org.jcuda/jcublas-natives]]]] | |
| :main ^:skip-aot uncomp-1.core | |
| :target-path "target/%s" |
OlderNewer