Aaron Judge |
Tuesday, June 13, 2017
Sunday, June 11, 2017
Saturday, June 10, 2017
Friday, June 9, 2017
macOS Sierra: Bash (Unix shell): Associative Array Example: Reading from CSV into Array
Command:
$ cat associative_array3.sh
Result:
#!/bin/bash
aa=()
while IFS=, read -ra line; do if [ -n "${line[0]}" ]; then aa+=("${line[0]}::${line[3]}");fi;done < List\ of\ organisms\ by\ population.csv
total=0
for k in "${aa[@]}"
do
value="${k##*::}"
total=$((total + value))
done
echo "Total population: $total"
LC_CTYPE=C; MIN=1; MAX=$total; while rnd=$(cat /dev/urandom | tr -dc 0-9 | fold -w${#MAX} | head -1 | sed 's/^0*//;'); [ -z $rnd ] && rnd=0; (( $rnd < $MIN || $rnd > $MAX)); do :; done;
echo "Random index: $rnd"
index=$rnd
current=0
for k in "${aa[@]}"
do
value="${k##*::}"
current=$((current + value))
if [ $index -le $current ]
then
name="${k%%::*}"
population=$value
break
fi
done
echo "$name (population: $population)"
printf "Probability: "
echo "$population/$total" | bc -l
Command:
$ ./associative_array3.sh
Result:
Total population: 13958220136
Random index: 8955227583
Domestic pig (population: 1000000000)
Probability: .07164237204003357179
Result:
Total population: 13958220136
Random index: 4227209587
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Total population: 13958220136
Random index: 7805864096
Cattle (population: 1000000000)
Probability: .07164237204003357179
Result:
Total population: 13958220136
Random index: 8511144278
Domestic pig (population: 1000000000)
Probability: .07164237204003357179
Result:
Total population: 13958220136
Random index: 3892081176
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Total population: 13958220136
Random index: 2589979307
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Total population: 13958220136
Random index: 7946872317
Cattle (population: 1000000000)
Probability: .07164237204003357179
Result:
Total population: 13958220136
Random index: 372258826
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Total population: 13958220136
Random index: 13908122684
Short-eared owl (population: 2000000)
Probability: .00014328474408006714
Result:
Total population: 13958220136
Random index: 7247815301
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Total population: 13958220136
Random index: 9352855300
Domestic sheep (population: 1000000000)
Probability: .07164237204003357179
Result:
Total population: 13958220136
Random index: 9642135454
Domestic sheep (population: 1000000000)
Probability: .07164237204003357179
Result:
Total population: 13958220136
Random index: 11711491958
Cat (population: 600000000)
Probability: .04298542322402014307
Result:
Total population: 13958220136
Random index: 3990365909
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Total population: 13958220136
Random index: 272907397
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Total population: 13958220136
Random index: 9041133545
Domestic pig (population: 1000000000)
Probability: .07164237204003357179
Result:
Total population: 13958220136
Random index: 7777621570
Cattle (population: 1000000000)
Probability: .07164237204003357179
Result:
Total population: 13958220136
Random index: 9017444984
Domestic pig (population: 1000000000)
Probability: .07164237204003357179
Result:
Total population: 13958220136
Random index: 4118816981
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Total population: 13958220136
Random index: 3797333834
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Total population: 13958220136
Random index: 12061584807
Mourning dove (population: 475000000)
Probability: .03403012671901594660
Result:
Total population: 13958220136
Random index: 12170053267
Mourning dove (population: 475000000)
Probability: .03403012671901594660
Result:
Total population: 13958220136
Random index: 531916373
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Total population: 13958220136
Random index: 10657946193
Domestic goat (population: 850000000)
Probability: .06089601623402853602
Result:
Total population: 13958220136
Random index: 13481628295
Collared trogon (population: 50000000)
Probability: .00358211860200167858
Result:
Total population: 13958220136
Random index: 9130914826
Domestic pig (population: 1000000000)
Probability: .07164237204003357179
Result:
Total population: 13958220136
Random index: 7627418145
Cattle (population: 1000000000)
Probability: .07164237204003357179
Result:
Total population: 13958220136
Random index: 12225242832
Mourning dove (population: 475000000)
Probability: .03403012671901594660
Result:
Total population: 13958220136
Random index: 3731595661
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Total population: 13958220136
Random index: 11796334858
Cat (population: 600000000)
Probability: .04298542322402014307
Result:
Total population: 13958220136
Random index: 7477886491
Cattle (population: 1000000000)
Probability: .07164237204003357179
Result:
Total population: 13958220136
Random index: 760089938
Human (population: 7350000000)
Probability: .52657143449424675272
$ cat associative_array3.sh
Result:
#!/bin/bash
aa=()
while IFS=, read -ra line; do if [ -n "${line[0]}" ]; then aa+=("${line[0]}::${line[3]}");fi;done < List\ of\ organisms\ by\ population.csv
total=0
for k in "${aa[@]}"
do
value="${k##*::}"
total=$((total + value))
done
echo "Total population: $total"
LC_CTYPE=C; MIN=1; MAX=$total; while rnd=$(cat /dev/urandom | tr -dc 0-9 | fold -w${#MAX} | head -1 | sed 's/^0*//;'); [ -z $rnd ] && rnd=0; (( $rnd < $MIN || $rnd > $MAX)); do :; done;
echo "Random index: $rnd"
index=$rnd
current=0
for k in "${aa[@]}"
do
value="${k##*::}"
current=$((current + value))
if [ $index -le $current ]
then
name="${k%%::*}"
population=$value
break
fi
done
echo "$name (population: $population)"
printf "Probability: "
echo "$population/$total" | bc -l
Command:
$ ./associative_array3.sh
Result:
Total population: 13958220136
Random index: 8955227583
Domestic pig (population: 1000000000)
Probability: .07164237204003357179
Result:
Random index: 4227209587
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Random index: 7805864096
Cattle (population: 1000000000)
Probability: .07164237204003357179
Result:
Random index: 8511144278
Domestic pig (population: 1000000000)
Probability: .07164237204003357179
Result:
Random index: 3892081176
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Random index: 2589979307
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Random index: 7946872317
Cattle (population: 1000000000)
Probability: .07164237204003357179
Result:
Random index: 372258826
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Random index: 13908122684
Short-eared owl (population: 2000000)
Probability: .00014328474408006714
Result:
Random index: 7247815301
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Random index: 9352855300
Domestic sheep (population: 1000000000)
Probability: .07164237204003357179
Result:
Random index: 9642135454
Domestic sheep (population: 1000000000)
Probability: .07164237204003357179
Result:
Random index: 11711491958
Cat (population: 600000000)
Probability: .04298542322402014307
Result:
Random index: 3990365909
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Random index: 272907397
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Random index: 9041133545
Domestic pig (population: 1000000000)
Probability: .07164237204003357179
Result:
Random index: 7777621570
Cattle (population: 1000000000)
Probability: .07164237204003357179
Result:
Random index: 9017444984
Domestic pig (population: 1000000000)
Probability: .07164237204003357179
Result:
Random index: 4118816981
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Random index: 3797333834
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Random index: 12061584807
Mourning dove (population: 475000000)
Probability: .03403012671901594660
Result:
Random index: 12170053267
Mourning dove (population: 475000000)
Probability: .03403012671901594660
Result:
Random index: 531916373
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Random index: 10657946193
Domestic goat (population: 850000000)
Probability: .06089601623402853602
Result:
Random index: 13481628295
Collared trogon (population: 50000000)
Probability: .00358211860200167858
Result:
Random index: 9130914826
Domestic pig (population: 1000000000)
Probability: .07164237204003357179
Result:
Random index: 7627418145
Cattle (population: 1000000000)
Probability: .07164237204003357179
Result:
Random index: 12225242832
Mourning dove (population: 475000000)
Probability: .03403012671901594660
Result:
Random index: 3731595661
Human (population: 7350000000)
Probability: .52657143449424675272
Result:
Random index: 11796334858
Cat (population: 600000000)
Probability: .04298542322402014307
Result:
Random index: 7477886491
Cattle (population: 1000000000)
Probability: .07164237204003357179
Result:
Random index: 760089938
Human (population: 7350000000)
Probability: .52657143449424675272
Thursday, June 8, 2017
macOS Sierra: Bash (Unix shell): Associative Array Example: Random Bird (using List of birds by population)
Command:
$ cat associative_array2.sh
Result:
#!/bin/bash
aa=(
'Mallard::17000000'
'Chimney swift::15000000'
'European nightjar::6000000'
'Thick-billed murre::22000000'
'White-faced ibis::1200000'
'Rock dove::260000000'
'Rainbow bee-eater::1000000'
'Common cuckoo::100000000'
'Common Kestrel::5000000'
'Willow ptarmigan::40000000'
'Pacific loon::1600000'
'American coot::6000000'
'Red-footed booby::1000000'
'Lesser flamingo::3240000'
'Great spotted woodpecker::216000000'
'Black-necked grebe::42000000'
'Short-tailed shearwater::23000000'
'Red-tailed black cockatoo::100000'
'Macaroni penguin::18000000'
'Short-eared owl::2000000'
'Southern brown kiwi::29800'
'Little tinamou::4999999'
'Collared trogon::50000000'
'Laysan duck::521'
'Juan Fernández firecrown::3000'
'Puerto Rican nightjar::2000'
'Shore dotterel::250'
"Storm's stork::500"
'Socorro dove::100'
'Narcondam hornbill::340'
'Black-hooded coucal::70'
'Madagascar fish eagle::360'
'Bornean peacock-pheasant::2499'
'Yellow-billed loon::32000'
'Lord Howe woodhen::230'
'Flightless cormorant::1679'
'Andean flamingo::38000'
'Ivory-billed woodpecker::50'
'New Zealand grebe::2000'
'New Zealand storm petrel::50'
'Kakapo::126'
'Galapagos penguin::1800'
'Forest owlet::400'
'Little spotted kiwi::1200'
'Slaty-breasted tinamou::49999'
'Javan trogon::1500'
)
total=0
for k in "${aa[@]}"
do
value="${k##*::}"
total=$((total + value))
done
echo "Total population: $total"
LC_CTYPE=C; MIN=1; MAX=$total; while rnd=$(cat /dev/urandom | tr -dc 0-9 | fold -w${#MAX} | head -1 | sed 's/^0*//;'); [ -z $rnd ] && rnd=0; (( $rnd < $MIN || $rnd > $MAX)); do :; done;
echo "Random index: $rnd"
index=$rnd
current=0
for k in "${aa[@]}"
do
value="${k##*::}"
current=$((current + value))
if [ $index -le $current ]
then
name="${k%%::*}"
population=$value
break
fi
done
echo "$name (population: $population)"
printf "Probability: "
echo "$population/$total" | bc -l
Command:
$ ./associative_array2.sh
Result:
Total population: 835308473
Random index: 763607797
Macaroni penguin (population: 18000000)
Probability: .02154892543511886536
Result:
Total population: 835308473
Random index: 442019183
Willow ptarmigan (population: 40000000)
Probability: .04788650096693081191
Result:
Total population: 835308473
Random index: 600337171
Great spotted woodpecker (population: 216000000)
Probability: .25858710522142638435
Result:
Total population: 835308473
Random index: 542347304
Great spotted woodpecker (population: 216000000)
Probability: .25858710522142638435
Result:
Total population: 835308473
Random index: 399097554
Common cuckoo (population: 100000000)
Probability: .11971625241732702979
Result:
Total population: 835308473
Random index: 602221971
Great spotted woodpecker (population: 216000000)
Probability: .25858710522142638435
Result:
Total population: 835308473
Random index: 31407682
Chimney swift (population: 15000000)
Probability: .01795743786259905446
Result:
Total population: 835308473
Random index: 471711629
American coot (population: 6000000)
Probability: .00718297514503962178
Result:
Total population: 835308473
Random index: 127100259
Rock dove (population: 260000000)
Probability: .31126225628505027746
Result:
Total population: 835308473
Random index: 380012920
Common cuckoo (population: 100000000)
Probability: .11971625241732702979
Result:
Total population: 835308473
Random index: 394531514
Common cuckoo (population: 100000000)
Probability: .11971625241732702979
Result:
Total population: 835308473
Random index: 78048210
Rock dove (population: 260000000)
Probability: .31126225628505027746
Result:
Total population: 835308473
Random index: 33341909
European nightjar (population: 6000000)
Probability: .00718297514503962178
Result:
Total population: 835308473
Random index: 211802308
Rock dove (population: 260000000)
Probability: .31126225628505027746
Result:
Total population: 835308473
Random index: 94119789
Rock dove (population: 260000000)
Probability: .31126225628505027746
Result:
Total population: 835308473
Random index: 359620354
Common cuckoo (population: 100000000)
Probability: .11971625241732702979
Result:
Total population: 835308473
Random index: 429592312
Willow ptarmigan (population: 40000000)
Probability: .04788650096693081191
Result:
Total population: 835308473
Random index: 199643906
Rock dove (population: 260000000)
Probability: .31126225628505027746
Result:
Total population: 835308473
Random index: 656519406
Great spotted woodpecker (population: 216000000)
Probability: .25858710522142638435
Result:
Total population: 835308473
Random index: 448395870
Willow ptarmigan (population: 40000000)
Probability: .04788650096693081191
Result:
Total population: 835308473
Random index: 392079604
Common cuckoo (population: 100000000)
Probability: .11971625241732702979
Result:
Total population: 835308473
Random index: 61798025
Rock dove (population: 260000000)
Probability: .31126225628505027746
Result:
Total population: 835308473
Random index: 778932643
Short-eared owl (population: 2000000)
Probability: .00239432504834654059
Result:
Total population: 835308473
Random index: 393661406
Common cuckoo (population: 100000000)
Probability: .11971625241732702979
Result:
Total population: 835308473
Random index: 88104221
Rock dove (population: 260000000)
Probability: .31126225628505027746
Result:
Total population: 835308473
Random index: 623477130
Great spotted woodpecker (population: 216000000)
Probability: .25858710522142638435
Result:
Total population: 835308473
Random index: 401873132
Common cuckoo (population: 100000000)
Probability: .11971625241732702979
Result:
Total population: 835308473
Random index: 680185574
Great spotted woodpecker (population: 216000000)
Probability: .25858710522142638435
Result:
Total population: 835308473
Random index: 724901495
Black-necked grebe (population: 42000000)
Probability: .05028082601527735251
Result:
Total population: 835308473
Random index: 281804665
Rock dove (population: 260000000)
Probability: .31126225628505027746
$ cat associative_array2.sh
Result:
#!/bin/bash
aa=(
'Mallard::17000000'
'Chimney swift::15000000'
'European nightjar::6000000'
'Thick-billed murre::22000000'
'White-faced ibis::1200000'
'Rock dove::260000000'
'Rainbow bee-eater::1000000'
'Common cuckoo::100000000'
'Common Kestrel::5000000'
'Willow ptarmigan::40000000'
'Pacific loon::1600000'
'American coot::6000000'
'Red-footed booby::1000000'
'Lesser flamingo::3240000'
'Great spotted woodpecker::216000000'
'Black-necked grebe::42000000'
'Short-tailed shearwater::23000000'
'Red-tailed black cockatoo::100000'
'Macaroni penguin::18000000'
'Short-eared owl::2000000'
'Southern brown kiwi::29800'
'Little tinamou::4999999'
'Collared trogon::50000000'
'Laysan duck::521'
'Juan Fernández firecrown::3000'
'Puerto Rican nightjar::2000'
'Shore dotterel::250'
"Storm's stork::500"
'Socorro dove::100'
'Narcondam hornbill::340'
'Black-hooded coucal::70'
'Madagascar fish eagle::360'
'Bornean peacock-pheasant::2499'
'Yellow-billed loon::32000'
'Lord Howe woodhen::230'
'Flightless cormorant::1679'
'Andean flamingo::38000'
'Ivory-billed woodpecker::50'
'New Zealand grebe::2000'
'New Zealand storm petrel::50'
'Kakapo::126'
'Galapagos penguin::1800'
'Forest owlet::400'
'Little spotted kiwi::1200'
'Slaty-breasted tinamou::49999'
'Javan trogon::1500'
)
total=0
for k in "${aa[@]}"
do
value="${k##*::}"
total=$((total + value))
done
echo "Total population: $total"
LC_CTYPE=C; MIN=1; MAX=$total; while rnd=$(cat /dev/urandom | tr -dc 0-9 | fold -w${#MAX} | head -1 | sed 's/^0*//;'); [ -z $rnd ] && rnd=0; (( $rnd < $MIN || $rnd > $MAX)); do :; done;
echo "Random index: $rnd"
index=$rnd
current=0
for k in "${aa[@]}"
do
value="${k##*::}"
current=$((current + value))
if [ $index -le $current ]
then
name="${k%%::*}"
population=$value
break
fi
done
echo "$name (population: $population)"
printf "Probability: "
echo "$population/$total" | bc -l
Command:
$ ./associative_array2.sh
Result:
Total population: 835308473
Random index: 763607797
Macaroni penguin (population: 18000000)
Probability: .02154892543511886536
Result:
Total population: 835308473
Random index: 442019183
Willow ptarmigan (population: 40000000)
Probability: .04788650096693081191
Result:
Total population: 835308473
Random index: 600337171
Great spotted woodpecker (population: 216000000)
Probability: .25858710522142638435
Result:
Total population: 835308473
Random index: 542347304
Great spotted woodpecker (population: 216000000)
Probability: .25858710522142638435
Result:
Total population: 835308473
Random index: 399097554
Common cuckoo (population: 100000000)
Probability: .11971625241732702979
Result:
Total population: 835308473
Random index: 602221971
Great spotted woodpecker (population: 216000000)
Probability: .25858710522142638435
Result:
Total population: 835308473
Random index: 31407682
Chimney swift (population: 15000000)
Probability: .01795743786259905446
Result:
Total population: 835308473
Random index: 471711629
American coot (population: 6000000)
Probability: .00718297514503962178
Result:
Total population: 835308473
Random index: 127100259
Rock dove (population: 260000000)
Probability: .31126225628505027746
Result:
Total population: 835308473
Random index: 380012920
Common cuckoo (population: 100000000)
Probability: .11971625241732702979
Result:
Total population: 835308473
Random index: 394531514
Common cuckoo (population: 100000000)
Probability: .11971625241732702979
Result:
Total population: 835308473
Random index: 78048210
Rock dove (population: 260000000)
Probability: .31126225628505027746
Result:
Total population: 835308473
Random index: 33341909
European nightjar (population: 6000000)
Probability: .00718297514503962178
Result:
Total population: 835308473
Random index: 211802308
Rock dove (population: 260000000)
Probability: .31126225628505027746
Result:
Total population: 835308473
Random index: 94119789
Rock dove (population: 260000000)
Probability: .31126225628505027746
Result:
Total population: 835308473
Random index: 359620354
Common cuckoo (population: 100000000)
Probability: .11971625241732702979
Result:
Total population: 835308473
Random index: 429592312
Willow ptarmigan (population: 40000000)
Probability: .04788650096693081191
Result:
Total population: 835308473
Random index: 199643906
Rock dove (population: 260000000)
Probability: .31126225628505027746
Result:
Total population: 835308473
Random index: 656519406
Great spotted woodpecker (population: 216000000)
Probability: .25858710522142638435
Result:
Total population: 835308473
Random index: 448395870
Willow ptarmigan (population: 40000000)
Probability: .04788650096693081191
Result:
Total population: 835308473
Random index: 392079604
Common cuckoo (population: 100000000)
Probability: .11971625241732702979
Result:
Total population: 835308473
Random index: 61798025
Rock dove (population: 260000000)
Probability: .31126225628505027746
Result:
Total population: 835308473
Random index: 778932643
Short-eared owl (population: 2000000)
Probability: .00239432504834654059
Result:
Total population: 835308473
Random index: 393661406
Common cuckoo (population: 100000000)
Probability: .11971625241732702979
Result:
Total population: 835308473
Random index: 88104221
Rock dove (population: 260000000)
Probability: .31126225628505027746
Result:
Total population: 835308473
Random index: 623477130
Great spotted woodpecker (population: 216000000)
Probability: .25858710522142638435
Result:
Total population: 835308473
Random index: 401873132
Common cuckoo (population: 100000000)
Probability: .11971625241732702979
Result:
Total population: 835308473
Random index: 680185574
Great spotted woodpecker (population: 216000000)
Probability: .25858710522142638435
Result:
Total population: 835308473
Random index: 724901495
Black-necked grebe (population: 42000000)
Probability: .05028082601527735251
Result:
Total population: 835308473
Random index: 281804665
Rock dove (population: 260000000)
Probability: .31126225628505027746
Wednesday, June 7, 2017
山本太郎: 安倍愚民党が目論む密告、監視社会の未来を語る
- Conspiracy (criminal) (共謀罪)
- Miscarriage of justice (冤罪)
- Public Security Intelligence Agency (公安調査庁)
- 日本ペンクラブ
- 日本ジャーナリスト会議
- Amnesty International (アムネスティ・インターナショナル)
- Consumers' co-operative (生活協同組合)
- 青年法律家協会
- 情報公開を求める市民運動
- 全国公害患者の会連合会
- 核兵器廃絶を訴える団体
- 原水爆禁止日本国民会議
- 原水爆禁止日本協議会
- XKeyscore
- 人権蹂躙
Tuesday, June 6, 2017
macOS Sierra: Bash (Unix shell): Generating Random Number in Arbitrary Range
Command (Random number between 0 to 120,000,000):
$ MIN=0; MAX=120000000; while rnd=$(cat /dev/urandom | LC_CTYPE=C tr -dc 0-9 | fold -w${#MAX} | head -1 | sed 's/^0*//;'); [ -z $rnd ] && rnd=0; (( $rnd < $MIN || $rnd > $MAX)); do :; done; echo $rnd;
Result:
74774521
$ MIN=0; MAX=120000000; while rnd=$(cat /dev/urandom | LC_CTYPE=C tr -dc 0-9 | fold -w${#MAX} | head -1 | sed 's/^0*//;'); [ -z $rnd ] && rnd=0; (( $rnd < $MIN || $rnd > $MAX)); do :; done; echo $rnd;
Result:
74774521
macOS Sierra: Bash (Unix shell): Command to Test for Int64 or Long Integer Support
Command:
$ ((x=(2**63)-1)); echo $x; ((x++)); echo $x;
Result:
9223372036854775807
-9223372036854775808
Interesting note:
9,223,372,036,854,775,807
is
nine quintillion two hundred twenty three quadrillion three hundred seventy two trillion thirty six billion eight hundred fifty four million seven hundred seventy five thousand eight hundred seven
is
九百二十二京三千三百七十二兆三百六十八億五千四百七十七万五千八百七
$ ((x=(2**63)-1)); echo $x; ((x++)); echo $x;
Result:
9223372036854775807
-9223372036854775808
Interesting note:
9,223,372,036,854,775,807
is
nine quintillion two hundred twenty three quadrillion three hundred seventy two trillion thirty six billion eight hundred fifty four million seven hundred seventy five thousand eight hundred seven
is
九百二十二京三千三百七十二兆三百六十八億五千四百七十七万五千八百七
Monday, June 5, 2017
Subscribe to:
Posts (Atom)