Re: strutils find

2019-03-21 Thread dataman
There is awesome [String Matching Algorithms Research 
Tool](https://smart-tool.github.io/smart/). 


Re: A microbenchmarking library

2018-08-20 Thread dataman
Cool! Where is dip module? :) (in statistics.nim)


Re: do regular expression on unicode string?

2018-08-17 Thread dataman
Try this: 


import nre

let txt = "自我 我们 我"  # this is actually read from external file
let r = re"(*U).{0,1}我.{0,1}"

for res in findAll(txt, r):
  echo res


Run

Show for me:


自我
我们
 我


Run


Re: cannot countProcessor in compile time

2018-05-23 Thread dataman
The best way for this feature is to add a new code to the VM. No chances. 


Re: Why is Nim so slow in this

2018-05-19 Thread dataman
@machingan

> If it's in Windows, antivirus is to blame.

Oh! Do you think that anti-viruses don't check executable files created by 
other compilers?

If so, then this is the conspiracy against Nim! 


Re: Statistics for standard library usage

2018-05-01 Thread dataman
> I am against reducing standard library.

Fully agreed! To the contrary, I would prefer to expand it.


Re: How to add unique items to array?

2018-04-18 Thread dataman
import intsets

var
s = initIntSet()

s.incl(1) s.incl(10)

echo s echo s.card


Re: How to add unique items to array?

2018-04-18 Thread dataman
@jzakiya

> Is there a way to increase the size, or work around this?

Try [IntSet](https://nim-lang.org/docs/intsets.html).


Re: a proc returning void creates 1 arg, not 0: breaking generic code

2018-03-29 Thread dataman
@timothee

Why don't you write D as d? Please learn to write Nim with a capital letter. 
This is disrespectful at least.


Re: Looking for efficient API for regexp library

2018-03-01 Thread dataman
@zevv, your library doesn't support utf-8. IMO, this is a big disadvantage.

BTW, have you seen [nim-regex](https://github.com/nitely/nim-regex) library?


Re: File, FileStream, and GZFileStream

2018-01-19 Thread dataman
@bli

Perhaps the [NimData](https://github.com/bluenote10/NimData) package will be 
useful for you. This package has the ability to read data from a gzip archive.


Re: bytes to hex string

2017-11-14 Thread dataman

import strutils

proc hexDump*[T](v: T): string =
  var s: seq[uint8] = @[]
  s.setLen(v.sizeof)
  copymem(addr(s[0]), v.unsafeAddr, v.sizeof)
  result = ""
  for i in s: result.add(i.toHex)

var
  i: int64 = 123
  ui: uint64 = 123
  f: float = 123.45
  s = @[1, 2, 3, 4]
  t: tuple[a: int, b: string] = (1, "123")
  set: set[uint8] = {1'u8..3'u8, 5'u8..6'u8}
  a: array[5, uint8] = [1'u8, 2, 3, 4, 5]

echo i.hexDump
echo ui.hexDump
echo f.hexDump
echo s.hexDump
echo t.hexDump
echo set.hexDump
echo a.hexDump



Re: How do you keep your motivation on your open-source projects

2017-10-28 Thread dataman
> what keeps you motivated or make you most happy in an open-source project (or 
> inversely)

When my pull-requests are accepted.  This means that not only I find them 
useful. This is very important.


The Git - useful tips

2017-07-15 Thread dataman
Hello everybody!

I found a very useful tip on using pull requests: [Checkout github pull 
requests locally](https://gist.github.com/piscisaureus/3342247)

I quoted:

> Locate the section for your github remote in the .git/config file. It looks 
> like this:
> 
> 
>  [remote "origin"]
> fetch = +refs/heads/*:refs/remotes/origin/*
> url = g...@github.com:joyent/node.git
>  
> 
> Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this 
> section. Obviously, change the github url to match your project's URL. It 
> ends up looking like this:
> 
> 
>  [remote "origin"]
> fetch = +refs/heads/*:refs/remotes/origin/*
> url = g...@github.com:joyent/node.git
> fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
>  
> 
> Now fetch all the pull requests:
> 
> 
>  $ git fetch origin
>  From github.com:joyent/node
>   * [new ref] refs/pull/1000/head -> origin/pr/1000
>   * [new ref] refs/pull/1002/head -> origin/pr/1002
>   * [new ref] refs/pull/1004/head -> origin/pr/1004
>   * [new ref] refs/pull/1009/head -> origin/pr/1009
>  ...
>  
> 
> To check out a particular pull request:
> 
> 
>  $ git checkout pr/999
>  Branch pr/999 set up to track remote branch pr/999 from origin.
>  Switched to a new branch 'pr/999'
>  

**Warning: the size of the repository will increase significantly in the 
occupied space!**

I would be happy if it is useful to someone.

And how do you use git?


Re: Nim Koans?

2017-06-12 Thread dataman
> Does anyone know of any Nim koan or practice problem repositories?

[http://rosettacode.org/wiki/Category:Nim](http://rosettacode.org/wiki/Category:Nim)

[http://exercism.io/languages/nim/exercises](http://exercism.io/languages/nim/exercises)


Re: Slow strings

2017-05-20 Thread dataman
Levenshtein distance, based on my old Pascal source. In some cases, faster than 
a implementation in strutils module by 10%.

(Enj|Destr)oy! 


import strutils, os
import nimbench

proc editDistance2*(a, b: string): int = #{.noSideEffect.} =
  ## Returns the edit distance between `a` and `b`.
  ##
  ## This uses the `Levenshtein`:idx: distance algorithm with only a linear
  ## memory overhead.  This implementation is highly optimized!
  var len1 = a.len
  var len2 = b.len
  if len1 > len2:
# make `b` the longer string
return editDistance(b, a)
  
  # strip common prefix:
  var s = 0
  while a[s] == b[s] and a[s] != '\0':
inc(s)
dec(len1)
dec(len2)
  
  # strip common suffix:
  while len1 > 0 and len2 > 0 and a[s+len1-1] == b[s+len2-1]:
dec(len1)
dec(len2)
  
  # trivial cases:
  if len1 == 0: return len2
  if len2 == 0: return len1
  
  # another special case:
  if len1 == 1:
for j in s..s+len2-1:
  if a[s] == b[j]: return len2 - 1

return len2
  
  inc(len1)
  inc(len2)
  var row: seq[int]
  newSeq(row, len2)
  
  for i in 0..len2 - 1: row[i] = i
  
  for i in 1 .. len1- 1:
var char1 = a[s + i - 1]
var prevCost = i - 1;
var newCost = i;

for j in 1 .. len2 - 1:
  var char2 = b[s + j - 1]
  
  if char1 == char2:
newCost = prevCost
  else:
newCost = min(newCost, min(prevCost, row[j])) + 1
  
  prevCost = row[j]
  row[j] = newCost
  
  result = row[len2 - 1]

var s1: string = "0123456789"
var s2: string = "0123455779"

if paramCount() > 1:
  if fileExists(paramStr(1)):
s1 = readFile(paramStr(1))
  else:
s1 = paramStr(1)
  
  if fileExists(paramStr(2)):
s2 = readFile(paramStr(2))
  else:
s2 = paramStr(2)

echo "editDistance:  ", editDistance(s1, s2)
echo "editDistance2: ", editDistance2(s1, s2)

bench(editDistance, m):
  var d = 0
  for i in 1..m:
d = editDistance(s1, s2)
  
  doNotOptimizeAway(d)

benchRelative(editDistance2, m):
  var d = 0
  
  for i in 1..m:
d = editDistance2(s1, s2)
  
  doNotOptimizeAway(d)


runBenchmarks()



Re: Please , can we stop spams?

2017-05-20 Thread dataman
Almost two days passed, and my first message is still moderated. I have never 
seen such an attitude to users at any forum.


Re: Version 0.17.0 released!

2017-05-18 Thread dataman
Congratulations!

Also bitops module (very useful) added.