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
| $ cat b.rb | |
| (1..10).map { |n| | |
| array = (1..5_000_000).map {|x| x * x } | |
| } | |
| $ time ruby b.rb | |
| real 0m5.502s | |
| user 0m5.344s |
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
| #!strongSpaces | |
| import jester, strtabs, htmlgen, strutils, os | |
| proc fib(n: int): int = | |
| if n < 2: | |
| result = n | |
| else: | |
| result = fib(n-1) + fib(n-2) | |
| get "/fib/?": |
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 <stdio.h> | |
| #define BUFSIZE 8*1024 | |
| int main() | |
| { | |
| FILE *fp = stdin; /* or use fopen to open a file */ | |
| char buf[BUFSIZE+1]; | |
| unsigned long c, n = 0; | |
| int i, chars_read; |
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
| # nimrod c -d:ssl connect.nim | |
| # connect.nim(12, 4) Error: undeclared identifier: 'isSSL=' | |
| import sockets, strutils | |
| var | |
| sock: TSocket | |
| server = "www.google.com" | |
| port = 443 |
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
| # nimrod c -d:ssl connect.nim | |
| import sockets, strutils | |
| let defaultSSLContext = newContext(verifyMode = CVerifyNone) | |
| var | |
| s = socket() | |
| server = "www.google.com" |
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
| # length of data in 32-bit unsigned, network (big-endian) byte order | |
| # plus the data (and increase length by 4 to account for length field | |
| def packed(xml) | |
| [xml.size + 4].pack("N") + xml | |
| end | |
| puts packed("a test packet") |
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
| var r = 0 | |
| var tmp:int32 = cast[int32](pkt.len) | |
| var thenum:int32 = 0 | |
| bigEndian32(addr(thenum), addr(tmp)) | |
| echo repr(addr(thenum)) | |
| r = s.send(addr(thenum), 4) |
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 | |
| # use mod == 0 a lot... | |
| proc mod0(a,b:int):bool = (a mod b) == 0 | |
| # if i try to add to "result" directly I get a SIGSEGV | |
| # so use "res" instead. why? | |
| # oh yeah and there's probably a much better way to do this... | |
| proc addCommas(s:string): 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
| var buckets: array[0..9, string] | |
| # initialize. wish they were automagically initialized | |
| for i in 0..buckets.high: buckets[i] = "" | |
| # XXX not work | |
| for i in 0..1: | |
| for buck in buckets: | |
| # following line doesn't work. compile error: | |
| # Error: for a 'var' type a variable needs to be passed |
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 unsigned | |
| type hp = array[0..1,uint32] | |
| var | |
| cells: seq[hp] = @[] | |
| ncells = 3 | |
| cells.add( [uint32(1),uint32(0)] ) | |
| echo repr(cells) | |
| # => 0x7f8197d0b050[[(invalid data!), (invalid data!)]] |