Skip to content

Commit

Permalink
Port before_v0.60/data_extraction before_v0.60/examples `before_v…
Browse files Browse the repository at this point in the history
…0.60/duplicates` (#847)

This PR is part of porting all old scripts #221 and includes a set of
modules:

- `data_extraction`
- `examples` 
- `duplicates`

## 7 changed files:

### `data_extraction`
- `data_extraction/ultimate_extractor.nu`: removed. Has already been
ported to `modules/data_extraction/ultimate_extractor.nu`

### `duplicates`
- `duplicates/duplicates.nu` -> `modules/duplicates/duplicates.nu`
- `duplicates/example.nu` -> `modules/duplicates/example.nu`
- `duplicates/README.md` -> `modules/duplicates/README.md`: unchanged

### `examples`
- `examples/netstat.nu` -> `modules/examples/netstat.nu`
- `examples/date_in_local_timezones.nu` ->
`modules/examples/date_in_local_timezones.nu`
- `befove_v0.60/assets/core_team.nu`: removed. This table has been
embedded into `date_in_local_timezones.nu`
  • Loading branch information
39555 committed May 26, 2024
1 parent 9d399d8 commit 275a0f8
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 93 deletions.
12 changes: 0 additions & 12 deletions before_v0.60/assets/core_team.nu

This file was deleted.

27 changes: 0 additions & 27 deletions before_v0.60/data_extraction/ultimate_extractor.nu

This file was deleted.

25 changes: 0 additions & 25 deletions before_v0.60/examples/date_in_local_timezones.nu

This file was deleted.

17 changes: 0 additions & 17 deletions before_v0.60/examples/netstat.nu

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# duplicates example
echo $info | from json
use mod.nu *

let info = "[{name: "John", lastname: "Doe"}, {name: "John", lastname: "Roe"}, {name: "Jane", lastname: "Soe"}]"
echo $info | from json | duplicates name
print ($info | from json)
print ($info | from json | duplicates name)

#duplicates files example
echo A | save A.txt
echo A | save B.txt
# note that if I used "echo B | save B.txt" the function will give a false positive
echo ABC | save C.txt
ls
duplicates files
rm A.txt B.txt C.txt --permanent
print (ls)
print (duplicates files)
rm A.txt B.txt C.txt --permanent
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# duplicates returns the rows that correspond to duplicates of the given column.
def duplicates [
export def duplicates [
column: string # Column to look duplicates at
--count(-c) # set it to display the number of times the value is repeated.
] {
group-by $column |
pivot |
insert count { $it.Column1 | flatten | length } |
group-by {get $column | into string} |
transpose |
insert count { $in.column1 | flatten | length } |
where count > 1 |
reject Column0 |
if ($count | empty?) { reject count } { each { $it } } |
reject column0 |
if ($count | is-empty) { reject count } else { each { $in } } |
flatten |
flatten
}

# duplicates files recursively finds duplicate files in the current working folder.
# It uses a heuristic based on duplicate files having the same size.
def "duplicates files" [] {
export def "duplicates files" [] {
do -i {ls **/*} | duplicates size
}

Expand Down
42 changes: 42 additions & 0 deletions sourced/examples/date_in_local_timezones.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

def "nu core-team" [] {
[
[ 'name', 'tz'];
[ 'andres', 'America/Guayaquil']
[ 'fdncred', 'US/Central']
[ 'gedge', 'US/Eastern']
[ 'jt', 'NZ']
[ 'wycats', 'US/Pacific']
[ 'kubouch', 'Europe/Helsinki']
['elferherrera', 'Europe/London']
]
}

def "date local" [now] {
insert time {|value|
let converted = ($now | date to-timezone $value.tz);

$converted | format date '%c'
}
}

let next_call = ("2021-08-31 15:00:21.290597200 -05:00" | into datetime);
let people = (nu core-team | date local $next_call);

def say [closure] {
$in | each {|person|
do $closure (
$person | update name {|row| $row.name | str capitalize}
)
} | str join (char newline)
}

print ($people | say {|person| $"($person.name)'s timezone is ($person.tz)"})

print ($"
for the next call happening on ($next_call | format date '%c').. in their timezones they would be:
")

print ($people | say {|person| $"($person.name)'s: ($person.time)"})
25 changes: 25 additions & 0 deletions sourced/examples/netstat.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
let ns = (netstat | lines | skip 1)

let first_batch = ($ns | take until {|it| $it =~ Active } | str join (char nl) | from ssv -m 1)
let second_batch = ($ns |
skip until {|it| $it =~ Active } |
skip 1 |
str join (char nl) |
str replace '\[ \]' "[]" --all |
from ssv -m 1 |
default I-Node "" |
default Path ""
| each {|row| if $row.Type == DGRAM {
$row | update Path { get I-Node } | update I-Node { get State } | update State ""
} else {
$row
}
}
)

print $first_batch
print $second_batch




0 comments on commit 275a0f8

Please sign in to comment.