September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,61 @@
@echo off
setlocal enabledelayedexpansion
call:commonpath /home/user1/tmp/coverage/test /home/user1/tmp/covert/operator /home/user1/tmp/coven/members
pause>nul
exit /b
:commonpath
setlocal enabledelayedexpansion
for %%i in (%*) do (
set /a args+=1
set arg!args!=%%i
set fullarg!args!=%%i
)
for /l %%i in (1,1,%args%) do set fullarg%%i=!fullarg%%i:/= !
for /l %%i in (1,1,%args%) do (
set tempcount=0
for %%j in (!fullarg%%i!) do (
set /a tempcount+=1
set arg%%it!tempcount!=%%j
set arg%%itokencount=!tempcount!
)
)
set mintokencount=%arg1tokencount%
set leasttokens=1
for /l %%i in (1,1,%args%) do (
set currenttokencount=!arg%%itokencount!
if !currenttokencount! lss !mintokencount! (
set mintokencount=!currenttokencount!
set leasttokens=%%i
)
)
for /l %%i in (1,1,%mintokencount%) do set commonpath%%i=!arg%leasttokens%t%%i!
for /l %%i in (1,1,%mintokencount%) do (
for /l %%j in (1,1,%args%) do (
set currentpath=!arg%%jt%%i!
if !currentpath!==!commonpath%%i! set pathtokens%%j=%%i
)
)
set minpathtokens=%pathtokens1%
set leastpathtokens=1
for /l %%i in (1,1,%args%) do (
set currentpathtokencount=!pathtokens%%i!
if !currentpathtokencount! lss !minpathtokens! (
set minpathtokencount=!currentpathtokencount!
set leastpathtokens=%%i
)
)
set commonpath=/
for /l %%i in (1,1,!pathtokens%leastpathtokens%!) do set commonpath=!commonpath!!arg%leastpathtokens%t%%i!/
echo %commonpath%
endlocal
exit /b

View file

@ -0,0 +1,17 @@
Public Sub Main()
Dim sFolder As String[] = ["/home/user1/tmp/coverage/test", "/home/user1/tmp/covert/operator", "/home/user1/tmp/coven/members"]
Dim sSame As String
Dim siCount As Short = 1
Do
If Mid(sFolder[0], siCount, 1) = Mid(sFolder[1], siCount, 1) And Mid(sFolder[0], siCount, 1) = Mid(sFolder[2], siCount, 1) Then
sSame &= Mid(sFolder[0], siCount, 1)
Else
Break
End If
Inc siCount
Loop
Print Mid(sSame, 1, RInStr(sSame, "/") - 1)
End

View file

@ -0,0 +1,9 @@
dirpath:=proc(a,b,c)
local dirtemp,dirnew,x;
use StringTools in
dirtemp:=LongestCommonSubString(c, LongestCommonSubString(a,b));
x:=FirstFromRight("/",dirtemp);
dirnew:=dirtemp[1..x];
return dirnew;
end use;
end proc;

View file

@ -0,0 +1,22 @@
function common_directory_path(sequence paths, integer sep='/')
sequence res = {}
if length(paths) then
res = split(paths[1],sep)[1..-2]
for i=2 to length(paths) do
sequence pi = split(paths[i],sep)[1..-2]
for j=1 to length(res) do
if j>length(pi) or res[j]!=pi[j] then
res = res[1..j-1]
exit
end if
end for
if length(res)=0 then exit end if
end for
end if
return join(res,sep)
end function
constant test = {"/home/user1/tmp/coverage/test",
"/home/user1/tmp/covert/operator",
"/home/user1/tmp/coven/members"}
?common_directory_path(test)

View file

@ -0,0 +1,26 @@
# Project : Find common directory path
# Author : Gal Zsolt (~ CalmoSoft ~)
# Email : <calmosoft@gmail.com>
load "stdlib.ring"
i = null
o = null
path = list(3)
path[1] = "/home/user1/tmp/coverage/test"
path[2] = "/home/user1/tmp/covert/operator"
path[3] = "/home/user1/tmp/coven/members"
see commonpath(path, "/")
func commonpath(p, s)
while i != 0
o = i
i = substring(p[1], s, i+1)
for j = 2 to len(p)
if left(p[1], i) != left(p[j], i)
exit 2
ok
next
end
return left(p[1], o-1)

View file

@ -0,0 +1,17 @@
import Foundation
func getPrefix(_ text:[String]) -> String? {
var common:String = text[0]
for i in text {
common = i.commonPrefix(with: common)
}
return common
}
var test = ["/home/user1/tmp/coverage/test",
"/home/user1/tmp/covert/operator",
"/home/user1/tmp/coven/members"]
var output:String = getPrefix(test)!
print(output)

View file

@ -0,0 +1,5 @@
dirs:=T("/home/user1/tmp/coverage/test", "/home/user1/tmp/covert/operator",
"/home/user1/tmp/coven/members");
n:=Utils.zipWith('==,dirs.xplode()).find(False); // character pos which differs
n=dirs[0][0,n].rfind("/"); // find last "/"
dirs[0][0,n];