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
case 'h': | |
of 'a', 'e', 'i', 'o', 'u': | |
echo "Vowel" | |
of '\127'..'\255': | |
echo "Unknown" | |
else: | |
echo "Consonant" | |
proc positiveOrNegative(num: int): string = | |
result = case num: |
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
import threadpool, tables, strutils | |
const | |
filesArray = ["data1.txt", "data2.txt", "data3.txt"] | |
proc countWords2(filename: string): CountTableRef[string] = | |
result = newCountTable[string]() | |
for word in readFile(filename).splitWhitespace(): | |
result.inc word |
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 ([email protected], @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
# p6 | |
$_ = 'my123123 2replacements 7123'; | |
s/\d+//; # extract the first occurance of the numbers | |
# `m` is for matching | |
if 'properly' ~~ m/ perl / { | |
say "properly contains 'perl'" | |
} |
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) |
OlderNewer